diff --git a/mlx/coverity_services.py b/mlx/coverity_services.py index 8128969f..aa1f5014 100644 --- a/mlx/coverity_services.py +++ b/mlx/coverity_services.py @@ -224,7 +224,7 @@ def get_snapshot_id(snapshots, idx=1): if abs(required) > 0 and abs(required) <= num_snapshots: # base zero - return snapshots[required-1].id + return snapshots[required - 1].id return 0 def get_snapshot_detail(self, snapshot_id): @@ -396,7 +396,7 @@ def get_defects(self, project, stream, checker=None, impact=None, kind=None, cla name_value_pair = name_value_pair.strip() valid, name, values = parse_two_part_term(name_value_pair, ':') if valid: - logging.info("attr (%d) [%s] = any of ...", i+1, name) + logging.info("attr (%d) [%s] = any of ...", i + 1, name) attribute_definition_id = self.client.factory.create('attributeDefinitionIdDataObj') attribute_definition_id.name = name diff --git a/tests/test_coverity.py b/tests/test_coverity.py index f70ce11b..11318b48 100644 --- a/tests/test_coverity.py +++ b/tests/test_coverity.py @@ -2,7 +2,7 @@ try: from unittest.mock import MagicMock, patch # from unittest.mock import call -except ImportError as err: +except ImportError: from mock import MagicMock, patch # from mock import call import mlx.coverity as cov @@ -95,3 +95,23 @@ def test_defect_service_defects(self, suds_client_mock, suds_security_mock, suds suds_username_mock.assert_called_once_with('user', 'password') coverity_service.get_defects('projectname', 'somestream') + + @patch('mlx.coverity_services.UsernameToken') + @patch('mlx.coverity_services.Security') + @patch('mlx.coverity_services.Client') + def test_configuration_service_login_no_username_error(self, suds_client_mock, suds_security_mock, + suds_username_mock): + ''' Test login function of CoverityConfigurationService when error occurs''' + suds_client_mock.return_value = MagicMock(spec=Client) + suds_client_mock.return_value.service = MagicMock(spec=covservices.Service) + suds_client_mock.return_value.service.getVersion = MagicMock() + suds_security_mock.return_value = MagicMock(spec=Security) + suds_security_mock.return_value.tokens = [] + + # Login to Coverity and obtain stream information + coverity_conf_service = cov.CoverityConfigurationService('http', 'scan.coverity.com', '8080') + suds_client_mock.assert_called_once_with('http://scan.coverity.com:8080/ws/v9/configurationservice?wsdl') + + suds_client_mock.side_effect = Exception((401, 'Unauthorized')) + coverity_conf_service.login('', '') + diff --git a/tox.ini b/tox.ini index da1298e8..1a6f3617 100644 --- a/tox.ini +++ b/tox.ini @@ -56,7 +56,7 @@ skip_install = true commands = python setup.py check --strict --metadata --restructuredtext check-manifest {toxinidir} -u - flake8 mlx tests setup.py + flake8 --ignore=W605,W391 mlx tests setup.py [testenv:py36-check] deps = @@ -69,7 +69,7 @@ skip_install = true commands = python setup.py check --strict --metadata --restructuredtext check-manifest {toxinidir} -u - flake8 mlx tests setup.py + flake8 --ignore=W605,W391 mlx tests setup.py [testenv:py36-coveralls]