diff --git a/probe_scraper/probe_expiry_alert.py b/probe_scraper/probe_expiry_alert.py index 98dffb37..4459ea9a 100644 --- a/probe_scraper/probe_expiry_alert.py +++ b/probe_scraper/probe_expiry_alert.py @@ -287,8 +287,9 @@ def check_bugzilla_user_exists(email: str, api_key: str): try: user_response.raise_for_status() except requests.exceptions.HTTPError as e: - # 400 is raised if user does not exist - if e.response.status_code == 400 and e.response.json()["code"] == 51: + # Error code 51 means the user does not exist. Bugzilla used to return + # it with HTTP 400 and now returns it with HTTP 404. + if e.response.status_code in (400, 404) and e.response.json()["code"] == 51: return False raise # As of Sept 2020, api seems to be returning 200 response with an unknown diff --git a/tests/test_probe_expiry_alert.py b/tests/test_probe_expiry_alert.py index b47b346f..7ec4bcf6 100644 --- a/tests/test_probe_expiry_alert.py +++ b/tests/test_probe_expiry_alert.py @@ -3,6 +3,7 @@ from dataclasses import dataclass from unittest import mock +import pytest from requests.exceptions import HTTPError from probe_scraper import probe_expiry_alert @@ -493,10 +494,11 @@ def test_get_longest_prefix(): assert probe_expiry_alert.get_longest_prefix(["abc"]) == "abc" +@pytest.mark.parametrize("status_code", [400, 404]) @mock.patch("requests.get") -def test_check_bugzilla_user_account_not_found(mock_get): +def test_check_bugzilla_user_account_not_found(mock_get, status_code): mock_response = mock.MagicMock() - mock_response.status_code = 400 + mock_response.status_code = status_code mock_response.json = mock.MagicMock(return_value={"code": 51}) def user_not_found():