diff --git a/concordia/tests/test_admin_views.py b/concordia/tests/test_admin_views.py index 075fb8d20..d593b21d8 100644 --- a/concordia/tests/test_admin_views.py +++ b/concordia/tests/test_admin_views.py @@ -1,9 +1,26 @@ import json +from http import HTTPStatus from django.test import RequestFactory, TestCase +from django.urls import reverse from concordia.admin.views import SerializedObjectView -from concordia.tests.utils import create_card +from concordia.tests.utils import CreateTestUsers, create_card + + +class TestFunctionBasedViews(CreateTestUsers, TestCase): + def test_admin_bulk_import_review(self): + self.login_user(is_staff=True, is_superuser=True) + self.assertTrue(self.user.is_active) + self.assertTrue(self.user.is_staff) + self.assertTrue(self.user.is_superuser) + path = reverse("admin:bulk-review") + response = self.client.get(path) + self.assertEqual(response.status_code, 200) + + data = {} + response = self.client.post(path, data=data) + self.assertEqual(response.status_code, 200) class TestSerializedObjectView(TestCase): @@ -12,11 +29,20 @@ def setUp(self): # Every test needs access to the request factory. self.factory = RequestFactory() - def test_get(self): + def test_exists(self): request = self.factory.get( "/admin/card/", - {"model_name": "Card", "object_id": 1, "field_name": "title"}, + {"model_name": "Card", "object_id": self.card.id, "field_name": "title"}, ) response = SerializedObjectView.as_view()(request) self.assertEqual(response.status_code, 200) self.assertEqual(json.loads(response.content)["title"], self.card.title) + + def test_dne(self): + request = self.factory.get( + "/admin/card/", + {"model_name": "Card", "object_id": 2, "field_name": "title"}, + ) + response = SerializedObjectView.as_view()(request) + self.assertEqual(response.status_code, HTTPStatus.NOT_FOUND) + self.assertJSONEqual(response.content, {"status": "false"}) diff --git a/concordia/tests/utils.py b/concordia/tests/utils.py index d43be5842..ba53901c3 100644 --- a/concordia/tests/utils.py +++ b/concordia/tests/utils.py @@ -241,13 +241,13 @@ def assertValidJSON(self, response, expected_status=200): class CreateTestUsers(object): - def login_user(self, username="tester"): + def login_user(self, username="tester", **kwargs): """ Create a user and log the user in """ if not hasattr(self, "user"): - self.user = self.create_test_user(username) + self.user = self.create_test_user(username, **kwargs) self.client.login(username=self.user.username, password=self.user._password)