From b42b297b8eea9c4b6b06a997c5d50d3a7c14ac41 Mon Sep 17 00:00:00 2001 From: Jacob Walls Date: Thu, 27 Jun 2024 16:57:52 -0400 Subject: [PATCH] Refactor to reduce login boilerplate --- arches_for_science/tests.py | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/arches_for_science/tests.py b/arches_for_science/tests.py index 5d0e97e21..0c10fef7a 100644 --- a/arches_for_science/tests.py +++ b/arches_for_science/tests.py @@ -1,8 +1,6 @@ from django.core.management import call_command - from django.contrib.auth.models import User from django.test import TestCase -from django.test.client import Client from django.urls import reverse from django.utils.translation import get_language @@ -26,11 +24,6 @@ def setUpModule(): class AnalysisAreaAndSampleTakingTests(TestCase): - def login(self, username="dev", password="dev"): - client = Client() - client.login(username=username, password=password) - return client - def get_resource_instance(self, graph_id): r = ResourceInstance(graph_id=graph_id) r.save() # not part of the transaction, part of the setup @@ -51,7 +44,7 @@ def make_tile(self, parent_phys_thing, data, transaction_id): def test_create_delete_analysis_area(self): # TODO: fails with dev/dev? 🤔 - client = self.login(username="ben", password="Test12345!") + self.client.login(username="ben", password="Test12345!") transaction_id = "10000000-1000-1000-1000-100000000000" parent_phys_thing = self.get_resource_instance(PHYSICAL_THING_GRAPH_ID) @@ -68,7 +61,7 @@ def test_create_delete_analysis_area(self): }), "analysisAreaName": "Test Analysis Area", } - response = client.post(reverse("saveanalysisarea"), create_data) + response = self.client.post(reverse("saveanalysisarea"), create_data) self.assertEqual(response.status_code, 200) new_resource = ResourceInstance.objects.get( @@ -92,12 +85,12 @@ def test_create_delete_analysis_area(self): } delete_data = JSONSerializer().serialize(delete_data) content_type = "application/json" - response = client.post(reverse("deleteanalysisarea"), delete_data, content_type=content_type) + response = self.client.post(reverse("deleteanalysisarea"), delete_data, content_type=content_type) self.assertEqual(response.status_code, 200) def test_create_delete_sample(self): - client = self.login() + self.client.login(username="dev", password="dev") transaction_id = "10000000-1000-1000-1000-100000000001" parent_phys_thing = self.get_resource_instance(PHYSICAL_THING_GRAPH_ID) @@ -125,7 +118,7 @@ def test_create_delete_sample(self): "sampleDescription": "Test Description", "samplingActivityResourceId": str(sampling_activity.pk), } - response = client.post(reverse("savesamplearea"), create_data) + response = self.client.post(reverse("savesamplearea"), create_data) self.assertEqual(response.status_code, 200) # Delete @@ -150,6 +143,6 @@ def test_create_delete_sample(self): } delete_data = JSONSerializer().serialize(delete_data) content_type = "application/json" - response = client.post(reverse("deletesamplearea"), delete_data, content_type=content_type) + response = self.client.post(reverse("deletesamplearea"), delete_data, content_type=content_type) self.assertEqual(response.status_code, 200)