Skip to content

Commit

Permalink
Test failed login
Browse files Browse the repository at this point in the history
  • Loading branch information
JokeWaumans committed Aug 2, 2024
1 parent 601fb3b commit bb0cd2d
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions tests/test_coverity.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,18 @@ def test_get_defects(self):
assert mocker.last_request.verify
assert mocker.last_request.headers["Authorization"] == requests.auth._basic_auth_str("user", "password")

def test_failed_login(self):
fake_stream = "test_stream"

coverity_conf_service = mlx.coverity.CoverityDefectService("scan.coverity.com/")
stream_url = f"{coverity_conf_service.base_url.rstrip('/')}/streams/{fake_stream}"

with requests_mock.mock() as mocker:
mocker.get(stream_url, headers={"Authorization": "Basic fail"}, status_code = 401)
# Login to Coverity
coverity_conf_service.login("user", "password")
# Validate stream name
with self.assertRaises(requests.HTTPError) as err:
coverity_conf_service.validate_stream(fake_stream)
self.assertEqual(err.exception.response.status_code,401)

0 comments on commit bb0cd2d

Please sign in to comment.