Skip to content

Commit

Permalink
unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
kena-SL committed Oct 31, 2023
1 parent ac51e9c commit 28bf869
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tests/unit/test_collect.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import pytest
import responses
import requests

from digital_land.collect import Collector, FetchStatus

Expand All @@ -23,6 +24,15 @@ def prepared_response():
responses.add(responses.GET, "http://some.url", body="some data")


@pytest.fixture
def prepared_exception():
responses.add(
responses.GET,
"http://mock.url",
body=requests.ConnectionError("Mocked Connection Error"),
)


def sha_digest(string):
return hashlib.sha256(string.encode("utf-8")).hexdigest()

Expand Down Expand Up @@ -78,3 +88,13 @@ def read_log(collector, url):

def log_file(url):
return f"{datetime.now().strftime('%Y-%m-%d')}/{sha_digest(url)}.json"


@responses.activate
def test_get(collector, prepared_exception):
url = "http://mock.url"
log, content = collector.get(url)

assert "status" not in log
assert log.get("exception") == "ConnectionError"
assert content is None

0 comments on commit 28bf869

Please sign in to comment.