forked from bookwyrm-social/bookwyrm
-
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.
celery inmem test suite: tests/views/*.py
- Loading branch information
Showing
7 changed files
with
206 additions
and
298 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
"""testing the annual summary page""" | ||
import datetime | ||
from unittest.mock import patch | ||
|
||
from django.contrib.auth.models import AnonymousUser | ||
from django.http import Http404 | ||
|
@@ -23,20 +22,15 @@ class AnnualSummary(TestCase): | |
@classmethod | ||
def setUpTestData(cls): | ||
"""we need basic test data and mocks""" | ||
with ( | ||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), | ||
patch("bookwyrm.activitystreams.populate_stream_task.delay"), | ||
patch("bookwyrm.lists_stream.populate_lists_task.delay"), | ||
): | ||
cls.local_user = models.User.objects.create_user( | ||
"[email protected]", | ||
"[email protected]", | ||
"mouseword", | ||
local=True, | ||
localname="mouse", | ||
remote_id="https://example.com/users/mouse", | ||
summary_keys={"2020": "0123456789"}, | ||
) | ||
cls.local_user = models.User.objects.create_user( | ||
"[email protected]", | ||
"[email protected]", | ||
"mouseword", | ||
local=True, | ||
localname="mouse", | ||
remote_id="https://example.com/users/mouse", | ||
summary_keys={"2020": "0123456789"}, | ||
) | ||
cls.work = models.Work.objects.create(title="Test Work") | ||
cls.book = models.Edition.objects.create( | ||
title="Example Edition", | ||
|
@@ -53,7 +47,7 @@ def setUp(self): | |
self.anonymous_user = AnonymousUser | ||
self.anonymous_user.is_authenticated = False | ||
|
||
def test_annual_summary_not_authenticated(self, *_): | ||
def test_annual_summary_not_authenticated(self): | ||
"""there are so many views, this just makes sure it DOESN’T LOAD""" | ||
view = views.AnnualSummary.as_view() | ||
request = self.factory.get("") | ||
|
@@ -62,7 +56,7 @@ def test_annual_summary_not_authenticated(self, *_): | |
with self.assertRaises(Http404): | ||
view(request, self.local_user.localname, self.year) | ||
|
||
def test_annual_summary_not_authenticated_with_key(self, *_): | ||
def test_annual_summary_not_authenticated_with_key(self): | ||
"""there are so many views, this just makes sure it DOES LOAD""" | ||
key = self.local_user.summary_keys[self.year] | ||
view = views.AnnualSummary.as_view() | ||
|
@@ -78,7 +72,7 @@ def test_annual_summary_not_authenticated_with_key(self, *_): | |
validate_html(result.render()) | ||
self.assertEqual(result.status_code, 200) | ||
|
||
def test_annual_summary_wrong_year(self, *_): | ||
def test_annual_summary_wrong_year(self): | ||
"""there are so many views, this just makes sure it DOESN’T LOAD""" | ||
view = views.AnnualSummary.as_view() | ||
request = self.factory.get("") | ||
|
@@ -87,7 +81,7 @@ def test_annual_summary_wrong_year(self, *_): | |
with self.assertRaises(Http404): | ||
view(request, self.local_user.localname, self.year) | ||
|
||
def test_annual_summary_empty_page(self, *_): | ||
def test_annual_summary_empty_page(self): | ||
"""there are so many views, this just makes sure it LOADS""" | ||
view = views.AnnualSummary.as_view() | ||
request = self.factory.get("") | ||
|
@@ -99,9 +93,7 @@ def test_annual_summary_empty_page(self, *_): | |
validate_html(result.render()) | ||
self.assertEqual(result.status_code, 200) | ||
|
||
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async") | ||
@patch("bookwyrm.activitystreams.add_book_statuses_task.delay") | ||
def test_annual_summary_page(self, *_): | ||
def test_annual_summary_page(self): | ||
"""there are so many views, this just makes sure it LOADS""" | ||
models.ReadThrough.objects.create( | ||
user=self.local_user, book=self.book, finish_date=make_date(2020, 1, 1) | ||
|
@@ -117,9 +109,7 @@ def test_annual_summary_page(self, *_): | |
validate_html(result.render()) | ||
self.assertEqual(result.status_code, 200) | ||
|
||
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async") | ||
@patch("bookwyrm.activitystreams.add_book_statuses_task.delay") | ||
def test_annual_summary_page_with_review(self, *_): | ||
def test_annual_summary_page_with_review(self): | ||
"""there are so many views, this just makes sure it LOADS""" | ||
|
||
models.Review.objects.create( | ||
|
@@ -144,7 +134,7 @@ def test_annual_summary_page_with_review(self, *_): | |
validate_html(result.render()) | ||
self.assertEqual(result.status_code, 200) | ||
|
||
def test_personal_annual_summary(self, *_): | ||
def test_personal_annual_summary(self): | ||
"""redirect to unique user url""" | ||
view = views.personal_annual_summary | ||
request = self.factory.get("") | ||
|
@@ -155,7 +145,7 @@ def test_personal_annual_summary(self, *_): | |
self.assertEqual(result.status_code, 302) | ||
self.assertEqual(result.url, "/user/mouse/2020-in-the-books") | ||
|
||
def test_summary_add_key(self, *_): | ||
def test_summary_add_key(self): | ||
"""add shareable key""" | ||
self.assertFalse("2022" in self.local_user.summary_keys.keys()) | ||
|
||
|
@@ -167,7 +157,7 @@ def test_summary_add_key(self, *_): | |
self.assertEqual(result.status_code, 302) | ||
self.assertIsNotNone(self.local_user.summary_keys["2022"]) | ||
|
||
def test_summary_revoke_key(self, *_): | ||
def test_summary_revoke_key(self): | ||
"""add shareable key""" | ||
self.assertTrue("2020" in self.local_user.summary_keys.keys()) | ||
|
||
|
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 |
---|---|---|
|
@@ -19,19 +19,14 @@ class AuthorViews(TestCase): | |
@classmethod | ||
def setUpTestData(cls): | ||
"""we need basic test data and mocks""" | ||
with ( | ||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), | ||
patch("bookwyrm.activitystreams.populate_stream_task.delay"), | ||
patch("bookwyrm.lists_stream.populate_lists_task.delay"), | ||
): | ||
cls.local_user = models.User.objects.create_user( | ||
"[email protected]", | ||
"[email protected]", | ||
"mouseword", | ||
local=True, | ||
localname="mouse", | ||
remote_id="https://example.com/users/mouse", | ||
) | ||
cls.local_user = models.User.objects.create_user( | ||
"[email protected]", | ||
"[email protected]", | ||
"mouseword", | ||
local=True, | ||
localname="mouse", | ||
remote_id="https://example.com/users/mouse", | ||
) | ||
cls.group = Group.objects.create(name="editor") | ||
cls.group.permissions.add( | ||
Permission.objects.create( | ||
|
@@ -153,8 +148,7 @@ def test_edit_author(self): | |
request = self.factory.post("", form.data) | ||
request.user = self.local_user | ||
|
||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"): | ||
view(request, author.id) | ||
view(request, author.id) | ||
author.refresh_from_db() | ||
self.assertEqual(author.name, "New Name") | ||
self.assertEqual(author.last_edited_by, self.local_user) | ||
|
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,5 +1,4 @@ | ||
""" test for app action functionality """ | ||
from unittest.mock import patch | ||
|
||
from django.contrib.auth.models import AnonymousUser | ||
from django.template.response import TemplateResponse | ||
|
@@ -16,19 +15,14 @@ class DirectoryViews(TestCase): | |
@classmethod | ||
def setUpTestData(cls): | ||
"""we need basic test data and mocks""" | ||
with ( | ||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), | ||
patch("bookwyrm.activitystreams.populate_stream_task.delay"), | ||
patch("bookwyrm.lists_stream.populate_lists_task.delay"), | ||
): | ||
cls.local_user = models.User.objects.create_user( | ||
"[email protected]", | ||
"[email protected]", | ||
"mouseword", | ||
local=True, | ||
localname="mouse", | ||
remote_id="https://example.com/users/mouse", | ||
) | ||
cls.local_user = models.User.objects.create_user( | ||
"[email protected]", | ||
"[email protected]", | ||
"mouseword", | ||
local=True, | ||
localname="mouse", | ||
remote_id="https://example.com/users/mouse", | ||
) | ||
models.SiteSettings.objects.create() | ||
|
||
def setUp(self): | ||
|
@@ -37,11 +31,7 @@ def setUp(self): | |
self.anonymous_user = AnonymousUser | ||
self.anonymous_user.is_authenticated = False | ||
|
||
@patch("bookwyrm.suggested_users.rerank_suggestions_task.delay") | ||
@patch("bookwyrm.activitystreams.populate_stream_task.delay") | ||
@patch("bookwyrm.lists_stream.populate_lists_task.delay") | ||
@patch("bookwyrm.suggested_users.rerank_user_task.delay") | ||
def test_directory_page(self, *_): | ||
def test_directory_page(self): | ||
"""there are so many views, this just makes sure it LOADS""" | ||
models.User.objects.create_user( | ||
"[email protected]", | ||
|
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 |
---|---|---|
|
@@ -14,18 +14,13 @@ class DiscoverViews(TestCase): | |
@classmethod | ||
def setUpTestData(cls): | ||
"""we need basic test data and mocks""" | ||
with ( | ||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), | ||
patch("bookwyrm.activitystreams.populate_stream_task.delay"), | ||
patch("bookwyrm.lists_stream.populate_lists_task.delay"), | ||
): | ||
cls.local_user = models.User.objects.create_user( | ||
"[email protected]", | ||
"[email protected]", | ||
"password", | ||
local=True, | ||
localname="mouse", | ||
) | ||
cls.local_user = models.User.objects.create_user( | ||
"[email protected]", | ||
"[email protected]", | ||
"password", | ||
local=True, | ||
localname="mouse", | ||
) | ||
models.SiteSettings.objects.create() | ||
|
||
def setUp(self): | ||
|
@@ -47,9 +42,7 @@ def test_discover_page_empty(self): | |
self.assertEqual(result.status_code, 200) | ||
validate_html(result.render()) | ||
|
||
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async") | ||
@patch("bookwyrm.activitystreams.add_status_task.delay") | ||
def test_discover_page_with_posts(self, *_): | ||
def test_discover_page_with_posts(self): | ||
"""there are so many views, this just makes sure it LOADS""" | ||
view = views.Discover.as_view() | ||
request = self.factory.get("") | ||
|
Oops, something went wrong.