Merge "Allow InvoiceManager to take datetime values"
This commit is contained in:
commit
4bb89edc91
@ -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')
|
||||
|
@ -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:
|
||||
|
Loading…
x
Reference in New Issue
Block a user