diff --git a/bookwyrm/templates/report.html b/bookwyrm/templates/report.html index 686401ebe..be7ed68f7 100644 --- a/bookwyrm/templates/report.html +++ b/bookwyrm/templates/report.html @@ -6,5 +6,5 @@ {% endblock %} {% block content %} -{% include "snippets/report_modal.html" with user=user active=True static=True %} +{% include "snippets/report_modal.html" with user=user active=True static=True id="report-modal" %} {% endblock %} diff --git a/bookwyrm/tests/views/admin/test_ip_blocklist.py b/bookwyrm/tests/views/admin/test_ip_blocklist.py index e23abd8b1..af63ffaf3 100644 --- a/bookwyrm/tests/views/admin/test_ip_blocklist.py +++ b/bookwyrm/tests/views/admin/test_ip_blocklist.py @@ -4,7 +4,7 @@ from django.template.response import TemplateResponse from django.test import TestCase from django.test.client import RequestFactory -from bookwyrm import models, views +from bookwyrm import forms, models, views from bookwyrm.tests.validate_html import validate_html @@ -39,3 +39,35 @@ class IPBlocklistViews(TestCase): self.assertIsInstance(result, TemplateResponse) validate_html(result.render()) self.assertEqual(result.status_code, 200) + + def test_blocklist_page_post(self): + """there are so many views, this just makes sure it LOADS""" + view = views.IPBlocklist.as_view() + form = forms.IPBlocklistForm() + form.data["address"] = "0.0.0.0" + + request = self.factory.post("", form.data) + request.user = self.local_user + request.user.is_superuser = True + + result = view(request) + + self.assertIsInstance(result, TemplateResponse) + validate_html(result.render()) + self.assertEqual(result.status_code, 200) + + block = models.IPBlocklist.objects.get() + self.assertEqual(block.address, "0.0.0.0") + self.assertTrue(block.is_active) + + def test_blocklist_page_delete(self): + """there are so many views, this just makes sure it LOADS""" + block = models.IPBlocklist.objects.create(address="0.0.0.0") + view = views.IPBlocklist.as_view() + + request = self.factory.post("") + request.user = self.local_user + request.user.is_superuser = True + + view(request, block.id) + self.assertFalse(models.IPBlocklist.objects.exists()) diff --git a/bookwyrm/tests/views/admin/test_reports.py b/bookwyrm/tests/views/admin/test_reports.py index d0f2e9d91..d0875f2c2 100644 --- a/bookwyrm/tests/views/admin/test_reports.py +++ b/bookwyrm/tests/views/admin/test_reports.py @@ -89,6 +89,14 @@ class ReportViews(TestCase): self.assertEqual(comment.note, "hi") self.assertEqual(comment.report, report) + def test_report_modal_view(self): + """a user reports another user""" + request = self.factory.get("") + request.user = self.local_user + result = views.Report.as_view()(request, self.local_user.id) + + validate_html(result.render()) + def test_make_report(self): """a user reports another user""" form = forms.ReportForm() @@ -103,6 +111,30 @@ class ReportViews(TestCase): self.assertEqual(report.reporter, self.local_user) self.assertEqual(report.user, self.rat) + def test_report_link(self): + """a user reports a link as spam""" + book = models.Edition.objects.create(title="hi") + link = models.FileLink.objects.create( + book=book, added_by=self.local_user, url="https://skdjfs.sdf" + ) + domain = link.domain + domain.status = "approved" + domain.save() + + form = forms.ReportForm() + form.data["reporter"] = self.local_user.id + form.data["user"] = self.rat.id + form.data["links"] = link.id + request = self.factory.post("", form.data) + request.user = self.local_user + + views.Report.as_view()(request) + + report = models.Report.objects.get() + domain.refresh_from_db() + self.assertEqual(report.links.first().id, link.id) + self.assertEqual(domain.status, "pending") + def test_resolve_report(self): """toggle report resolution status""" report = models.Report.objects.create(reporter=self.local_user, user=self.rat) diff --git a/bookwyrm/tests/views/test_annual_summary.py b/bookwyrm/tests/views/test_annual_summary.py index 2d597be7f..aeb70794b 100644 --- a/bookwyrm/tests/views/test_annual_summary.py +++ b/bookwyrm/tests/views/test_annual_summary.py @@ -140,3 +140,14 @@ class AnnualSummary(TestCase): self.assertIsInstance(result, TemplateResponse) validate_html(result.render()) self.assertEqual(result.status_code, 200) + + def test_personal_annual_summary(self, *_): + """redirect to unique user url""" + view = views.personal_annual_summary + request = self.factory.get("") + request.user = self.local_user + + result = view(request, 2020) + + self.assertEqual(result.status_code, 302) + self.assertEqual(result.url, "/user/mouse/2020-in-the-books") diff --git a/bookwyrm/views/user.py b/bookwyrm/views/user.py index 9deea14b7..851cfdaae 100644 --- a/bookwyrm/views/user.py +++ b/bookwyrm/views/user.py @@ -30,17 +30,15 @@ class User(View): shelf_preview = [] - # only show other shelves that should be visible + # only show shelves that should be visible shelves = user.shelf_set is_self = request.user.id == user.id if not is_self: shelves = models.Shelf.privacy_filter( request.user, privacy_levels=["public", "followers"] - ).filter(user=user) + ).filter(user=user, books__isnull=False) - for user_shelf in shelves.all(): - if not user_shelf.books.count(): - continue + for user_shelf in shelves.all()[:3]: shelf_preview.append( { "name": user_shelf.name, @@ -49,8 +47,6 @@ class User(View): "size": user_shelf.books.count(), } ) - if len(shelf_preview) > 2: - break # user's posts activities = (