Skip to content

Commit

Permalink
Refactor to reduce login boilerplate
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtylerwalls committed Jun 27, 2024
1 parent 86470f5 commit b42b297
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions arches_for_science/tests.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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(
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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)

0 comments on commit b42b297

Please sign in to comment.