diff options
author | 2017-07-27 15:04:07 +0000 | |
---|---|---|
committer | 2017-07-27 15:04:07 +0000 | |
commit | 162c03ef301396072c1934e7e7e0c40a841b4fe2 (patch) | |
tree | 7a2a2781949252436450ff5832962785061a774a /app/test/fetch/db_fetch/test_db_fetch_oteps.py | |
parent | b88c78e3cf2bef22aa2f1c4d0bf305e303bc15f0 (diff) | |
parent | 7e83d0876ddb84a45e130eeba28bc40ef53c074b (diff) |
Merge "Calipso initial release for OPNFV"
Diffstat (limited to 'app/test/fetch/db_fetch/test_db_fetch_oteps.py')
-rw-r--r-- | app/test/fetch/db_fetch/test_db_fetch_oteps.py | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/app/test/fetch/db_fetch/test_db_fetch_oteps.py b/app/test/fetch/db_fetch/test_db_fetch_oteps.py new file mode 100644 index 0000000..905f55a --- /dev/null +++ b/app/test/fetch/db_fetch/test_db_fetch_oteps.py @@ -0,0 +1,92 @@ +############################################################################### +# Copyright (c) 2017 Koren Lev (Cisco Systems), Yaron Yogev (Cisco Systems) # +# and others # +# # +# All rights reserved. This program and the accompanying materials # +# are made available under the terms of the Apache License, Version 2.0 # +# which accompanies this distribution, and is available at # +# http://www.apache.org/licenses/LICENSE-2.0 # +############################################################################### +import copy + +from discover.fetchers.db.db_fetch_oteps import DbFetchOteps +from test.fetch.test_fetch import TestFetch +from test.fetch.db_fetch.test_data.db_fetch_oteps import * +from unittest.mock import MagicMock + + +class TestDbFetchOteps(TestFetch): + + def setUp(self): + self.configure_environment() + self.fetcher = DbFetchOteps() + self.fetcher.set_env(self.env) + + def check_get_oteps_results(self, vedge, + config, + host, + oteps_from_db, + expected_results, + err_msg): + original_get_vconnector = self.fetcher.get_vconnector + self.fetcher.get_vconnector = MagicMock() + self.fetcher.inv.get_by_id = MagicMock(side_effect=[vedge, host]) + self.fetcher.config.get_env_config = MagicMock(return_value=config) + self.fetcher.get_objects_list_for_id = MagicMock(return_value=oteps_from_db) + results = self.fetcher.get(VEDGE_ID) + self.assertEqual(results, expected_results, err_msg) + self.fetcher.get_vconnector = original_get_vconnector + + def test_get(self): + test_cases = [ + { + "vedge": VEDGE_WITHOUT_CONFIGS, + "config": NON_ICEHOUSE_CONFIGS, + "host": None, + "oteps_from_db": None, + "expected_results": [], + "err_msg": "Can't get [] when the vedge " + + "doesn't contains configurations" + }, + { + "vedge": VEDGE_WITHOUT_TUNNEL_TYPES, + "config": NON_ICEHOUSE_CONFIGS, + "host": None, + "oteps_from_db": None, + "expected_results": [], + "err_msg": "Can't get [] when the vedge configurations " + + "doesn't contain tunnel_types" + }, + { + "vedge": VEDGE, + "config": ICEHOUSE_CONFIGS, + "host": HOST, + "oteps_from_db": None, + "expected_results": OTEPS_FOR_ICEHOUSE_DISTRIBUTION_RESULTS, + "err_msg": "Can't get correct oteps result " + + "when the distribution is icehouse" + }, + { + "vedge": VEDGE, + "config": NON_ICEHOUSE_CONFIGS, + "host": None, + "oteps_from_db": OTEPS, + "expected_results": OTEPS_FOR_NON_ICEHOUSE_DISTRIBUTION_RESULTS, + "err_msg": "Can't get correct oteps result " + + "when the distribution is not icehouse" + } + ] + for test_case in test_cases: + self.check_get_oteps_results(test_case["vedge"], + test_case["config"], + test_case["host"], + test_case["oteps_from_db"], + test_case["expected_results"], + test_case["err_msg"]) + + def test_get_vconnectors(self): + self.fetcher.run_fetch_lines = MagicMock(return_value=IFCONFIG_LINES) + self.fetcher.get_vconnector(OTEP_FOR_GETTING_VECONNECTOR, + HOST_ID, VEDGE) + self.assertEqual(OTEP_FOR_GETTING_VECONNECTOR, OTEP_WITH_CONNECTOR, + "Can't get vconnector from the config lines for otep") |