mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-25 19:11:09 +00:00
Adds a couple tests to annual review views
Also I tweaked the save functions so they don't broadcast
This commit is contained in:
parent
fdc477afdf
commit
3a73ced5fa
5 changed files with 32 additions and 4 deletions
|
@ -21,6 +21,7 @@ def make_date(*args):
|
|||
class AnnualSummary(TestCase):
|
||||
"""views"""
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
def setUp(self):
|
||||
"""we need basic test data and mocks"""
|
||||
self.factory = RequestFactory()
|
||||
|
@ -151,3 +152,27 @@ class AnnualSummary(TestCase):
|
|||
|
||||
self.assertEqual(result.status_code, 302)
|
||||
self.assertEqual(result.url, "/user/mouse/2020-in-the-books")
|
||||
|
||||
def test_summary_add_key(self, *_):
|
||||
"""add shareable key"""
|
||||
self.assertFalse("2022" in self.local_user.summary_keys.keys())
|
||||
|
||||
request = self.factory.post("", {"year": "2022"})
|
||||
request.user = self.local_user
|
||||
|
||||
result = views.summary_add_key(request)
|
||||
|
||||
self.assertEqual(result.status_code, 302)
|
||||
self.assertIsNotNone(self.local_user.summary_keys["2022"])
|
||||
|
||||
def test_summary_revoke_key(self, *_):
|
||||
"""add shareable key"""
|
||||
self.assertTrue("2020" in self.local_user.summary_keys.keys())
|
||||
|
||||
request = self.factory.post("", {"year": "2020"})
|
||||
request.user = self.local_user
|
||||
|
||||
result = views.summary_revoke_key(request)
|
||||
|
||||
self.assertEqual(result.status_code, 302)
|
||||
self.assertFalse("2020" in self.local_user.summary_keys.keys())
|
||||
|
|
|
@ -120,7 +120,7 @@ def personal_annual_summary(request, year):
|
|||
@login_required
|
||||
@require_POST
|
||||
def summary_add_key(request):
|
||||
"""add summary key"""
|
||||
"""Create a shareable token for this annual review year"""
|
||||
|
||||
year = request.POST["year"]
|
||||
user = request.user
|
||||
|
@ -134,7 +134,7 @@ def summary_add_key(request):
|
|||
else:
|
||||
user.summary_keys[year] = new_key
|
||||
|
||||
user.save()
|
||||
user.save(update_fields=["summary_keys"], broadcast=False)
|
||||
|
||||
response = redirect("annual-summary", user.localname, year)
|
||||
response["Location"] += f"?key={str(new_key)}"
|
||||
|
@ -144,7 +144,7 @@ def summary_add_key(request):
|
|||
@login_required
|
||||
@require_POST
|
||||
def summary_revoke_key(request):
|
||||
"""revoke summary key"""
|
||||
"""No longer sharing the annual review"""
|
||||
|
||||
year = request.POST["year"]
|
||||
user = request.user
|
||||
|
@ -152,7 +152,7 @@ def summary_revoke_key(request):
|
|||
if user.summary_keys and year in user.summary_keys:
|
||||
user.summary_keys.pop(year)
|
||||
|
||||
user.save()
|
||||
user.save(update_fields=["summary_keys"], broadcast=False)
|
||||
|
||||
return redirect("annual-summary", user.localname, year)
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ shell \
|
|||
dbshell \
|
||||
restart_celery \
|
||||
pytest \
|
||||
pytest_coverage_report \
|
||||
collectstatic \
|
||||
makemessages \
|
||||
compilemessages \
|
||||
|
|
|
@ -10,6 +10,7 @@ shell
|
|||
dbshell
|
||||
restart_celery
|
||||
pytest
|
||||
pytest_coverage_report
|
||||
collectstatic
|
||||
makemessages
|
||||
compilemessages
|
||||
|
|
|
@ -12,6 +12,7 @@ shell
|
|||
dbshell
|
||||
restart_celery
|
||||
pytest
|
||||
pytest_coverage_report
|
||||
collectstatic
|
||||
makemessages
|
||||
compilemessages
|
||||
|
|
Loading…
Reference in a new issue