Support /invoices and /quotations API
According to the change of Distil API, this patch adds the support for /invoices and /quotations. And by the way, change the /measurements API as well. Unit tests are added based on changes. Change-Id: I251b534a4e4a41a76a3743118010be408116c27a
This commit is contained in:
parent
57ec3b1dea
commit
dffc18095b
@ -1,14 +1,17 @@
|
|||||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
# Copyright (c) 2017 Catalyst IT Ltd.
|
||||||
# not use this file except in compliance with the License. You may obtain
|
|
||||||
# a copy of the License at
|
|
||||||
#
|
#
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
#
|
#
|
||||||
# Unless required by applicable law or agreed to in writing, software
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||||
# License for the specific language governing permissions and limitations
|
# implied.
|
||||||
# under the License.
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
|
||||||
import ddt
|
import ddt
|
||||||
import uuid
|
import uuid
|
||||||
|
46
distilclient/tests/unit/v2/test_invoices.py
Normal file
46
distilclient/tests/unit/v2/test_invoices.py
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
# Copyright (c) 2017 Catalyst IT Ltd.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||||
|
# implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
|
||||||
|
import mock
|
||||||
|
import uuid
|
||||||
|
|
||||||
|
import distilclient
|
||||||
|
from distilclient import base
|
||||||
|
from distilclient.tests.unit import utils
|
||||||
|
from distilclient.v2 import client
|
||||||
|
|
||||||
|
|
||||||
|
class InvoicesTest(utils.TestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super(InvoicesTest, self).setUp()
|
||||||
|
self.client = client.Client(session=client.session.Session(),
|
||||||
|
api_version=distilclient.API_MAX_VERSION,
|
||||||
|
distil_url=uuid.uuid4().hex, retries=3,
|
||||||
|
input_auth_token='token')
|
||||||
|
|
||||||
|
@mock.patch.object(base.Manager, '_list')
|
||||||
|
def test_list_with_project_id(self, mock_list):
|
||||||
|
self.client.invoices.list('2017-1-1', '2018-2-1',
|
||||||
|
'project_id')
|
||||||
|
mock_list.assert_called_with('/v2/invoices?start=2017-1-1'
|
||||||
|
'&end=2018-2-1&project_id=project_id',
|
||||||
|
'invoices')
|
||||||
|
|
||||||
|
@mock.patch.object(base.Manager, '_list')
|
||||||
|
def test_list_without_project_id(self, mock_list):
|
||||||
|
self.client.invoices.list('2017-1-1', '2018-2-1')
|
||||||
|
mock_list.assert_called_with('/v2/invoices?start=2017-1-1'
|
||||||
|
'&end=2018-2-1', 'invoices')
|
@ -1,25 +1,47 @@
|
|||||||
# Copyright 2010 Jacob Kaplan-Moss
|
# Copyright (c) 2017 Catalyst IT Ltd.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||||
|
# implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
|
||||||
# Copyright 2011 OpenStack Foundation
|
import mock
|
||||||
# All Rights Reserved.
|
import uuid
|
||||||
#
|
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
||||||
# not use this file except in compliance with the License. You may obtain
|
|
||||||
# a copy of the License at
|
|
||||||
#
|
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
#
|
|
||||||
# Unless required by applicable law or agreed to in writing, software
|
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
||||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
||||||
# License for the specific language governing permissions and limitations
|
|
||||||
# under the License.
|
|
||||||
|
|
||||||
|
import distilclient
|
||||||
|
from distilclient import base
|
||||||
from distilclient.tests.unit import utils
|
from distilclient.tests.unit import utils
|
||||||
|
from distilclient.v2 import client
|
||||||
|
|
||||||
|
|
||||||
class MeasurementsTest(utils.TestCase):
|
class MeasurementsTest(utils.TestCase):
|
||||||
|
|
||||||
# Testcases for class Share
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(MeasurementsTest, self).setUp()
|
super(MeasurementsTest, self).setUp()
|
||||||
|
|
||||||
|
self.client = client.Client(session=client.session.Session(),
|
||||||
|
api_version=distilclient.API_MAX_VERSION,
|
||||||
|
distil_url=uuid.uuid4().hex, retries=3,
|
||||||
|
input_auth_token='token')
|
||||||
|
|
||||||
|
@mock.patch.object(base.Manager, '_list')
|
||||||
|
def test_list_with_project_id(self, mock_list):
|
||||||
|
self.client.measurements.list('2017-1-1', '2018-2-1',
|
||||||
|
'project_id')
|
||||||
|
mock_list.assert_called_with('/v2/measurements?start=2017-1-1'
|
||||||
|
'&end=2018-2-1&project_id=project_id',
|
||||||
|
'measurements')
|
||||||
|
|
||||||
|
@mock.patch.object(base.Manager, '_list')
|
||||||
|
def test_list_without_project_id(self, mock_list):
|
||||||
|
self.client.measurements.list('2017-1-1', '2018-2-1')
|
||||||
|
mock_list.assert_called_with('/v2/measurements?start=2017-1-1'
|
||||||
|
'&end=2018-2-1', 'measurements')
|
||||||
|
46
distilclient/tests/unit/v2/test_quotations.py
Normal file
46
distilclient/tests/unit/v2/test_quotations.py
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
# Copyright (c) 2017 Catalyst IT Ltd.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||||
|
# implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
|
||||||
|
import mock
|
||||||
|
import uuid
|
||||||
|
|
||||||
|
import distilclient
|
||||||
|
from distilclient import base
|
||||||
|
from distilclient.tests.unit import utils
|
||||||
|
from distilclient.v2 import client
|
||||||
|
|
||||||
|
|
||||||
|
class QuotationsTest(utils.TestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super(QuotationsTest, self).setUp()
|
||||||
|
self.client = client.Client(session=client.session.Session(),
|
||||||
|
api_version=distilclient.API_MAX_VERSION,
|
||||||
|
distil_url=uuid.uuid4().hex, retries=3,
|
||||||
|
input_auth_token='token')
|
||||||
|
|
||||||
|
@mock.patch.object(base.Manager, '_list')
|
||||||
|
def test_list_with_project_id(self, mock_list):
|
||||||
|
self.client.quotations.list('2017-1-1', '2018-2-1',
|
||||||
|
'project_id')
|
||||||
|
mock_list.assert_called_with('/v2/quotations?start=2017-1-1'
|
||||||
|
'&end=2018-2-1&project_id=project_id',
|
||||||
|
'quotations')
|
||||||
|
|
||||||
|
@mock.patch.object(base.Manager, '_list')
|
||||||
|
def test_list_without_project_id(self, mock_list):
|
||||||
|
self.client.quotations.list('2017-1-1', '2018-2-1')
|
||||||
|
mock_list.assert_called_with('/v2/quotations?start=2017-1-1'
|
||||||
|
'&end=2018-2-1', 'quotations')
|
@ -20,7 +20,9 @@ import six
|
|||||||
|
|
||||||
from distilclient.common import httpclient
|
from distilclient.common import httpclient
|
||||||
from distilclient import exceptions
|
from distilclient import exceptions
|
||||||
|
from distilclient.v2 import invoices
|
||||||
from distilclient.v2 import measurements
|
from distilclient.v2 import measurements
|
||||||
|
from distilclient.v2 import quotations
|
||||||
|
|
||||||
|
|
||||||
class Client(object):
|
class Client(object):
|
||||||
@ -186,6 +188,8 @@ class Client(object):
|
|||||||
api_version=self.api_version)
|
api_version=self.api_version)
|
||||||
|
|
||||||
self.measurements = measurements.MeasurementManager(self)
|
self.measurements = measurements.MeasurementManager(self)
|
||||||
|
self.invoices = invoices.InvoiceManager(self)
|
||||||
|
self.quotations = quotations.QuotationManager(self)
|
||||||
|
|
||||||
self._load_extensions(extensions)
|
self._load_extensions(extensions)
|
||||||
|
|
||||||
|
36
distilclient/v2/invoices.py
Normal file
36
distilclient/v2/invoices.py
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
# Copyright 2017 Catalyst IT Ltd.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
# not use this file except in compliance with the License. You may obtain
|
||||||
|
# a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
# License for the specific language governing permissions and limitations
|
||||||
|
# under the License.
|
||||||
|
|
||||||
|
from distilclient import base
|
||||||
|
|
||||||
|
|
||||||
|
class InvoiceManager(base.Manager):
|
||||||
|
|
||||||
|
def list(self, start, end, project_id=None):
|
||||||
|
"""Retrieve a list of invoices.
|
||||||
|
|
||||||
|
:param start: Start date of the query
|
||||||
|
:param end: End date of the query
|
||||||
|
:param project_id: Project ID, there there is no project id given,
|
||||||
|
Distil will use the project ID from token.
|
||||||
|
:returns: A list of invoices.
|
||||||
|
"""
|
||||||
|
|
||||||
|
url = "/v2/invoices?start={0}&end={1}"
|
||||||
|
if project_id:
|
||||||
|
url = url.format(start, end) + "&project_id=" + project_id
|
||||||
|
else:
|
||||||
|
url = url.format(start, end)
|
||||||
|
|
||||||
|
return self._list(url, "invoices")
|
@ -17,11 +17,20 @@ from distilclient import base
|
|||||||
|
|
||||||
class MeasurementManager(base.Manager):
|
class MeasurementManager(base.Manager):
|
||||||
|
|
||||||
def list(self, project_id, start, end):
|
def list(self, start, end, project_id=None):
|
||||||
"""Retrieve a list of measurements.
|
"""Retrieve a list of measurements.
|
||||||
|
|
||||||
|
:param start: Start date of the query
|
||||||
|
:param end: End date of the query
|
||||||
|
:param project_id: Project ID, there there is no project id given,
|
||||||
|
Distil will use the project ID from token.
|
||||||
:returns: A list of measurements.
|
:returns: A list of measurements.
|
||||||
"""
|
"""
|
||||||
url = "/v2/measurements?project_id={0}&start={1}&end={2}"
|
|
||||||
url = url.format(project_id, start, end)
|
url = "/v2/measurements?start={0}&end={1}"
|
||||||
|
if project_id:
|
||||||
|
url = url.format(start, end) + "&project_id=" + project_id
|
||||||
|
else:
|
||||||
|
url = url.format(start, end)
|
||||||
|
|
||||||
return self._list(url, "measurements")
|
return self._list(url, "measurements")
|
||||||
|
36
distilclient/v2/quotations.py
Normal file
36
distilclient/v2/quotations.py
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
# Copyright 2017 Catalyst IT Ltd.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
# not use this file except in compliance with the License. You may obtain
|
||||||
|
# a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
# License for the specific language governing permissions and limitations
|
||||||
|
# under the License.
|
||||||
|
|
||||||
|
from distilclient import base
|
||||||
|
|
||||||
|
|
||||||
|
class QuotationManager(base.Manager):
|
||||||
|
|
||||||
|
def list(self, start, end, project_id=None):
|
||||||
|
"""Retrieve a list of quotations.
|
||||||
|
|
||||||
|
:param start: Start date of the query
|
||||||
|
:param end: End date of the query
|
||||||
|
:param project_id: Project ID, there there is no project id given,
|
||||||
|
Distil will use the project ID from token.
|
||||||
|
:returns: A list of quotations.
|
||||||
|
"""
|
||||||
|
|
||||||
|
url = "/v2/quotations?start={0}&end={1}"
|
||||||
|
if project_id:
|
||||||
|
url = url.format(start, end) + "&project_id=" + project_id
|
||||||
|
else:
|
||||||
|
url = url.format(start, end)
|
||||||
|
|
||||||
|
return self._list(url, "quotations")
|
Loading…
x
Reference in New Issue
Block a user