-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
16 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,42 @@ | ||
import json | ||
from urllib.parse import quote | ||
|
||
import pytest | ||
from freezegun import freeze_time | ||
|
||
from slack_annotations.core import notify | ||
|
||
|
||
@pytest.fixture | ||
def slack_annotations(): | ||
with open("tests/data/slack_annotations.json") as f: | ||
with open("tests/data/slack_annotations.json", encoding="utf-8") as f: | ||
return json.load(f) | ||
|
||
|
||
@pytest.fixture | ||
def search_annotations(): | ||
with open("tests/data/search_annotations.json") as f: | ||
with open("tests/data/search_annotations.json", encoding="utf-8") as f: | ||
return json.load(f) | ||
|
||
|
||
@freeze_time("2024-12-01T01:00:00+00:00") | ||
def test_notify_search_after(httpx_mock, search_annotations, slack_annotations): | ||
url = "https://hypothes.is/api/search?search_after=1733007600000.0&sort=created&order=asc" | ||
search_after = quote("2024-12-01T00:00:00+00:00") | ||
url = f"https://hypothes.is/api/search?sort=created&order=asc&search_after={search_after}" | ||
httpx_mock.add_response(url=url, content=json.dumps(search_annotations)) | ||
|
||
search_params = {"search_after": "1733007600000.0"} | ||
assert notify(search_params=search_params) == json.dumps(slack_annotations) | ||
assert notify() == json.dumps(slack_annotations) | ||
|
||
|
||
@freeze_time("2024-11-01T01:00:00+00:00") | ||
def test_notify_cache_file(httpx_mock, tmp_path, search_annotations, slack_annotations): | ||
url = "https://hypothes.is/api/search?search_after=1733007600000.0&sort=created&order=asc" | ||
search_after = quote("2024-12-01T00:00:00+00:00") | ||
url = f"https://hypothes.is/api/search?sort=created&order=asc&search_after={search_after}" | ||
httpx_mock.add_response(url=url, content=json.dumps(search_annotations)) | ||
|
||
search_params = {"search_after": "1733007600000.0"} | ||
cache_path = tmp_path / "cache.json" | ||
assert notify(search_params=search_params, cache_path=cache_path) == json.dumps( | ||
slack_annotations | ||
) | ||
cache_path.write_text(json.dumps({"search_after": "2024-12-01T00:00:00+00:00"})) | ||
assert notify(cache_path=cache_path) == json.dumps(slack_annotations) | ||
assert json.loads(cache_path.read_text()) == { | ||
"search_after": "2024-11-22T17:03:54.248643+00:00" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters