From d3023f350dfd7cac952f039def2722ff253ace5f Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Wed, 6 Jul 2022 14:56:02 -0700 Subject: [PATCH] Adds tests to site admin view --- bookwyrm/tests/views/admin/test_site.py | 80 +++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 bookwyrm/tests/views/admin/test_site.py diff --git a/bookwyrm/tests/views/admin/test_site.py b/bookwyrm/tests/views/admin/test_site.py new file mode 100644 index 000000000..6b228cf86 --- /dev/null +++ b/bookwyrm/tests/views/admin/test_site.py @@ -0,0 +1,80 @@ +""" test for app action functionality """ +from unittest.mock import patch +from django.template.response import TemplateResponse +from django.test import TestCase +from django.test.client import RequestFactory + +from bookwyrm import forms, models, views +from bookwyrm.tests.validate_html import validate_html + + +class SiteSettingsViews(TestCase): + """Edit site settings""" + + def setUp(self): + """we need basic test data and mocks""" + self.factory = RequestFactory() + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( + "bookwyrm.activitystreams.populate_stream_task.delay" + ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + self.local_user = models.User.objects.create_user( + "mouse@local.com", + "mouse@mouse.mouse", + "password", + local=True, + localname="mouse", + ) + + self.site = models.SiteSettings.objects.create() + + def test_site_get(self): + """there are so many views, this just makes sure it LOADS""" + view = views.Site.as_view() + request = self.factory.get("") + 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) + + def test_site_post(self): + """there are so many views, this just makes sure it LOADS""" + view = views.Site.as_view() + form = forms.SiteForm() + form.data["name"] = "Name!" + form.data["instance_tagline"] = "hi" + form.data["instance_description"] = "blah" + form.data["registration_closed_text"] = "blah" + form.data["invite_request_text"] = "blah" + form.data["code_of_conduct"] = "blah" + form.data["privacy_policy"] = "blah" + 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) + + site = models.SiteSettings.objects.get() + self.assertEqual(site.name, "Name!") + + def test_site_post_invalid(self): + """there are so many views, this just makes sure it LOADS""" + view = views.Site.as_view() + form = forms.SiteForm() + 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) + + self.site.refresh_from_db() + self.assertEqual(self.site.name, "BookWyrm")