Skip to content

Commit

Permalink
chore(api/test): add tests for timeout and invalid json
Browse files Browse the repository at this point in the history
  • Loading branch information
c0rydoras committed Feb 19, 2024
1 parent 979c6be commit 3993f87
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions api/outdated/outdated/tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from typing import TYPE_CHECKING

import pytest
from requests import exceptions

from outdated.outdated.parser import LockfileParser
from outdated.outdated.tracking import Tracker
Expand Down Expand Up @@ -182,3 +183,28 @@ def test_fetch_end_of_life(
for dependency_name in dependency_names:
LockfileParser([])._get_version((dependency_name, "4.4.1"), provider="PIP") # noqa: SLF001
assert get_end_of_life_date_spy.call_count == call_count


@pytest.mark.django_db()
@pytest.mark.parametrize(
"exception", [exceptions.ConnectTimeout, exceptions.ReadTimeout]
)
def test_fetch_end_of_life_ignore_timeout(mocker, requests_mock, exception):
mocker.patch.object(
LockfileParser, "_get_release_date", return_value=date(2024, 1, 1)
)
requests_mock.get(compile("https://endoflife.date/api/[-a-z]+/4.4"), exc=exception)
LockfileParser([])._get_version(("django", "4.4.1"), provider="PIP") # noqa: SLF001


@pytest.mark.django_db()
def test_fetch_end_of_life_invalid_json(mocker, requests_mock):
mocker.patch.object(
LockfileParser, "_get_release_date", return_value=date(2024, 1, 1)
)
requests_mock.get(
compile("https://endoflife.date/api/[-a-z]+/4.4"),
text="503 Service Temporarily Unavailable",
status_code=503,
)
LockfileParser([])._get_version(("django", "4.4.1"), provider="PIP") # noqa: SLF001

0 comments on commit 3993f87

Please sign in to comment.