Allow InvoiceManager to take datetime values
Change-Id: I3b353184fdbadcc4fbe81c5a184101cdbde3f833
This commit is contained in:
parent
a7c836b9dd
commit
1904edc3c8
@ -13,6 +13,7 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
|
import datetime
|
||||||
import mock
|
import mock
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
@ -46,3 +47,13 @@ class InvoicesTest(utils.TestCase):
|
|||||||
mock_list.assert_called_with('/v2/invoices?start=2017-1-1'
|
mock_list.assert_called_with('/v2/invoices?start=2017-1-1'
|
||||||
'&end=2018-2-1&detailed=False',
|
'&end=2018-2-1&detailed=False',
|
||||||
'invoices')
|
'invoices')
|
||||||
|
|
||||||
|
@mock.patch.object(base.Manager, '_list')
|
||||||
|
def test_list_with_datetime(self, mock_list):
|
||||||
|
start = datetime.date(year=2017, day=1, month=1)
|
||||||
|
end = datetime.date(year=2018, day=1, month=2)
|
||||||
|
self.client.invoices.list(start, end,
|
||||||
|
'project_id')
|
||||||
|
mock_list.assert_called_with('/v2/invoices?start=2017-01-01'
|
||||||
|
'&end=2018-02-01&detailed=False'
|
||||||
|
'&project_id=project_id', 'invoices')
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
import datetime
|
||||||
from distilclient import base
|
from distilclient import base
|
||||||
|
|
||||||
|
|
||||||
@ -28,6 +29,10 @@ class InvoiceManager(base.Manager):
|
|||||||
usage info in the response.
|
usage info in the response.
|
||||||
:returns: A list of invoices.
|
:returns: A list of invoices.
|
||||||
"""
|
"""
|
||||||
|
if isinstance(start, datetime.datetime):
|
||||||
|
start = start.strftime('%Y-%m-%d')
|
||||||
|
if isinstance(end, datetime.datetime):
|
||||||
|
end = end.strftime('%Y-%m-%d')
|
||||||
|
|
||||||
url = "/v2/invoices?start={0}&end={1}&detailed={2}"
|
url = "/v2/invoices?start={0}&end={1}&detailed={2}"
|
||||||
if project_id:
|
if project_id:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user