diff options
author | Sastry Isukapalli <sastry@research.att.com> | 2018-03-15 02:28:32 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2018-03-15 02:28:32 +0000 |
commit | 13b79a8318b767c55109f5ab5d2b8454ec03f7b6 (patch) | |
tree | 691d08b78872acfbf9ab1d20186d1fb155e4a1c2 | |
parent | e4cee54e5b2bf43b3da857866036b1d178ee9617 (diff) | |
parent | 4cff4c23d5f17f6e67b25b1224996c4f56c544f4 (diff) |
Merge "Adding more unit tests and .coveragerc"
-rw-r--r-- | conductor/.coveragerc | 21 | ||||
-rw-r--r-- | conductor/conductor/tests/unit/data/constraints.json | 50 | ||||
-rw-r--r-- | conductor/conductor/tests/unit/data/test_service.py | 82 |
3 files changed, 149 insertions, 4 deletions
diff --git a/conductor/.coveragerc b/conductor/.coveragerc new file mode 100644 index 0000000..10eba38 --- /dev/null +++ b/conductor/.coveragerc @@ -0,0 +1,21 @@ +# .coveragerc to control coverage.py +[report] +# Regexes for lines to exclude from consideration +exclude_lines = + # Have to re-enable the standard pragma + pragma: no cover + + # Don't complain about missing debug-only code: + def __repr__ + def main() + if self\.debug + + # Don't complain if tests don't hit defensive assertion code: + raise AssertionError + raise NotImplementedError + + # Don't complain if non-runnable code isn't run: + if 0: + if __name__ == .__main__.: + +ignore_errors = True diff --git a/conductor/conductor/tests/unit/data/constraints.json b/conductor/conductor/tests/unit/data/constraints.json index f7e9250..3b26a3a 100644 --- a/conductor/conductor/tests/unit/data/constraints.json +++ b/conductor/conductor/tests/unit/data/constraints.json @@ -58,6 +58,26 @@ "cloud_owner": "att-aic", "cloud_region_version": "1.1", "physical_location_id": "SFOCA55" + }, + { + "candidate_id": "instance-1", + "candidate_type": "service", + "inventory_type": "service", + "inventory_provider": "aai", + "host_id": "vnf_333", + "cost": "100", + "location_id": "SFOCA55", + "location_type": "azure", + "latitude": "32.897480", + "longitude": "-97.040443", + "city": "San Francisco", + "state": "CA", + "country": "USA", + "region": "US", + "complex_name": "sfo_one", + "cloud_owner": "att-aic", + "cloud_region_version": "1.1", + "physical_location_id": "SFOCA55" } ], "constraint_type": "instance_fit", @@ -71,6 +91,7 @@ "properties": { "evaluate": { "network_roles": "", + "replication_role": "candidate-role1", "complex_name": { "any": [ "dalls_one" @@ -90,7 +111,36 @@ "all": [ "US" ] + }, + "cloud-region": { + "cloud-requests": [ + "NYCNY55", + "DLLSTX55" + ], + "service-requests": [ + "DLLSTX55" + ] } } + }, + "resolved_candidate": { + "candidate_id": "instance-2", + "candidate_type": "service", + "inventory_type": "service", + "inventory_provider": "aai", + "host_id": "vnf_333", + "cost": "100", + "location_id": "SFOCA55", + "location_type": "azure", + "latitude": "32.897480", + "longitude": "-97.040443", + "city": "San Francisco", + "state": "CA", + "country": "USA", + "region": "US", + "complex_name": "sfo_one", + "cloud_owner": "att-aic", + "cloud_region_version": "1.1", + "physical_location_id": "SFOCA55" } }
\ No newline at end of file diff --git a/conductor/conductor/tests/unit/data/test_service.py b/conductor/conductor/tests/unit/data/test_service.py index e2fba3e..89f1833 100644 --- a/conductor/conductor/tests/unit/data/test_service.py +++ b/conductor/conductor/tests/unit/data/test_service.py @@ -104,7 +104,7 @@ class TestDataEndpoint(unittest.TestCase): value_attrib = 'complex_name' value = req_json['properties']['evaluate'][value_attrib] candidate_list = req_json['candidate_list'] - self.assertEqual(2, len(self.data_ep.get_candidate_discard_set(value, + self.assertEqual(3, len(self.data_ep.get_candidate_discard_set(value, candidate_list, value_attrib))) value_attrib = 'region' @@ -113,6 +113,44 @@ class TestDataEndpoint(unittest.TestCase): candidate_list, value_attrib))) + def test_get_candidate_discard_set_by_cloud_region(self): + req_json_file = './conductor/tests/unit/data/constraints.json' + req_json = yaml.safe_load(open(req_json_file).read()) + value_attrib = 'location_id' + value = req_json['properties']['evaluate']['cloud-region'] + candidate_list = req_json['candidate_list'] + self.assertEqual(2, len( + self.data_ep.get_candidate_discard_set_by_cloud_region(value, + candidate_list, + value_attrib))) + + @mock.patch.object(service.LOG, 'error') + @mock.patch.object(service.LOG, 'debug') + @mock.patch.object(service.LOG, 'info') + @mock.patch.object(stevedore.ExtensionManager, 'map_method') + @mock.patch.object(stevedore.ExtensionManager, 'names') + def test_get_inventory_group_candidates(self, ext2_mock, ext1_mock, + info_mock, debug_mock, error_mock): + ext1_mock.return_value = None + req_json_file = './conductor/tests/unit/data/constraints.json' + req_json = yaml.safe_load(open(req_json_file).read()) + self.assertEqual({'response': [], 'error': True}, + self.data_ep.get_inventory_group_candidates(None, + arg=req_json)) + ext1_mock.return_value = [None] + self.assertEqual({'response': [], 'error': True}, + self.data_ep.get_inventory_group_candidates(None, + arg=req_json)) + pairs = [['instance-1', 'instance-2']] + ext1_mock.return_value = [pairs] + ext2_mock.return_value = ['aai'] + candidate_list = req_json['candidate_list'] + expected_candidate_list = [c for c in candidate_list + if c["candidate_id"] == 'instance-1'] + self.assertEqual({'response': expected_candidate_list, 'error': False}, + self.data_ep.get_inventory_group_candidates(None, + arg=req_json)) + @mock.patch.object(service.LOG, 'error') @mock.patch.object(service.LOG, 'debug') @mock.patch.object(service.LOG, 'info') @@ -123,20 +161,43 @@ class TestDataEndpoint(unittest.TestCase): req_json_file = './conductor/tests/unit/data/constraints.json' req_json = yaml.safe_load(open(req_json_file).read()) candidate_list = req_json['candidate_list'] - ext_mock1.return_value = [candidate_list] - ext_mock2.return_value = [None] + ext_mock1.side_effect = ip_ext_sideeffect + ext_mock2.return_value = ['aai'] self.maxDiff = None expected_response = {'response': [candidate_list[0]], 'error': False} self.assertEqual(expected_response, self.data_ep.get_candidates_by_attributes(None, req_json)) + req_json['properties']['evaluate']['network_roles'] = {"all": []} + expected_response = {'response': [candidate_list[0]], 'error': False} + self.assertEqual(expected_response, + self.data_ep.get_candidates_by_attributes(None, + req_json)) + req_json['properties']['evaluate']['network_roles'] = {"any": []} + expected_response = {'response': [candidate_list[0]], 'error': False} + self.assertEqual(expected_response, + self.data_ep.get_candidates_by_attributes(None, + req_json)) + req_json['properties']['evaluate']['network_roles'] = { + "all": ['role-1']} + expected_response = {'response': [], 'error': False} + self.assertEqual(expected_response, + self.data_ep.get_candidates_by_attributes(None, + req_json)) + req_json['properties']['evaluate']['network_roles'] = { + "all": ['role-2']} + expected_response = {'response': [], 'error': False} + self.assertEqual(expected_response, + self.data_ep.get_candidates_by_attributes(None, + req_json)) @mock.patch.object(service.LOG, 'error') @mock.patch.object(service.LOG, 'debug') @mock.patch.object(service.LOG, 'info') @mock.patch.object(log_util, 'getTransactionId') @mock.patch.object(stevedore.ExtensionManager, 'map_method') - def test_reslove_demands(self, ext_mock, logutil_mock, info_mock, debug_mock, + def test_reslove_demands(self, ext_mock, logutil_mock, info_mock, + debug_mock, error_mock): req_json_file = './conductor/tests/unit/data/demands.json' req_json = yaml.safe_load(open(req_json_file).read()) @@ -158,5 +219,18 @@ class TestDataEndpoint(unittest.TestCase): self.data_ep.resolve_demands(ctxt, req_json)) +def ip_ext_sideeffect(*args, **kwargs): + req_json_file = './conductor/tests/unit/data/constraints.json' + req_json = yaml.safe_load(open(req_json_file).read()) + candidate_list = req_json['candidate_list'] + if args[0] == 'check_network_roles': + if kwargs['network_role_id'] == 'role-1': + return None + else: + return ['DLLSTX55'] + elif args[0] == 'check_candidate_role': + return ['candidate-role0'] + + if __name__ == "__main__": unittest.main() |