From 4d3cad8148e8f1e13b0f424e8b81ec33e3b3a5f3 Mon Sep 17 00:00:00 2001 From: Kiall Mac Innes Date: Mon, 22 Jun 2015 20:24:47 +0100 Subject: [PATCH] Fix backwards compat for edit_managed/all_tenants The previous commit at [1] introduced a bug due to last minute reordering of code, this fixes the ordering and adds a couple of tests to verify the functionaility. [1]: I2e3d74168976868ea1e4dd6c797f6340faa50d0f Change-Id: Ia6f8df92b2700f63b2208290ede85f247b33bc63 --- designateclient/tests/test_v1/__init__.py | 20 ++++ designateclient/tests/test_v1/test_client.py | 104 +++++++++++++++++++ designateclient/utils.py | 2 +- designateclient/v1/__init__.py | 6 +- 4 files changed, 127 insertions(+), 5 deletions(-) create mode 100644 designateclient/tests/test_v1/__init__.py create mode 100644 designateclient/tests/test_v1/test_client.py diff --git a/designateclient/tests/test_v1/__init__.py b/designateclient/tests/test_v1/__init__.py new file mode 100644 index 0000000..a662afe --- /dev/null +++ b/designateclient/tests/test_v1/__init__.py @@ -0,0 +1,20 @@ +# Copyright 2015 Hewlett-Packard Development Company, L.P. +# +# Author: Kiall Mac Innes +# +# 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 designateclient.tests import base + + +class APIV1TestCase(base.APITestCase): + VERSION = "1" diff --git a/designateclient/tests/test_v1/test_client.py b/designateclient/tests/test_v1/test_client.py new file mode 100644 index 0000000..e195191 --- /dev/null +++ b/designateclient/tests/test_v1/test_client.py @@ -0,0 +1,104 @@ +# Copyright 2015 Hewlett-Packard Development Company, L.P. +# +# Author: Kiall Mac Innes +# +# 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 designateclient.tests import test_v1 +from designateclient import utils +from designateclient import v1 + + +class TestClient(test_v1.APIV1TestCase): + def test_all_tenants(self): + # Create a client with the all_tenants flag set to True + client = v1.Client(all_tenants=True) + + # Verify this has been picked up + self.assertTrue(client.all_tenants) + + def test_all_tenants_not_suplied(self): + # Create a client without supplying any all_tenants flag + client = v1.Client() + + # Verify all_tenants is False + self.assertFalse(client.all_tenants) + self.assertIsNotNone(client.all_tenants) + + def test_all_tenants_through_session(self): + # Create a session with the all_tenants flag set to True + session = utils.get_session( + auth_url='Anything', + endpoint='Anything', + domain_id='Anything', + domain_name='Anything', + project_id='Anything', + project_name='Anything', + project_domain_name='Anything', + project_domain_id='Anything', + username='Anything', + user_id='Anything', + password='Anything', + user_domain_id='Anything', + user_domain_name='Anything', + token=None, + insecure=False, + cacert=None, + all_tenants=True) + + # Create a client using the pre-created session + client = v1.Client(session=session) + + # Verify the all_tenants flag has been picked up + self.assertTrue(client.all_tenants) + + def test_edit_managed(self): + # Create a client with the edit_managed flag set to True + client = v1.Client(edit_managed=True) + + # Verify this has been picked up + self.assertTrue(client.edit_managed) + + def test_edit_managed_not_suplied(self): + # Create a client without supplying any edit_managed flag + client = v1.Client() + + # Verify edit_managed is False + self.assertFalse(client.edit_managed) + self.assertIsNotNone(client.edit_managed) + + def test_edit_managed_through_session(self): + # Create a session with the edit_managed flag set to True + session = utils.get_session( + auth_url='Anything', + endpoint='Anything', + domain_id='Anything', + domain_name='Anything', + project_id='Anything', + project_name='Anything', + project_domain_name='Anything', + project_domain_id='Anything', + username='Anything', + user_id='Anything', + password='Anything', + user_domain_id='Anything', + user_domain_name='Anything', + token=None, + insecure=False, + cacert=None, + edit_managed=True) + + # Create a client using the pre-created session + client = v1.Client(session=session) + + # Verify the edit_managed flag has been picked up + self.assertTrue(client.edit_managed) diff --git a/designateclient/utils.py b/designateclient/utils.py index 119b35e..ea5d48b 100644 --- a/designateclient/utils.py +++ b/designateclient/utils.py @@ -103,7 +103,7 @@ def get_columns(data): def get_session(auth_url, endpoint, domain_id, domain_name, project_id, project_name, project_domain_name, project_domain_id, username, user_id, password, user_domain_id, user_domain_name, token, - insecure, cacert, all_tenants=None, edit_managed=None): + insecure, cacert, all_tenants=False, edit_managed=False): # NOTE: all_tenants and edit_managed are here for backwards compat # reasons, do not add additional modifiers here. diff --git a/designateclient/v1/__init__.py b/designateclient/v1/__init__.py index 73fef35..5c216dc 100644 --- a/designateclient/v1/__init__.py +++ b/designateclient/v1/__init__.py @@ -69,14 +69,12 @@ class Client(object): # backwards compat reasons, do not pull additional modifiers from # here. Once removed, the kwargs above should default to False. if all_tenants is None: - self.all_tenants = getattr(self.session.session, 'all_tenants', - False) + self.all_tenants = getattr(session, 'all_tenants', False) else: self.all_tenants = all_tenants if edit_managed is None: - self.edit_managed = getattr(self.session.session, 'edit_managed', - False) + self.edit_managed = getattr(session, 'edit_managed', False) else: self.edit_managed = edit_managed