diff options
author | Andrew Godwin | 2022-11-21 20:10:01 -0700 |
---|---|---|
committer | Andrew Godwin | 2022-11-21 20:10:01 -0700 |
commit | 0d1e09fbcdb1a1db93d9561c9323c7ef105e71ca (patch) | |
tree | 3799cb9523757c98b62e6a552cdf13ca3d98bb1b /tests/activities | |
parent | e38e17678432613111ea220260c5d76677a84d3e (diff) | |
download | takahe-0d1e09fbcdb1a1db93d9561c9323c7ef105e71ca.tar.gz takahe-0d1e09fbcdb1a1db93d9561c9323c7ef105e71ca.tar.bz2 takahe-0d1e09fbcdb1a1db93d9561c9323c7ef105e71ca.zip |
Refactor almost all tests into /tests/
Diffstat (limited to 'tests/activities')
-rw-r--r-- | tests/activities/models/test_post.py | 31 | ||||
-rw-r--r-- | tests/activities/templatetags/test_activity_tags.py | 21 |
2 files changed, 52 insertions, 0 deletions
diff --git a/tests/activities/models/test_post.py b/tests/activities/models/test_post.py new file mode 100644 index 0000000..5c7fca2 --- /dev/null +++ b/tests/activities/models/test_post.py @@ -0,0 +1,31 @@ +import pytest +from pytest_httpx import HTTPXMock + +from activities.models import Post + + +@pytest.mark.django_db +def test_fetch_post(httpx_mock: HTTPXMock): + """ + Tests that a post we don't have locally can be fetched by by_object_uri + """ + httpx_mock.add_response( + url="https://example.com/test-post", + json={ + "@context": [ + "https://www.w3.org/ns/activitystreams", + ], + "id": "https://example.com/test-post", + "type": "Note", + "published": "2022-11-13T23:20:16Z", + "url": "https://example.com/test-post", + "attributedTo": "https://example.com/test-actor", + "content": "BEEEEEES", + }, + ) + # Fetch with a HTTP access + post = Post.by_object_uri("https://example.com/test-post", fetch=True) + assert post.content == "BEEEEEES" + assert post.author.actor_uri == "https://example.com/test-actor" + # Fetch again with a DB hit + assert Post.by_object_uri("https://example.com/test-post").id == post.id diff --git a/tests/activities/templatetags/test_activity_tags.py b/tests/activities/templatetags/test_activity_tags.py new file mode 100644 index 0000000..987c008 --- /dev/null +++ b/tests/activities/templatetags/test_activity_tags.py @@ -0,0 +1,21 @@ +from datetime import timedelta + +from django.utils import timezone + +from activities.templatetags.activity_tags import timedeltashort + + +def test_timedeltashort_regress(): + assert timedeltashort(None) == "" + assert timedeltashort("") == "" + + value = timezone.now() + + assert timedeltashort(value) == "0s" + assert timedeltashort(value - timedelta(seconds=2)) == "2s" + assert timedeltashort(value - timedelta(minutes=2)) == "2m" + assert timedeltashort(value - timedelta(hours=2)) == "2h" + assert timedeltashort(value - timedelta(days=2)) == "2d" + assert timedeltashort(value - timedelta(days=364)) == "364d" + assert timedeltashort(value - timedelta(days=365)) == "1y" + assert timedeltashort(value - timedelta(days=366)) == "1y" |