Skip to content

Commit

Permalink
refactor(test): use fixtures for institution in doc admin test
Browse files Browse the repository at this point in the history
This prevents the need for having to call `Institution.objects.create` with a
_globally unique_ name in each test (previously, reusing a name would cause an
error)
  • Loading branch information
Restioson committed Nov 7, 2024
1 parent 85cad33 commit ecdc695
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions app/general/tests/test_document_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,18 @@ def setUp(self):
pdf_file = f.read()

self.file_mock = SimpleUploadedFile("test.pdf", pdf_file, content_type="application/pdf")
self.test_institution = Institution.objects.create(name="Test Institution for Document tests")

def tearDown(self):
self.test_institution.delete()

def test_clean_without_url_and_file(self):
tests_form = {
"title": "Test",
"license": "MIT",
"document_type": "Glossary",
"mime_type": "pdf",
"institution": Institution.objects.create(name="Test Institution"),
"institution": self.test_institution,
"url": "",
"uploaded_file": "",
"description": "Test description",
Expand All @@ -46,7 +50,7 @@ def test_clean_without_file(self):
"license": "(c)",
"document_type": "Glossary",
"mime_type": "pdf",
"institution": Institution.objects.create(name="Test Institution 2"),
"institution": self.test_institution,
"url": "www.example.com",
"uploaded_file": "",
"document_data": "",
Expand All @@ -63,7 +67,7 @@ def test_clean_without_url(self):
"license": "CC0",
"document_type": "Glossary",
"mime_type": "pdf",
"institution": Institution.objects.create(name="Test Institution 3"),
"institution": self.test_institution,
"url": "",
"uploaded_file": self.file_mock,
"document_data": "",
Expand All @@ -81,7 +85,7 @@ def test_clean_with_large_file(self):
"license": "MIT",
"document_type": "Glossary",
"mime_type": "pdf",
"institution": Institution.objects.create(name="Test Institution 4"),
"institution": self.test_institution,
"url": "",
"uploaded_file": self.file_mock,
"description": "Test description",
Expand Down

0 comments on commit ecdc695

Please sign in to comment.