Allow InvoiceManager to take datetime values

Change-Id: I3b353184fdbadcc4fbe81c5a184101cdbde3f833
This commit is contained in:
Amelia Cordwell 2017-07-20 15:03:16 +12:00 committed by Feilong Wang
parent a7c836b9dd
commit 1904edc3c8
2 changed files with 16 additions and 0 deletions

View File

@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import datetime
import mock
import uuid
@ -46,3 +47,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')

View File

@ -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: