diff --git a/distilclient/tests/unit/v2/test_invoices.py b/distilclient/tests/unit/v2/test_invoices.py index eb3b30e..9ecd308 100644 --- a/distilclient/tests/unit/v2/test_invoices.py +++ b/distilclient/tests/unit/v2/test_invoices.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import datetime import mock import distilclient @@ -48,3 +49,13 @@ class InvoicesTest(utils.TestCase): mock_list.assert_called_with('/v2/invoices?start=2017-1-1' '&end=2018-2-1&detailed=False', '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') diff --git a/distilclient/v2/invoices.py b/distilclient/v2/invoices.py index 92c29aa..2b95a1f 100644 --- a/distilclient/v2/invoices.py +++ b/distilclient/v2/invoices.py @@ -12,6 +12,7 @@ # License for the specific language governing permissions and limitations # under the License. +import datetime from distilclient import base @@ -28,6 +29,10 @@ class InvoiceManager(base.Manager): usage info in the response. :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}" if project_id: