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_vedges_vpp.py | |
parent | b88c78e3cf2bef22aa2f1c4d0bf305e303bc15f0 (diff) | |
parent | 7e83d0876ddb84a45e130eeba28bc40ef53c074b (diff) |
Merge "Calipso initial release for OPNFV"
Diffstat (limited to 'app/test/fetch/db_fetch/test_db_fetch_vedges_vpp.py')
-rw-r--r-- | app/test/fetch/db_fetch/test_db_fetch_vedges_vpp.py | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/app/test/fetch/db_fetch/test_db_fetch_vedges_vpp.py b/app/test/fetch/db_fetch/test_db_fetch_vedges_vpp.py new file mode 100644 index 0000000..9e6f497 --- /dev/null +++ b/app/test/fetch/db_fetch/test_db_fetch_vedges_vpp.py @@ -0,0 +1,82 @@ +############################################################################### +# 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 # +############################################################################### +from discover.fetchers.db.db_fetch_vedges_vpp import DbFetchVedgesVpp +from test.fetch.test_fetch import TestFetch +from test.fetch.db_fetch.test_data.db_fetch_vedges_vpp import * +from unittest.mock import MagicMock + + +class TestDbFetchVedgesVpp(TestFetch): + + def setUp(self): + self.configure_environment() + self.fetcher = DbFetchVedgesVpp() + self.fetcher.set_env(self.env) + + def check_get_results(self, version, + interfaces, host, + expected_results, err_msg): + original_run_fetch_lines = self.fetcher.run_fetch_lines + original_get_by_id = self.fetcher.inv.get_by_id + + self.fetcher.run_fetch_lines = MagicMock(side_effect=[version, interfaces]) + self.fetcher.inv.get_by_id = MagicMock(return_value=host) + + vedges = self.fetcher.get(VEDGE_FOLDER_ID) + self.assertEqual(vedges, expected_results, err_msg) + + self.fetcher.run_fetch_lines = original_run_fetch_lines + self.fetcher.inv.get_by_id = original_get_by_id + + def test_get(self): + test_cases = [ + { + "version": VERSION, + "interfaces": INTERFACES, + "host": HOST, + "expected_results": VEDGE_RESULTS, + "err_msg": "Can' get correct vedges" + }, + { + "version": [], + "interfaces": INTERFACES, + "host": HOST, + "expected_results": VEDGE_RESULTS_WITHOUT_BINARY, + "err_msg": "Can' get correct vedges when " + + "it can't get version info host" + }, + { + "version": VERSION, + "interfaces": INTERFACES, + "host": [], + "expected_results": [], + "err_msg": "Can't get [] when the host of the " + + "vedge doesn't exist in db" + }, + { + "version": VERSION, + "interfaces": INTERFACES, + "host": HOST_WITHOUT_REQUIRED_HOST_TYPE, + "expected_results": [], + "err_msg": "Can't get [] when the host of the " + + "vedge doesn't contains required host types" + } + ] + + for test_case in test_cases: + self.check_get_results(test_case["version"], + test_case["interfaces"], + test_case["host"], + test_case["expected_results"], + test_case["err_msg"]) + + def test_fetch_ports(self): + ports = self.fetcher.fetch_ports(INTERFACES) + self.assertEqual(ports, PORTS, "Can't get the correct ports info")
\ No newline at end of file |