diff --git a/distilclient/tests/unit/v2/test_health.py b/distilclient/tests/unit/v2/test_health.py new file mode 100644 index 0000000..ad8dd9d --- /dev/null +++ b/distilclient/tests/unit/v2/test_health.py @@ -0,0 +1,37 @@ +# 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 HealthTest(utils.TestCase): + + def setUp(self): + super(HealthTest, 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_get(self, mock_list): + self.client.health.get() + mock_list.assert_called_with('/v2/health', 'health') diff --git a/distilclient/tests/unit/v2/test_products.py b/distilclient/tests/unit/v2/test_products.py new file mode 100644 index 0000000..beac8fc --- /dev/null +++ b/distilclient/tests/unit/v2/test_products.py @@ -0,0 +1,43 @@ +# 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 ProductsTest(utils.TestCase): + + def setUp(self): + super(ProductsTest, 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(self, mock_list): + self.client.products.list() + mock_list.assert_called_with('/v2/products', 'products') + + @mock.patch.object(base.Manager, '_list') + def test_list_with_regions(self, mock_list): + self.client.products.list(regions=["nz-hlz-1", "nz-por-1"]) + mock_list.assert_called_with('/v2/products?regions=nz-hlz-1,nz-por-1', + 'products') diff --git a/distilclient/v2/client.py b/distilclient/v2/client.py index 0fbf688..afb9676 100644 --- a/distilclient/v2/client.py +++ b/distilclient/v2/client.py @@ -21,8 +21,10 @@ import six from distilclient.common import httpclient from distilclient import exceptions from distilclient.v2 import credits +from distilclient.v2 import health from distilclient.v2 import invoices from distilclient.v2 import measurements +from distilclient.v2 import products from distilclient.v2 import quotations @@ -192,6 +194,8 @@ class Client(object): self.invoices = invoices.InvoiceManager(self) self.quotations = quotations.QuotationManager(self) self.credits = credits.CreditManager(self) + self.products = products.ProductManager(self) + self.health = health.HealthManager(self) self._load_extensions(extensions) diff --git a/distilclient/v2/health.py b/distilclient/v2/health.py new file mode 100644 index 0000000..b5d3fb7 --- /dev/null +++ b/distilclient/v2/health.py @@ -0,0 +1,32 @@ +# 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 HealthManager(base.Manager): + + def get(self): + """Retrieve the health status of Distil server. + + :returns: A list of checking items for Distil health. + """ + + url = "/v2/health" + + # TODO(flwang): Here is using _list instead of _get because by default + # _get function will try to parse the response as a resource object. + # However, we don't have a well-defined health object yet. So let just + # use _list() for now. + return self._list(url, 'health') diff --git a/distilclient/v2/products.py b/distilclient/v2/products.py new file mode 100644 index 0000000..24fe41c --- /dev/null +++ b/distilclient/v2/products.py @@ -0,0 +1,30 @@ +# 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 ProductManager(base.Manager): + + def list(self, regions=[]): + """Retrieve a list of products. + + :returns: A list of products. + """ + + url = "/v2/products" + if regions: + url += "?regions=" + ",".join(regions) + + return self._list(url, "products")