From 9c2697fe949cdc671d6cb70708c5b88ba263a579 Mon Sep 17 00:00:00 2001 From: vmyrhorodskyi Date: Sat, 11 Jun 2016 20:35:20 +0200 Subject: [PATCH 01/10] Clusters, pools, mons and calamari API connection tests were added --- tests/rest/controllers/common_test_methods.py | 38 ++++++++++ .../test_calamari_api_connection.py | 34 +++++++++ tests/rest/controllers/test_clusters.py | 56 +++++++++++++++ tests/rest/controllers/test_mons.py | 64 +++++++++++++++++ tests/rest/controllers/test_osds.py | 3 + tests/rest/controllers/test_pools.py | 69 +++++++++++++++++++ 6 files changed, 264 insertions(+) create mode 100644 tests/rest/controllers/common_test_methods.py create mode 100644 tests/rest/controllers/test_calamari_api_connection.py create mode 100644 tests/rest/controllers/test_clusters.py create mode 100644 tests/rest/controllers/test_mons.py create mode 100644 tests/rest/controllers/test_osds.py create mode 100644 tests/rest/controllers/test_pools.py diff --git a/tests/rest/controllers/common_test_methods.py b/tests/rest/controllers/common_test_methods.py new file mode 100644 index 0000000..1d4c633 --- /dev/null +++ b/tests/rest/controllers/common_test_methods.py @@ -0,0 +1,38 @@ +"""Common test methods""" + + +def get_clusters_id(clusters_data): + clusters_id = clusters_data['data']['id'] + return clusters_id + + + + +def test_expectedResponse(self, response, data): + self.assertEqual(response.status_code, 200) + self.assertTrue(isinstance(data, dict)) + +def test_consistDataKey(self, data): + self.assertIn('data', data) + +def test_expectedDataStructure(self, data): + self.assertTrue(isinstance(data['data'], list)) + for j in range(len(data['data'])): + self.assertTrue(isinstance(data['data'][j], dict)) + self.assertTrue(isinstance(data['data'][j]['attributes'], dict)) + +def test_KeysInDatalistOfDictionaries(self, data): + for j in range(len(data['data'])): + self.assertIn('attributes', data['data'][j]) + self.assertIn('type', data['data'][j]) + self.assertIn('id', data['data'][j]) + +def test_type(self, data, type): + for j in range(len(data['data'])): + self.assertEqual(data['data'][j]['type'], type) + + +def test_expectedAttributesKeys(self, data, list_of_expected_attributes): + for j in range(len(data['data'])): + for k in range(len(list_of_expected_attributes)): + self.assertIn(list_of_expected_attributes[k], data['data'][j]['attributes']) \ No newline at end of file diff --git a/tests/rest/controllers/test_calamari_api_connection.py b/tests/rest/controllers/test_calamari_api_connection.py new file mode 100644 index 0000000..c1de9c9 --- /dev/null +++ b/tests/rest/controllers/test_calamari_api_connection.py @@ -0,0 +1,34 @@ +"""Calamari API connection tests""" + +import unittest +from requests import ConnectionError +from config import CALAMARI_API_URL, CALAMARI_API_PWD, CALAMARI_API_USER, CALAMARI_API_TIMEOUT +from kujira.rest.lib.calamari_client import CalamariClient +from kujira.rest.lib.parsing_methods import create_error_422 + + + +class CalamariAPIConnectionTestCase(unittest.TestCase): + + def test_server_is_up_and_running(self): + constr = CalamariClient(api_url=CALAMARI_API_URL, username=CALAMARI_API_USER, + password=CALAMARI_API_PWD, timeout=CALAMARI_API_TIMEOUT) + client = constr.authenticate() + response = client.get(constr._api_url, timeout=constr._timeout) + self.assertEqual(response.status_code, 200) + + + def test_error_422(self): + try: + constr = CalamariClient(api_url="http://localhost/api/v2/", username=CALAMARI_API_USER, + password=CALAMARI_API_PWD, timeout=CALAMARI_API_TIMEOUT) + client = constr.authenticate() + response = client.get(constr._api_url, timeout=constr._timeout) + except ConnectionError as err: + response = create_error_422(constr._api_url, str(err)) + self.assertEqual(response.status_code, 422) + + + +if __name__ == '__main__': + unittest.main(); diff --git a/tests/rest/controllers/test_clusters.py b/tests/rest/controllers/test_clusters.py new file mode 100644 index 0000000..3455358 --- /dev/null +++ b/tests/rest/controllers/test_clusters.py @@ -0,0 +1,56 @@ +"""Clusters controller test + kujira-api must already be running +""" + +import unittest +import requests + + + +class ClustersTestCase(unittest.TestCase): + + response = None + data = None + + def setUp(self): + self.response = requests.get("http://0.0.0.0:5000/kujira/api/v1/clusters") + self.data = self.response.json() + + def tearDown(self): + self.response = None + self.data = None + + + def test_expectedResponse(self): + self.assertEqual(self.response.status_code, 200) + self.assertTrue(isinstance(self.data, dict)) + + def test_consistDataKey(self): + self.assertIn('data', self.data) + + def test_expectedDataStructure(self): + self.assertTrue(isinstance(self.data['data'], dict)) + self.assertTrue(isinstance(self.data['data']['attributes'], dict)) + + def test_KeysInDataDictionary(self): + self.assertIn('attributes', self.data['data']) + self.assertIn('type', self.data['data']) + self.assertIn('id', self.data['data']) + + def test_type(self): + self.assertEqual(self.data['data']['type'], 'clusters') + + def test_expectedAttributesKeys(self): + self.assertIn('epoch', self.data['data']['attributes']) + self.assertIn('health', self.data['data']['attributes']) + self.assertIn('id', self.data['data']['attributes']) + self.assertIn('name', self.data['data']['attributes']) + + def test_name(self): + self.assertEqual(self.data['data']['attributes']['name'], 'ceph') + +if __name__ == '__main__': + unittest.main() + + + diff --git a/tests/rest/controllers/test_mons.py b/tests/rest/controllers/test_mons.py new file mode 100644 index 0000000..b41526b --- /dev/null +++ b/tests/rest/controllers/test_mons.py @@ -0,0 +1,64 @@ +"""Mons controller test + kujira-api must already be running +""" + +import unittest +import requests +import common_test_methods + + + +class MonsTestCase(unittest.TestCase): + + clusters_id = None + response = None + data = None + + + def setUp(self): + clusters_data = requests.get("http://0.0.0.0:5000/kujira/api/v1/clusters").json() + self.clusters_id = common_test_methods.get_clusters_id(clusters_data) + self.response = requests.get("http://0.0.0.0:5000/kujira/api/v1/mons/" + str(self.clusters_id)) + self.data = self.response.json() + + + def tearDown(self): + self.clusters_id = None + self.response = None + self.data = None + + + + def test_expectedResponse(self): + common_test_methods.test_expectedResponse(self, self.response, self.data) + + def test_consistDataKey(self): + common_test_methods.test_consistDataKey(self, self.data) + + def test_expectedDataStructure(self): + common_test_methods.test_expectedDataStructure(self, self.data) + + def test_KeysInDatalistOfDictionaries(self): + common_test_methods.test_KeysInDatalistOfDictionaries(self, self.data) + + def test_type(self): + common_test_methods.test_type(self, self.data, 'mons') + + def test_expectedAttributesKeys(self): + list_of_expected_attributes = [] + list_of_expected_attributes.append('name') + list_of_expected_attributes.append('in-quorum') + list_of_expected_attributes.append('addr') + list_of_expected_attributes.append('rank') + list_of_expected_attributes.append('server') + common_test_methods.test_expectedAttributesKeys(self, self.data, list_of_expected_attributes) + + def test_server_name(self): + for j in range(len(self.data['data'])): + id = self.data['data'][j]['id'] + self.assertEqual(self.data['data'][j]['attributes']['name'], id) + self.assertEqual(self.data['data'][j]['attributes']['server'], id) + + +if __name__ == '__main__': + unittest.main() \ No newline at end of file diff --git a/tests/rest/controllers/test_osds.py b/tests/rest/controllers/test_osds.py new file mode 100644 index 0000000..80d79a5 --- /dev/null +++ b/tests/rest/controllers/test_osds.py @@ -0,0 +1,3 @@ +"""Osds controller test + kujira-api must already be running +""" diff --git a/tests/rest/controllers/test_pools.py b/tests/rest/controllers/test_pools.py new file mode 100644 index 0000000..c983470 --- /dev/null +++ b/tests/rest/controllers/test_pools.py @@ -0,0 +1,69 @@ +"""Pools controller test + kujira-api must already be running +""" + +import unittest +import requests +import common_test_methods + + + +class PoolsTestCase(unittest.TestCase): + + clusters_id = None + response = None + data = None + + + def setUp(self): + clusters_data = requests.get("http://0.0.0.0:5000/kujira/api/v1/clusters").json() + self.clusters_id = common_test_methods.get_clusters_id(clusters_data) + self.response = requests.get("http://0.0.0.0:5000/kujira/api/v1/pools/" + str(self.clusters_id)) + self.data = self.response.json() + + def tearDown(self): + self.clusters_id = None + self.response = None + self.data = None + + + + def test_expectedResponse(self): + common_test_methods.test_expectedResponse(self, self.response, self.data) + + def test_consistDataKey(self): + common_test_methods.test_consistDataKey(self, self.data) + + def test_expectedDataStructure(self): + common_test_methods.test_expectedDataStructure(self, self.data) + + def test_KeysInDatalistOfDictionaries(self): + common_test_methods.test_KeysInDatalistOfDictionaries(self, self.data) + + def test_type(self): + common_test_methods.test_type(self, self.data, 'pools') + + def test_expectedAttributesKeys(self): + list_of_expected_attributes = [] + list_of_expected_attributes.append('full') + list_of_expected_attributes.append('name') + list_of_expected_attributes.append('id') + list_of_expected_attributes.append('crush-ruleset') + list_of_expected_attributes.append('crash-replay-interval') + list_of_expected_attributes.append('hashpspool') + list_of_expected_attributes.append('pg-num') + list_of_expected_attributes.append('quota-max-bytes') + list_of_expected_attributes.append('size') + list_of_expected_attributes.append('pgp-num') + list_of_expected_attributes.append('min-size') + list_of_expected_attributes.append('quota-max-objects') + common_test_methods.test_expectedAttributesKeys(self, self.data, list_of_expected_attributes) + + def test_id_equals(self): + for j in range(len(self.data['data'])): + id = self.data['data'][j]['id'] + self.assertEqual(str(self.data['data'][j]['attributes']['id']), id) + + +if __name__ == '__main__': + unittest.main() \ No newline at end of file From 7c9856d9ae79d02431678a23a403138b565c81e2 Mon Sep 17 00:00:00 2001 From: vmyrhorodskyi Date: Sun, 12 Jun 2016 10:33:11 +0200 Subject: [PATCH 02/10] Empty test class test_osds.py was deleted --- tests/rest/controllers/test_osds.py | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 tests/rest/controllers/test_osds.py diff --git a/tests/rest/controllers/test_osds.py b/tests/rest/controllers/test_osds.py deleted file mode 100644 index 80d79a5..0000000 --- a/tests/rest/controllers/test_osds.py +++ /dev/null @@ -1,3 +0,0 @@ -"""Osds controller test - kujira-api must already be running -""" From ff6bf84435ae7611d611403f719a1692c779b497 Mon Sep 17 00:00:00 2001 From: vmyrhorodskyi Date: Tue, 14 Jun 2016 12:45:15 +0200 Subject: [PATCH 03/10] test controllers is ready to pull request; osd.py was modified for the reason of bad response --- kujira/rest/controllers/osds.py | 2 +- tests/rest/controllers/test_clusters.py | 98 +++++++++++++++++++++++-- 2 files changed, 92 insertions(+), 8 deletions(-) diff --git a/kujira/rest/controllers/osds.py b/kujira/rest/controllers/osds.py index 2953c76..b5c0386 100644 --- a/kujira/rest/controllers/osds.py +++ b/kujira/rest/controllers/osds.py @@ -55,7 +55,7 @@ def parse_osd(osd_dict): attributes[key] = value elif isinstance(value, list): lst = [] - for index in enumerate(value): + for index in range(len(value)): if isinstance(value[index], dict): lst.append(parse_osd(value[index])) else: diff --git a/tests/rest/controllers/test_clusters.py b/tests/rest/controllers/test_clusters.py index 3455358..a4eafb9 100644 --- a/tests/rest/controllers/test_clusters.py +++ b/tests/rest/controllers/test_clusters.py @@ -6,49 +6,133 @@ import requests - class ClustersTestCase(unittest.TestCase): + """Clusters controllers test case""" response = None data = None + def setUp(self): - self.response = requests.get("http://0.0.0.0:5000/kujira/api/v1/clusters") + self.response = requests.get("http://0.0.0.0:5000/kujira/api/v1/" + + "clusters") self.data = self.response.json() + def tearDown(self): self.response = None self.data = None - def test_expectedResponse(self): + def test_expected_response(self): + """Test for expected response: + status code= 200, + response is dictionary.""" self.assertEqual(self.response.status_code, 200) self.assertTrue(isinstance(self.data, dict)) - def test_consistDataKey(self): + + def test_consist_data_key(self): + """Testing does response consist data key: + { + # DATA KEY - "data" + "data":{ + ... + } + } + """ self.assertIn('data', self.data) - def test_expectedDataStructure(self): + + def test_expected_data_structure(self): + """Testing does reponse structure is the same as expected: + { + "data":{ + # IS DICTIONARY + "attributes":{ + # IS DICTIONARY + ... + }, + ... + } + } + """ self.assertTrue(isinstance(self.data['data'], dict)) self.assertTrue(isinstance(self.data['data']['attributes'], dict)) - def test_KeysInDataDictionary(self): + + def test_keys_in_data_dictionary(self): + """Testing keys in data dictionary: + { + "data":{ + # RESPONSE CONSIST KEY "attributes" + "attributes":{ + ... + }, + # RESPONSE CONSIST KEY "type" + "type": "some value", + # RESPONSE CONSIST KEY "id" + "id": "some value" + } + } + """ self.assertIn('attributes', self.data['data']) self.assertIn('type', self.data['data']) self.assertIn('id', self.data['data']) + def test_type(self): + """ "type": "clusters" test: + { + "data":{ + ... + # RESPONSE CONSIST KEY "type" WITH "clusters VALUE" + type": "clusters", + ... + } + } + """ self.assertEqual(self.data['data']['type'], 'clusters') - def test_expectedAttributesKeys(self): + + def test_expected_attributes_keys(self): + """ Testing keys in "attributes" dictionary: + { + "data":{ + "attributes":{ + # "attributes" KEY VALUE IS DICTIONARY WITH + # "epoch", "health", "id", "name" KEYS + "epoch": "some value", + "health": "some value", + "id": "some value", + "name": "some value" + }, + ... + } + } + """ self.assertIn('epoch', self.data['data']['attributes']) self.assertIn('health', self.data['data']['attributes']) self.assertIn('id', self.data['data']['attributes']) self.assertIn('name', self.data['data']['attributes']) + def test_name(self): + """ "name": "ceph" test: + { + "data":{ + "attributes":{ + ... + # "ceph" IS EXPECTED VALUE OF "name" KEY + "name": "ceph" + }, + ... + } + } + """ self.assertEqual(self.data['data']['attributes']['name'], 'ceph') + if __name__ == '__main__': unittest.main() From a1d4ea44ec1466e5ed442aff3abb844694247ab3 Mon Sep 17 00:00:00 2001 From: vmyrhorodskyi Date: Wed, 15 Jun 2016 12:08:14 +0200 Subject: [PATCH 04/10] test for Calamari API connection with docstrings --- tests/rest/__init__.py | 0 tests/rest/controllers/__init__.py | 0 .../test_calamari_api_connection.py | 23 +++++++++++++------ 3 files changed, 16 insertions(+), 7 deletions(-) create mode 100755 tests/rest/__init__.py create mode 100755 tests/rest/controllers/__init__.py diff --git a/tests/rest/__init__.py b/tests/rest/__init__.py new file mode 100755 index 0000000..e69de29 diff --git a/tests/rest/controllers/__init__.py b/tests/rest/controllers/__init__.py new file mode 100755 index 0000000..e69de29 diff --git a/tests/rest/controllers/test_calamari_api_connection.py b/tests/rest/controllers/test_calamari_api_connection.py index c1de9c9..1f73292 100644 --- a/tests/rest/controllers/test_calamari_api_connection.py +++ b/tests/rest/controllers/test_calamari_api_connection.py @@ -7,21 +7,31 @@ from kujira.rest.lib.parsing_methods import create_error_422 - class CalamariAPIConnectionTestCase(unittest.TestCase): + """Calamari API connection test case""" def test_server_is_up_and_running(self): - constr = CalamariClient(api_url=CALAMARI_API_URL, username=CALAMARI_API_USER, - password=CALAMARI_API_PWD, timeout=CALAMARI_API_TIMEOUT) + """ Calamari API request test: + expected response status code - 200 + """ + constr = CalamariClient(api_url=CALAMARI_API_URL, + username=CALAMARI_API_USER, + password=CALAMARI_API_PWD, + timeout=CALAMARI_API_TIMEOUT) client = constr.authenticate() response = client.get(constr._api_url, timeout=constr._timeout) self.assertEqual(response.status_code, 200) def test_error_422(self): + """ Testing request with wrong Calamari API url: + 422 error is expected + """ try: - constr = CalamariClient(api_url="http://localhost/api/v2/", username=CALAMARI_API_USER, - password=CALAMARI_API_PWD, timeout=CALAMARI_API_TIMEOUT) + constr = CalamariClient(api_url="http://wrong_calamari_api_url/api/v2/", + username=CALAMARI_API_USER, + password=CALAMARI_API_PWD, + timeout=CALAMARI_API_TIMEOUT) client = constr.authenticate() response = client.get(constr._api_url, timeout=constr._timeout) except ConnectionError as err: @@ -29,6 +39,5 @@ def test_error_422(self): self.assertEqual(response.status_code, 422) - if __name__ == '__main__': - unittest.main(); + unittest.main() From 21f4b2eabf06c640388891e47ec6d05f9d84f3f0 Mon Sep 17 00:00:00 2001 From: vmyrhorodskyi Date: Wed, 15 Jun 2016 17:42:06 +0200 Subject: [PATCH 05/10] Osds, pools, mons, clusters, Calamari API connectin tests with docstrings --- tests/rest/controllers/__init__.py | 0 tests/rest/controllers/common_test_methods.py | 38 ----- tests/rest/controllers/test_mons.py | 64 ------- tests/rest/controllers/test_pools.py | 69 -------- .../rest/{ => tests_controllers}/__init__.py | 0 .../common_testing_methods.py | 158 ++++++++++++++++++ .../test_calamari_api_connection.py | 0 .../test_clusters.py | 7 +- tests/rest/tests_controllers/test_mons.py | 24 +++ tests/rest/tests_controllers/test_osds.py | 26 +++ tests/rest/tests_controllers/test_pools.py | 23 +++ 11 files changed, 235 insertions(+), 174 deletions(-) delete mode 100755 tests/rest/controllers/__init__.py delete mode 100644 tests/rest/controllers/common_test_methods.py delete mode 100644 tests/rest/controllers/test_mons.py delete mode 100644 tests/rest/controllers/test_pools.py rename tests/rest/{ => tests_controllers}/__init__.py (100%) create mode 100644 tests/rest/tests_controllers/common_testing_methods.py rename tests/rest/{controllers => tests_controllers}/test_calamari_api_connection.py (100%) rename tests/rest/{controllers => tests_controllers}/test_clusters.py (97%) create mode 100644 tests/rest/tests_controllers/test_mons.py create mode 100644 tests/rest/tests_controllers/test_osds.py create mode 100644 tests/rest/tests_controllers/test_pools.py diff --git a/tests/rest/controllers/__init__.py b/tests/rest/controllers/__init__.py deleted file mode 100755 index e69de29..0000000 diff --git a/tests/rest/controllers/common_test_methods.py b/tests/rest/controllers/common_test_methods.py deleted file mode 100644 index 1d4c633..0000000 --- a/tests/rest/controllers/common_test_methods.py +++ /dev/null @@ -1,38 +0,0 @@ -"""Common test methods""" - - -def get_clusters_id(clusters_data): - clusters_id = clusters_data['data']['id'] - return clusters_id - - - - -def test_expectedResponse(self, response, data): - self.assertEqual(response.status_code, 200) - self.assertTrue(isinstance(data, dict)) - -def test_consistDataKey(self, data): - self.assertIn('data', data) - -def test_expectedDataStructure(self, data): - self.assertTrue(isinstance(data['data'], list)) - for j in range(len(data['data'])): - self.assertTrue(isinstance(data['data'][j], dict)) - self.assertTrue(isinstance(data['data'][j]['attributes'], dict)) - -def test_KeysInDatalistOfDictionaries(self, data): - for j in range(len(data['data'])): - self.assertIn('attributes', data['data'][j]) - self.assertIn('type', data['data'][j]) - self.assertIn('id', data['data'][j]) - -def test_type(self, data, type): - for j in range(len(data['data'])): - self.assertEqual(data['data'][j]['type'], type) - - -def test_expectedAttributesKeys(self, data, list_of_expected_attributes): - for j in range(len(data['data'])): - for k in range(len(list_of_expected_attributes)): - self.assertIn(list_of_expected_attributes[k], data['data'][j]['attributes']) \ No newline at end of file diff --git a/tests/rest/controllers/test_mons.py b/tests/rest/controllers/test_mons.py deleted file mode 100644 index b41526b..0000000 --- a/tests/rest/controllers/test_mons.py +++ /dev/null @@ -1,64 +0,0 @@ -"""Mons controller test - kujira-api must already be running -""" - -import unittest -import requests -import common_test_methods - - - -class MonsTestCase(unittest.TestCase): - - clusters_id = None - response = None - data = None - - - def setUp(self): - clusters_data = requests.get("http://0.0.0.0:5000/kujira/api/v1/clusters").json() - self.clusters_id = common_test_methods.get_clusters_id(clusters_data) - self.response = requests.get("http://0.0.0.0:5000/kujira/api/v1/mons/" + str(self.clusters_id)) - self.data = self.response.json() - - - def tearDown(self): - self.clusters_id = None - self.response = None - self.data = None - - - - def test_expectedResponse(self): - common_test_methods.test_expectedResponse(self, self.response, self.data) - - def test_consistDataKey(self): - common_test_methods.test_consistDataKey(self, self.data) - - def test_expectedDataStructure(self): - common_test_methods.test_expectedDataStructure(self, self.data) - - def test_KeysInDatalistOfDictionaries(self): - common_test_methods.test_KeysInDatalistOfDictionaries(self, self.data) - - def test_type(self): - common_test_methods.test_type(self, self.data, 'mons') - - def test_expectedAttributesKeys(self): - list_of_expected_attributes = [] - list_of_expected_attributes.append('name') - list_of_expected_attributes.append('in-quorum') - list_of_expected_attributes.append('addr') - list_of_expected_attributes.append('rank') - list_of_expected_attributes.append('server') - common_test_methods.test_expectedAttributesKeys(self, self.data, list_of_expected_attributes) - - def test_server_name(self): - for j in range(len(self.data['data'])): - id = self.data['data'][j]['id'] - self.assertEqual(self.data['data'][j]['attributes']['name'], id) - self.assertEqual(self.data['data'][j]['attributes']['server'], id) - - -if __name__ == '__main__': - unittest.main() \ No newline at end of file diff --git a/tests/rest/controllers/test_pools.py b/tests/rest/controllers/test_pools.py deleted file mode 100644 index c983470..0000000 --- a/tests/rest/controllers/test_pools.py +++ /dev/null @@ -1,69 +0,0 @@ -"""Pools controller test - kujira-api must already be running -""" - -import unittest -import requests -import common_test_methods - - - -class PoolsTestCase(unittest.TestCase): - - clusters_id = None - response = None - data = None - - - def setUp(self): - clusters_data = requests.get("http://0.0.0.0:5000/kujira/api/v1/clusters").json() - self.clusters_id = common_test_methods.get_clusters_id(clusters_data) - self.response = requests.get("http://0.0.0.0:5000/kujira/api/v1/pools/" + str(self.clusters_id)) - self.data = self.response.json() - - def tearDown(self): - self.clusters_id = None - self.response = None - self.data = None - - - - def test_expectedResponse(self): - common_test_methods.test_expectedResponse(self, self.response, self.data) - - def test_consistDataKey(self): - common_test_methods.test_consistDataKey(self, self.data) - - def test_expectedDataStructure(self): - common_test_methods.test_expectedDataStructure(self, self.data) - - def test_KeysInDatalistOfDictionaries(self): - common_test_methods.test_KeysInDatalistOfDictionaries(self, self.data) - - def test_type(self): - common_test_methods.test_type(self, self.data, 'pools') - - def test_expectedAttributesKeys(self): - list_of_expected_attributes = [] - list_of_expected_attributes.append('full') - list_of_expected_attributes.append('name') - list_of_expected_attributes.append('id') - list_of_expected_attributes.append('crush-ruleset') - list_of_expected_attributes.append('crash-replay-interval') - list_of_expected_attributes.append('hashpspool') - list_of_expected_attributes.append('pg-num') - list_of_expected_attributes.append('quota-max-bytes') - list_of_expected_attributes.append('size') - list_of_expected_attributes.append('pgp-num') - list_of_expected_attributes.append('min-size') - list_of_expected_attributes.append('quota-max-objects') - common_test_methods.test_expectedAttributesKeys(self, self.data, list_of_expected_attributes) - - def test_id_equals(self): - for j in range(len(self.data['data'])): - id = self.data['data'][j]['id'] - self.assertEqual(str(self.data['data'][j]['attributes']['id']), id) - - -if __name__ == '__main__': - unittest.main() \ No newline at end of file diff --git a/tests/rest/__init__.py b/tests/rest/tests_controllers/__init__.py similarity index 100% rename from tests/rest/__init__.py rename to tests/rest/tests_controllers/__init__.py diff --git a/tests/rest/tests_controllers/common_testing_methods.py b/tests/rest/tests_controllers/common_testing_methods.py new file mode 100644 index 0000000..cbd9901 --- /dev/null +++ b/tests/rest/tests_controllers/common_testing_methods.py @@ -0,0 +1,158 @@ +"""Common testing methods""" + +import unittest +import requests + + +class CommonTestinglMethods(unittest.TestCase): + """Base class for mons, osds and pools controllers test cases""" + + clusters_data = None + clusters_id = None + response = None + data = None + type = None + expected_attributes = None + + + def setUp(self): + self.clusters_data = requests.get("http://0.0.0.0:5000/kujira/api/v1/"+"clusters").json() + self.clusters_id = self.get_clusters_id() + self.response = requests.get("http://0.0.0.0:5000/kujira/api/v1/" + self.type + "/" + self.clusters_id) + self.data = self.response.json() + + + def tearDown(self): + self.clusters_data = None + self.clusters_id = None + self.response = None + self.data = None + + + def get_clusters_id(self): + """Using to get cluster id parameter + which will be used later to request for mons, pools and osds + :return: field id from clusters response + """ + self.clusters_id = self.clusters_data['data']['id'] + return self.clusters_id + + + def test_expected_response(self): + """Test for expected response: + status code= 200, + response is dictionary.""" + self.assertEqual(self.response.status_code, 200) + self.assertTrue(isinstance(self.data, dict)) + + + def test_consist_data_key(self): + """Testing does response consist data key: + { + # DATA KEY - "data" + "data": [ + { + ... + }, + ... + ] + } + """ + self.assertIn('data', self.data) + + + def test_expected_data_structure(self): + """Testing does reponse structure is the same as expected: + { + "data": [ + { + # IS DICTIONARY + "attributes":{ + # IS DICTIONARY + ... + }, + ... + }, + ... + ] + } + """ + self.assertTrue(isinstance(self.data['data'], list)) + for j in range(len(self.data['data'])): + self.assertTrue(isinstance(self.data['data'][j], dict)) + self.assertTrue(isinstance(self.data['data'][j]['attributes'], dict)) + + + def test_keys_in__data_list(self): + """Testing keys in data list of dictionaries: + { + "data": [ + { + # RESPONSE CONSIST KEY "attributes" + "attributes":{ + ... + }, + # RESPONSE CONSIST KEY "type" + "type": "some value", + # RESPONSE CONSIST KEY "id" + "id": "some value" + }, + ... + ] + } + """ + for j in range(len(self.data['data'])): + self.assertIn('attributes', self.data['data'][j]) + self.assertIn('type', self.data['data'][j]) + self.assertIn('id', self.data['data'][j]) + + + def test_type(self): + """Testing response type""" + for j in range(len(self.data['data'])): + self.assertEqual(self.data['data'][j]['type'], self.type) + + + def test_expected_attributes_keys(self): + """ Testing keys in "attributes" dictionary""" + if self.type == "mons": + self.expected_attributes = [] + self.expected_attributes.append('name') + self.expected_attributes.append('in-quorum') + self.expected_attributes.append('addr') + self.expected_attributes.append('rank') + self.expected_attributes.append('server') + elif self.type == "pools": + self.expected_attributes = [] + self.expected_attributes.append('full') + self.expected_attributes.append('name') + self.expected_attributes.append('id') + self.expected_attributes.append('crush-ruleset') + self.expected_attributes.append('crash-replay-interval') + self.expected_attributes.append('hashpspool') + self.expected_attributes.append('pg-num') + self.expected_attributes.append('quota-max-bytes') + self.expected_attributes.append('size') + self.expected_attributes.append('pgp-num') + self.expected_attributes.append('min-size') + self.expected_attributes.append('quota-max-objects') + elif self.type == "osds": + self.expected_attributes = [] + self.expected_attributes.append('crush-node-ancestry') + self.expected_attributes.append('uuid') + self.expected_attributes.append('public-addr') + self.expected_attributes.append('reweight') + self.expected_attributes.append('valid-commands') + self.expected_attributes.append('up') + self.expected_attributes.append('server') + self.expected_attributes.append('cluster-addr') + self.expected_attributes.append('in') + self.expected_attributes.append('pools') + self.expected_attributes.append('id') + for j in range(len(self.data['data'])): + for k in range(len(self.expected_attributes)): + self.assertIn(self.expected_attributes[k], self.data['data'][j]['attributes']) + + +if __name__ == '__main__': + unittest.main() diff --git a/tests/rest/controllers/test_calamari_api_connection.py b/tests/rest/tests_controllers/test_calamari_api_connection.py similarity index 100% rename from tests/rest/controllers/test_calamari_api_connection.py rename to tests/rest/tests_controllers/test_calamari_api_connection.py diff --git a/tests/rest/controllers/test_clusters.py b/tests/rest/tests_controllers/test_clusters.py similarity index 97% rename from tests/rest/controllers/test_clusters.py rename to tests/rest/tests_controllers/test_clusters.py index a4eafb9..91355fa 100644 --- a/tests/rest/controllers/test_clusters.py +++ b/tests/rest/tests_controllers/test_clusters.py @@ -1,5 +1,5 @@ """Clusters controller test - kujira-api must already be running + - kujira-api must already be running """ import unittest @@ -27,7 +27,8 @@ def tearDown(self): def test_expected_response(self): """Test for expected response: status code= 200, - response is dictionary.""" + response is dictionary + """ self.assertEqual(self.response.status_code, 200) self.assertTrue(isinstance(self.data, dict)) @@ -40,7 +41,7 @@ def test_consist_data_key(self): ... } } - """ + """ self.assertIn('data', self.data) diff --git a/tests/rest/tests_controllers/test_mons.py b/tests/rest/tests_controllers/test_mons.py new file mode 100644 index 0000000..a2307c8 --- /dev/null +++ b/tests/rest/tests_controllers/test_mons.py @@ -0,0 +1,24 @@ +"""Mons controller tests + kujira-api must already be running +""" + +import common_testing_methods + + +class MonsTestCase(common_testing_methods.CommonTestinglMethods): + """Mons controllers test case, + inherits testing methods from CommonTestingMethods""" + + type = "mons" + + + def test_server_name(self): + """Testing does response server name equals to response id""" + for j in range(len(self.data['data'])): + data_id = self.data['data'][j]['id'] + self.assertEqual(self.data['data'][j]['attributes']['name'], data_id) + self.assertEqual(self.data['data'][j]['attributes']['server'], data_id) + + +if __name__ == '__main__': + common_testing_methods.main() diff --git a/tests/rest/tests_controllers/test_osds.py b/tests/rest/tests_controllers/test_osds.py new file mode 100644 index 0000000..4c4b964 --- /dev/null +++ b/tests/rest/tests_controllers/test_osds.py @@ -0,0 +1,26 @@ +"""Osds controller tests + kujira-api must already be running +""" + +import common_testing_methods + + +class OsdsTestCase(common_testing_methods.CommonTestinglMethods): + """Osds controllers test case, + inherits testing methods from CommonTestingMethods""" + + type = "osds" + + + def test_osds_specific_structure(self): + """Testing does the response attributes dictionary + structure is the same as expected""" + for i in range(len(self.data['data'])): + self.assertTrue(isinstance(self.data['data'][i]['attributes']['crush-node-ancestry'], list)) + self.assertTrue(isinstance(self.data['data'][i]['attributes']['valid-commands'], list)) + self.assertTrue(isinstance(self.data['data'][i]['attributes']['pools'], list)) + + + +if __name__ == '__main__': + common_testing_methods.main() diff --git a/tests/rest/tests_controllers/test_pools.py b/tests/rest/tests_controllers/test_pools.py new file mode 100644 index 0000000..45bc6c3 --- /dev/null +++ b/tests/rest/tests_controllers/test_pools.py @@ -0,0 +1,23 @@ +"""Pools controller tests + kujira-api must already be running +""" + +import common_testing_methods + + +class PoolsTestCase(common_testing_methods.CommonTestinglMethods): + """Pools controllers test case, + inherits testing methods from CommonTestingMethods""" + + type = "pools" + + + def test_id_equals(self): + """Testing does data id equals to data atrributes id""" + for j in range(len(self.data['data'])): + data_id = self.data['data'][j]['id'] + self.assertEqual(str(self.data['data'][j]['attributes']['id']), data_id) + + +if __name__ == '__main__': + common_testing_methods.main() From b4e67c9138cde297f7f160ba999eddfc469e6031 Mon Sep 17 00:00:00 2001 From: vmyrhorodskyi Date: Tue, 21 Jun 2016 08:41:09 +0200 Subject: [PATCH 06/10] Changed distance between class methods --- .../tests_controllers/common_testing_methods.py | 9 --------- .../test_calamari_api_connection.py | 2 -- tests/rest/tests_controllers/test_clusters.py | 13 +------------ tests/rest/tests_controllers/test_mons.py | 2 -- tests/rest/tests_controllers/test_osds.py | 3 --- tests/rest/tests_controllers/test_pools.py | 2 -- 6 files changed, 1 insertion(+), 30 deletions(-) diff --git a/tests/rest/tests_controllers/common_testing_methods.py b/tests/rest/tests_controllers/common_testing_methods.py index cbd9901..2ed935f 100644 --- a/tests/rest/tests_controllers/common_testing_methods.py +++ b/tests/rest/tests_controllers/common_testing_methods.py @@ -21,14 +21,12 @@ def setUp(self): self.response = requests.get("http://0.0.0.0:5000/kujira/api/v1/" + self.type + "/" + self.clusters_id) self.data = self.response.json() - def tearDown(self): self.clusters_data = None self.clusters_id = None self.response = None self.data = None - def get_clusters_id(self): """Using to get cluster id parameter which will be used later to request for mons, pools and osds @@ -37,7 +35,6 @@ def get_clusters_id(self): self.clusters_id = self.clusters_data['data']['id'] return self.clusters_id - def test_expected_response(self): """Test for expected response: status code= 200, @@ -45,7 +42,6 @@ def test_expected_response(self): self.assertEqual(self.response.status_code, 200) self.assertTrue(isinstance(self.data, dict)) - def test_consist_data_key(self): """Testing does response consist data key: { @@ -60,7 +56,6 @@ def test_consist_data_key(self): """ self.assertIn('data', self.data) - def test_expected_data_structure(self): """Testing does reponse structure is the same as expected: { @@ -82,7 +77,6 @@ def test_expected_data_structure(self): self.assertTrue(isinstance(self.data['data'][j], dict)) self.assertTrue(isinstance(self.data['data'][j]['attributes'], dict)) - def test_keys_in__data_list(self): """Testing keys in data list of dictionaries: { @@ -106,13 +100,11 @@ def test_keys_in__data_list(self): self.assertIn('type', self.data['data'][j]) self.assertIn('id', self.data['data'][j]) - def test_type(self): """Testing response type""" for j in range(len(self.data['data'])): self.assertEqual(self.data['data'][j]['type'], self.type) - def test_expected_attributes_keys(self): """ Testing keys in "attributes" dictionary""" if self.type == "mons": @@ -153,6 +145,5 @@ def test_expected_attributes_keys(self): for k in range(len(self.expected_attributes)): self.assertIn(self.expected_attributes[k], self.data['data'][j]['attributes']) - if __name__ == '__main__': unittest.main() diff --git a/tests/rest/tests_controllers/test_calamari_api_connection.py b/tests/rest/tests_controllers/test_calamari_api_connection.py index 1f73292..d18eaa4 100644 --- a/tests/rest/tests_controllers/test_calamari_api_connection.py +++ b/tests/rest/tests_controllers/test_calamari_api_connection.py @@ -22,7 +22,6 @@ def test_server_is_up_and_running(self): response = client.get(constr._api_url, timeout=constr._timeout) self.assertEqual(response.status_code, 200) - def test_error_422(self): """ Testing request with wrong Calamari API url: 422 error is expected @@ -38,6 +37,5 @@ def test_error_422(self): response = create_error_422(constr._api_url, str(err)) self.assertEqual(response.status_code, 422) - if __name__ == '__main__': unittest.main() diff --git a/tests/rest/tests_controllers/test_clusters.py b/tests/rest/tests_controllers/test_clusters.py index 91355fa..3b8cff6 100644 --- a/tests/rest/tests_controllers/test_clusters.py +++ b/tests/rest/tests_controllers/test_clusters.py @@ -12,18 +12,14 @@ class ClustersTestCase(unittest.TestCase): response = None data = None - def setUp(self): - self.response = requests.get("http://0.0.0.0:5000/kujira/api/v1/" + - "clusters") + self.response = requests.get("http://0.0.0.0:5000/kujira/api/v1/" + "clusters") self.data = self.response.json() - def tearDown(self): self.response = None self.data = None - def test_expected_response(self): """Test for expected response: status code= 200, @@ -32,7 +28,6 @@ def test_expected_response(self): self.assertEqual(self.response.status_code, 200) self.assertTrue(isinstance(self.data, dict)) - def test_consist_data_key(self): """Testing does response consist data key: { @@ -44,7 +39,6 @@ def test_consist_data_key(self): """ self.assertIn('data', self.data) - def test_expected_data_structure(self): """Testing does reponse structure is the same as expected: { @@ -61,7 +55,6 @@ def test_expected_data_structure(self): self.assertTrue(isinstance(self.data['data'], dict)) self.assertTrue(isinstance(self.data['data']['attributes'], dict)) - def test_keys_in_data_dictionary(self): """Testing keys in data dictionary: { @@ -81,7 +74,6 @@ def test_keys_in_data_dictionary(self): self.assertIn('type', self.data['data']) self.assertIn('id', self.data['data']) - def test_type(self): """ "type": "clusters" test: { @@ -95,7 +87,6 @@ def test_type(self): """ self.assertEqual(self.data['data']['type'], 'clusters') - def test_expected_attributes_keys(self): """ Testing keys in "attributes" dictionary: { @@ -117,7 +108,6 @@ def test_expected_attributes_keys(self): self.assertIn('id', self.data['data']['attributes']) self.assertIn('name', self.data['data']['attributes']) - def test_name(self): """ "name": "ceph" test: { @@ -133,7 +123,6 @@ def test_name(self): """ self.assertEqual(self.data['data']['attributes']['name'], 'ceph') - if __name__ == '__main__': unittest.main() diff --git a/tests/rest/tests_controllers/test_mons.py b/tests/rest/tests_controllers/test_mons.py index a2307c8..1dc0bc5 100644 --- a/tests/rest/tests_controllers/test_mons.py +++ b/tests/rest/tests_controllers/test_mons.py @@ -11,7 +11,6 @@ class MonsTestCase(common_testing_methods.CommonTestinglMethods): type = "mons" - def test_server_name(self): """Testing does response server name equals to response id""" for j in range(len(self.data['data'])): @@ -19,6 +18,5 @@ def test_server_name(self): self.assertEqual(self.data['data'][j]['attributes']['name'], data_id) self.assertEqual(self.data['data'][j]['attributes']['server'], data_id) - if __name__ == '__main__': common_testing_methods.main() diff --git a/tests/rest/tests_controllers/test_osds.py b/tests/rest/tests_controllers/test_osds.py index 4c4b964..45af144 100644 --- a/tests/rest/tests_controllers/test_osds.py +++ b/tests/rest/tests_controllers/test_osds.py @@ -11,7 +11,6 @@ class OsdsTestCase(common_testing_methods.CommonTestinglMethods): type = "osds" - def test_osds_specific_structure(self): """Testing does the response attributes dictionary structure is the same as expected""" @@ -20,7 +19,5 @@ def test_osds_specific_structure(self): self.assertTrue(isinstance(self.data['data'][i]['attributes']['valid-commands'], list)) self.assertTrue(isinstance(self.data['data'][i]['attributes']['pools'], list)) - - if __name__ == '__main__': common_testing_methods.main() diff --git a/tests/rest/tests_controllers/test_pools.py b/tests/rest/tests_controllers/test_pools.py index 45bc6c3..4a38118 100644 --- a/tests/rest/tests_controllers/test_pools.py +++ b/tests/rest/tests_controllers/test_pools.py @@ -11,13 +11,11 @@ class PoolsTestCase(common_testing_methods.CommonTestinglMethods): type = "pools" - def test_id_equals(self): """Testing does data id equals to data atrributes id""" for j in range(len(self.data['data'])): data_id = self.data['data'][j]['id'] self.assertEqual(str(self.data['data'][j]['attributes']['id']), data_id) - if __name__ == '__main__': common_testing_methods.main() From f9cf3ea7fccbee4f64cc7e030131326f0fbe1641 Mon Sep 17 00:00:00 2001 From: vmyrhorodskyi Date: Tue, 21 Jun 2016 08:54:49 +0200 Subject: [PATCH 07/10] Changed distance between class methods --- tests/rest/tests_controllers/common_testing_methods.py | 1 + tests/rest/tests_controllers/test_calamari_api_connection.py | 1 + tests/rest/tests_controllers/test_clusters.py | 1 + tests/rest/tests_controllers/test_mons.py | 1 + tests/rest/tests_controllers/test_osds.py | 1 + tests/rest/tests_controllers/test_pools.py | 1 + 6 files changed, 6 insertions(+) diff --git a/tests/rest/tests_controllers/common_testing_methods.py b/tests/rest/tests_controllers/common_testing_methods.py index 2ed935f..14e8fc8 100644 --- a/tests/rest/tests_controllers/common_testing_methods.py +++ b/tests/rest/tests_controllers/common_testing_methods.py @@ -145,5 +145,6 @@ def test_expected_attributes_keys(self): for k in range(len(self.expected_attributes)): self.assertIn(self.expected_attributes[k], self.data['data'][j]['attributes']) + if __name__ == '__main__': unittest.main() diff --git a/tests/rest/tests_controllers/test_calamari_api_connection.py b/tests/rest/tests_controllers/test_calamari_api_connection.py index d18eaa4..f077c30 100644 --- a/tests/rest/tests_controllers/test_calamari_api_connection.py +++ b/tests/rest/tests_controllers/test_calamari_api_connection.py @@ -37,5 +37,6 @@ def test_error_422(self): response = create_error_422(constr._api_url, str(err)) self.assertEqual(response.status_code, 422) + if __name__ == '__main__': unittest.main() diff --git a/tests/rest/tests_controllers/test_clusters.py b/tests/rest/tests_controllers/test_clusters.py index 3b8cff6..f8331b0 100644 --- a/tests/rest/tests_controllers/test_clusters.py +++ b/tests/rest/tests_controllers/test_clusters.py @@ -123,6 +123,7 @@ def test_name(self): """ self.assertEqual(self.data['data']['attributes']['name'], 'ceph') + if __name__ == '__main__': unittest.main() diff --git a/tests/rest/tests_controllers/test_mons.py b/tests/rest/tests_controllers/test_mons.py index 1dc0bc5..a85623d 100644 --- a/tests/rest/tests_controllers/test_mons.py +++ b/tests/rest/tests_controllers/test_mons.py @@ -18,5 +18,6 @@ def test_server_name(self): self.assertEqual(self.data['data'][j]['attributes']['name'], data_id) self.assertEqual(self.data['data'][j]['attributes']['server'], data_id) + if __name__ == '__main__': common_testing_methods.main() diff --git a/tests/rest/tests_controllers/test_osds.py b/tests/rest/tests_controllers/test_osds.py index 45af144..21037a6 100644 --- a/tests/rest/tests_controllers/test_osds.py +++ b/tests/rest/tests_controllers/test_osds.py @@ -19,5 +19,6 @@ def test_osds_specific_structure(self): self.assertTrue(isinstance(self.data['data'][i]['attributes']['valid-commands'], list)) self.assertTrue(isinstance(self.data['data'][i]['attributes']['pools'], list)) + if __name__ == '__main__': common_testing_methods.main() diff --git a/tests/rest/tests_controllers/test_pools.py b/tests/rest/tests_controllers/test_pools.py index 4a38118..2547340 100644 --- a/tests/rest/tests_controllers/test_pools.py +++ b/tests/rest/tests_controllers/test_pools.py @@ -17,5 +17,6 @@ def test_id_equals(self): data_id = self.data['data'][j]['id'] self.assertEqual(str(self.data['data'][j]['attributes']['id']), data_id) + if __name__ == '__main__': common_testing_methods.main() From e17e8357795194b3bf5e12a39a7a76c18848d9c3 Mon Sep 17 00:00:00 2001 From: vmyrhorodskyi Date: Tue, 21 Jun 2016 09:07:36 +0200 Subject: [PATCH 08/10] common test methods: distance between two methods --- tests/rest/tests_controllers/common_testing_methods.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/rest/tests_controllers/common_testing_methods.py b/tests/rest/tests_controllers/common_testing_methods.py index 14e8fc8..6238ab5 100644 --- a/tests/rest/tests_controllers/common_testing_methods.py +++ b/tests/rest/tests_controllers/common_testing_methods.py @@ -14,7 +14,6 @@ class CommonTestinglMethods(unittest.TestCase): type = None expected_attributes = None - def setUp(self): self.clusters_data = requests.get("http://0.0.0.0:5000/kujira/api/v1/"+"clusters").json() self.clusters_id = self.get_clusters_id() From b315efdea88804b0c05f182a7d67156ca9e2ae8e Mon Sep 17 00:00:00 2001 From: vmyrhorodskyi Date: Tue, 21 Jun 2016 10:56:40 +0200 Subject: [PATCH 09/10] Clusters request strig url was changed --- tests/rest/tests_controllers/common_testing_methods.py | 2 +- tests/rest/tests_controllers/test_clusters.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/rest/tests_controllers/common_testing_methods.py b/tests/rest/tests_controllers/common_testing_methods.py index 6238ab5..48a6a97 100644 --- a/tests/rest/tests_controllers/common_testing_methods.py +++ b/tests/rest/tests_controllers/common_testing_methods.py @@ -15,7 +15,7 @@ class CommonTestinglMethods(unittest.TestCase): expected_attributes = None def setUp(self): - self.clusters_data = requests.get("http://0.0.0.0:5000/kujira/api/v1/"+"clusters").json() + self.clusters_data = requests.get("http://0.0.0.0:5000/kujira/api/v1/clusters").json() self.clusters_id = self.get_clusters_id() self.response = requests.get("http://0.0.0.0:5000/kujira/api/v1/" + self.type + "/" + self.clusters_id) self.data = self.response.json() diff --git a/tests/rest/tests_controllers/test_clusters.py b/tests/rest/tests_controllers/test_clusters.py index f8331b0..0612e8b 100644 --- a/tests/rest/tests_controllers/test_clusters.py +++ b/tests/rest/tests_controllers/test_clusters.py @@ -13,7 +13,7 @@ class ClustersTestCase(unittest.TestCase): data = None def setUp(self): - self.response = requests.get("http://0.0.0.0:5000/kujira/api/v1/" + "clusters") + self.response = requests.get("http://0.0.0.0:5000/kujira/api/v1/clusters") self.data = self.response.json() def tearDown(self): From 9c932efecf57f2160b8ba285d50e0911a5a2cca3 Mon Sep 17 00:00:00 2001 From: vmyrhorodskyi Date: Tue, 21 Jun 2016 11:41:40 +0200 Subject: [PATCH 10/10] Test methods were actualized after blueprints changing --- .../tests_controllers/common_testing_methods.py | 15 ++------------- .../test_calamari_api_connection.py | 16 ++++++++-------- tests/rest/tests_controllers/test_clusters.py | 2 +- 3 files changed, 11 insertions(+), 22 deletions(-) diff --git a/tests/rest/tests_controllers/common_testing_methods.py b/tests/rest/tests_controllers/common_testing_methods.py index 48a6a97..64df9f7 100644 --- a/tests/rest/tests_controllers/common_testing_methods.py +++ b/tests/rest/tests_controllers/common_testing_methods.py @@ -8,32 +8,21 @@ class CommonTestinglMethods(unittest.TestCase): """Base class for mons, osds and pools controllers test cases""" clusters_data = None - clusters_id = None response = None data = None type = None expected_attributes = None def setUp(self): - self.clusters_data = requests.get("http://0.0.0.0:5000/kujira/api/v1/clusters").json() - self.clusters_id = self.get_clusters_id() - self.response = requests.get("http://0.0.0.0:5000/kujira/api/v1/" + self.type + "/" + self.clusters_id) + self.clusters_data = requests.get("http://0.0.0.0:5000/kujira/api/v1/calamari/clusters").json() + self.response = requests.get("http://0.0.0.0:5000/kujira/api/v1/calamari/" + self.type) self.data = self.response.json() def tearDown(self): self.clusters_data = None - self.clusters_id = None self.response = None self.data = None - def get_clusters_id(self): - """Using to get cluster id parameter - which will be used later to request for mons, pools and osds - :return: field id from clusters response - """ - self.clusters_id = self.clusters_data['data']['id'] - return self.clusters_id - def test_expected_response(self): """Test for expected response: status code= 200, diff --git a/tests/rest/tests_controllers/test_calamari_api_connection.py b/tests/rest/tests_controllers/test_calamari_api_connection.py index f077c30..597a03a 100644 --- a/tests/rest/tests_controllers/test_calamari_api_connection.py +++ b/tests/rest/tests_controllers/test_calamari_api_connection.py @@ -1,8 +1,8 @@ """Calamari API connection tests""" import unittest +import config from requests import ConnectionError -from config import CALAMARI_API_URL, CALAMARI_API_PWD, CALAMARI_API_USER, CALAMARI_API_TIMEOUT from kujira.rest.lib.calamari_client import CalamariClient from kujira.rest.lib.parsing_methods import create_error_422 @@ -14,10 +14,10 @@ def test_server_is_up_and_running(self): """ Calamari API request test: expected response status code - 200 """ - constr = CalamariClient(api_url=CALAMARI_API_URL, - username=CALAMARI_API_USER, - password=CALAMARI_API_PWD, - timeout=CALAMARI_API_TIMEOUT) + constr = CalamariClient(api_url=config.CALAMARI_API_URL, + username=config.CALAMARI_API_USER, + password=config.CALAMARI_API_PWD, + timeout=config.CALAMARI_API_TIMEOUT) client = constr.authenticate() response = client.get(constr._api_url, timeout=constr._timeout) self.assertEqual(response.status_code, 200) @@ -28,9 +28,9 @@ def test_error_422(self): """ try: constr = CalamariClient(api_url="http://wrong_calamari_api_url/api/v2/", - username=CALAMARI_API_USER, - password=CALAMARI_API_PWD, - timeout=CALAMARI_API_TIMEOUT) + username=config.CALAMARI_API_USER, + password=config.CALAMARI_API_PWD, + timeout=config.CALAMARI_API_TIMEOUT) client = constr.authenticate() response = client.get(constr._api_url, timeout=constr._timeout) except ConnectionError as err: diff --git a/tests/rest/tests_controllers/test_clusters.py b/tests/rest/tests_controllers/test_clusters.py index 0612e8b..eee7987 100644 --- a/tests/rest/tests_controllers/test_clusters.py +++ b/tests/rest/tests_controllers/test_clusters.py @@ -13,7 +13,7 @@ class ClustersTestCase(unittest.TestCase): data = None def setUp(self): - self.response = requests.get("http://0.0.0.0:5000/kujira/api/v1/clusters") + self.response = requests.get("http://0.0.0.0:5000/kujira/api/v1/calamari/clusters") self.data = self.response.json() def tearDown(self):