- @mock.patch('urllib2.urlopen',
- side_effect=urllib2.URLError('no host given'))
- def test_check_internet_connectivity_failed(self, mock_method):
- self.assertFalse(functest_utils.check_internet_connectivity())
- mock_method.assert_called_once_with(self.url, timeout=self.timeout)
-
- @mock.patch('urllib2.urlopen')
- def test_check_internet_connectivity_default(self, mock_method):
- self.assertTrue(functest_utils.check_internet_connectivity())
- mock_method.assert_called_once_with(self.url, timeout=self.timeout)
-
- @mock.patch('urllib2.urlopen')
- def test_check_internet_connectivity_debian(self, mock_method):
- self.url = "https://www.debian.org/"
- self.assertTrue(functest_utils.check_internet_connectivity(self.url))
- mock_method.assert_called_once_with(self.url, timeout=self.timeout)
-
- @mock.patch('urllib2.urlopen',
- side_effect=urllib2.URLError('no host given'))
- def test_download_url_failed(self, mock_url):
- self.assertFalse(functest_utils.download_url(self.url, self.dest_path))
-
- @mock.patch('urllib2.urlopen')
- def test_download_url_default(self, mock_url):
- with mock.patch("__builtin__.open", mock.mock_open()) as m, \
- mock.patch('functest.utils.functest_utils.shutil.copyfileobj')\
- as mock_sh:
- name = self.url.rsplit('/')[-1]
- dest = self.dest_path + "/" + name
- self.assertTrue(functest_utils.download_url(self.url,
- self.dest_path))
- m.assert_called_once_with(dest, 'wb')
- self.assertTrue(mock_sh.called)
-
- def test_get_git_branch(self):
- with mock.patch('functest.utils.functest_utils.Repo') as mock_repo:
- mock_obj2 = mock.Mock()
- attrs = {'name': 'test_branch'}
- mock_obj2.configure_mock(**attrs)
-
- mock_obj = mock.Mock()
- attrs = {'active_branch': mock_obj2}
- mock_obj.configure_mock(**attrs)
-
- mock_repo.return_value = mock_obj
- self.assertEqual(functest_utils.get_git_branch(self.repo_path),
- 'test_branch')
-
- @mock.patch('functest.utils.functest_utils.Repo',
- side_effect=NoSuchPathError)
- def test_get_git_branch_failed(self, mock_repo):
- self.assertRaises(NoSuchPathError,
- lambda: functest_utils.get_git_branch(self.repo_path
- ))
-
- @mock.patch('functest.utils.functest_utils.logger.error')
- def test_get_installer_type_failed(self, mock_logger_error):
- with mock.patch.dict(os.environ,
- {},
- clear=True):
- self.assertEqual(functest_utils.get_installer_type(),
- "Unknown_installer")
- mock_logger_error.assert_called_once_with("Impossible to retrieve"
- " the installer type")
-
- def test_get_installer_type_default(self):
- with mock.patch.dict(os.environ,
- {'INSTALLER_TYPE': 'test_installer'},
- clear=True):
- self.assertEqual(functest_utils.get_installer_type(),
- self.installer)
-
- @mock.patch('functest.utils.functest_utils.logger.info')
- def test_get_scenario_failed(self, mock_logger_info):
- with mock.patch.dict(os.environ,
- {},
- clear=True):
- self.assertEqual(functest_utils.get_scenario(),
- "os-nosdn-nofeature-noha")
- mock_logger_info.assert_called_once_with("Impossible to retrieve "
- "the scenario.Use "
- "default "
- "os-nosdn-nofeature-noha")
-
- def test_get_scenario_default(self):
- with mock.patch.dict(os.environ,
- {'DEPLOY_SCENARIO': 'test_scenario'},
- clear=True):
- self.assertEqual(functest_utils.get_scenario(),
- self.scenario)
-
- @mock.patch('functest.utils.functest_utils.get_build_tag')
- def test_get_version_daily_job(self, mock_get_build_tag):
- mock_get_build_tag.return_value = self.build_tag
- self.assertEqual(functest_utils.get_version(), self.version)
-
- @mock.patch('functest.utils.functest_utils.get_build_tag')
- def test_get_version_weekly_job(self, mock_get_build_tag):
- mock_get_build_tag.return_value = self.build_tag_week
- self.assertEqual(functest_utils.get_version(), self.version)
-
- @mock.patch('functest.utils.functest_utils.get_build_tag')
- def test_get_version_with_dummy_build_tag(self, mock_get_build_tag):
- mock_get_build_tag.return_value = 'whatever'
- self.assertEqual(functest_utils.get_version(), 'unknown')
-
- @mock.patch('functest.utils.functest_utils.get_build_tag')
- def test_get_version_unknown(self, mock_get_build_tag):
- mock_get_build_tag.return_value = "unknown_build_tag"
- self.assertEqual(functest_utils.get_version(), "unknown")
-
- @mock.patch('functest.utils.functest_utils.logger.info')
- def test_get_pod_name_failed(self, mock_logger_info):
- with mock.patch.dict(os.environ,
- {},
- clear=True):
- self.assertEqual(functest_utils.get_pod_name(),
- "unknown-pod")
- mock_logger_info.assert_called_once_with("Unable to retrieve "
- "the POD name from "
- "environment. Using "
- "pod name 'unknown-pod'")
-
- def test_get_pod_name_default(self):
- with mock.patch.dict(os.environ,
- {'NODE_NAME': 'test_node_name'},
- clear=True):
- self.assertEqual(functest_utils.get_pod_name(),
- self.node_name)
-
- @mock.patch('functest.utils.functest_utils.logger.info')
- def test_get_build_tag_failed(self, mock_logger_info):
- with mock.patch.dict(os.environ,
- {},
- clear=True):
- self.assertEqual(functest_utils.get_build_tag(),
- "none")
- mock_logger_info.assert_called_once_with("Impossible to retrieve"
- " the build tag")
-
- def test_get_build_tag_default(self):
- with mock.patch.dict(os.environ,
- {'BUILD_TAG': self.build_tag},
- clear=True):
- self.assertEqual(functest_utils.get_build_tag(),
- self.build_tag)
-
- def test_get_db_url_env_var(self):
- with mock.patch.dict(os.environ,
- {'TEST_DB_URL': self.db_url_env,
- 'CONFIG_FUNCTEST_YAML':
- "./functest/ci/config_functest.yaml"},
- clear=True):
- self.assertEqual(functest_utils.get_db_url(),
- self.db_url_env)
-
- @mock.patch('functest.utils.functest_utils.get_functest_config')
- def test_get_db_url_default(self, mock_get_functest_config):
- mock_get_functest_config.return_value = self.db_url
- self.assertEqual(functest_utils.get_db_url(), self.db_url)
- mock_get_functest_config.assert_called_once_with('results.test_db_url')
-
- @mock.patch('functest.utils.functest_utils.logger.info')
- def test_logger_test_results(self, mock_logger_info):
- with mock.patch('functest.utils.functest_utils.get_pod_name',
- return_value=self.node_name), \
- mock.patch('functest.utils.functest_utils.get_scenario',
- return_value=self.scenario), \
- mock.patch('functest.utils.functest_utils.get_version',
- return_value=self.version), \
- mock.patch('functest.utils.functest_utils.get_build_tag',
- return_value=self.build_tag), \
- mock.patch('functest.utils.functest_utils.get_db_url',
- return_value=self.db_url):
- functest_utils.logger_test_results(self.project, self.case_name,
- self.status, self.details)
- mock_logger_info.assert_called_once_with(
- "\n"
- "****************************************\n"
- "\t %(p)s/%(n)s results \n\n"
- "****************************************\n"
- "DB:\t%(db)s\n"
- "pod:\t%(pod)s\n"
- "version:\t%(v)s\n"
- "scenario:\t%(s)s\n"
- "status:\t%(c)s\n"
- "build tag:\t%(b)s\n"
- "details:\t%(d)s\n"
- % {'p': self.project,
- 'n': self.case_name,
- 'db': self.db_url,
- 'pod': self.node_name,
- 'v': self.version,
- 's': self.scenario,
- 'c': self.status,
- 'b': self.build_tag,
- 'd': self.details})
-