Skip to content

Commit

Permalink
updated unit test and added comment
Browse files Browse the repository at this point in the history
  • Loading branch information
umar8hassan committed Jul 22, 2024
1 parent eda040e commit 3f7dbc8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions external_resources/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def check_external_resources(resources: list[int]):
log.debug(ex)
state.status = ExternalResourceState.Status.CHECK_FAILED
else:
# Status and flag should be updated if codes are not in ignored cases
if (
url_status not in RESOURCE_UNCHECKED_STATUSES
or backup_url_status not in RESOURCE_UNCHECKED_STATUSES
Expand Down
14 changes: 10 additions & 4 deletions external_resources/tasks_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
HTTP_401_UNAUTHORIZED,
)

from external_resources.constants import RESOURCE_UNCHECKED_STATUSES
from external_resources.exceptions import CheckFailedError
from external_resources.factories import ExternalResourceStateFactory
from external_resources.models import ExternalResourceState
Expand Down Expand Up @@ -148,7 +149,6 @@ def test_check_external_resources( # noqa: PLR0913

updated_state = ExternalResourceState.objects.get(id=external_resource_state.id)

assert updated_state.status == resource_status
assert updated_state.last_checked is not None

assert updated_state.is_external_url_broken is url_status
Expand All @@ -157,9 +157,15 @@ def test_check_external_resources( # noqa: PLR0913
assert updated_state.external_url_response_code == url_status_code
assert updated_state.backup_url_response_code == backup_url_status_code

assert updated_state.content.metadata.get("is_broken", False) == (
url_status and (backup_url_status_code is None or backup_url_status)
)
# Status and flag are updated if codes are not in ignored cases
if (
url_status_code not in RESOURCE_UNCHECKED_STATUSES
or backup_url_status_code not in RESOURCE_UNCHECKED_STATUSES
):
assert updated_state.status == resource_status
assert updated_state.content.metadata.get("is_broken", False) == (
url_status and (backup_url_status_code is None or backup_url_status)
)


@pytest.mark.django_db()
Expand Down

0 comments on commit 3f7dbc8

Please sign in to comment.