This commit is contained in:
David Kennedy 2024-07-05 12:13:42 -04:00
parent 5b4711e6f3
commit e338a73249
No known key found for this signature in database
GPG key ID: 6528A5386E66B96B
4 changed files with 511 additions and 534 deletions

View file

@ -525,16 +525,8 @@ class AuditedAdminMockData:
class MockDb(TestCase): class MockDb(TestCase):
"""Hardcoded mocks make test case assertions straightforward. def setUp(self):
setUpClass and tearDownClass are used so that multiple tests super().setUp()
can be executed using the same mock db data without having to
setUp and tearDown the data in between.
This strategy requires that any changes to data within a test
must be cleaned up within the test rather than relying on tearDown."""
@classmethod
def setUpClass(self):
super().setUpClass()
username = "test_user" username = "test_user"
first_name = "First" first_name = "First"
last_name = "Last" last_name = "Last"
@ -788,9 +780,8 @@ class MockDb(TestCase):
self.domain_request_6.submission_date = get_time_aware_date(datetime(2024, 4, 2)) self.domain_request_6.submission_date = get_time_aware_date(datetime(2024, 4, 2))
self.domain_request_6.save() self.domain_request_6.save()
@classmethod def tearDown(self):
def tearDownClass(self): super().tearDown()
super().tearDownClass()
PublicContact.objects.all().delete() PublicContact.objects.all().delete()
Domain.objects.all().delete() Domain.objects.all().delete()
DomainInformation.objects.all().delete() DomainInformation.objects.all().delete()

View file

@ -898,16 +898,9 @@ class TestListHeaderAdmin(TestCase):
class TestMyUserAdmin(MockDb): class TestMyUserAdmin(MockDb):
"""Test the MyUserAdmin class in Django Admin.
These tests use MockDb, which runs setUpClass and tearDownClass, rather than
setUp and tearDown. This is for efficiency purposes when running tests, but
also means that care must be taken to clean up within each test, because
setUp and tearDown are not used.
"""
@classmethod def setUp(self):
def setUpClass(self): super().setUp()
super().setUpClass()
admin_site = AdminSite() admin_site = AdminSite()
self.admin = MyUserAdmin(model=get_user_model(), admin_site=admin_site) self.admin = MyUserAdmin(model=get_user_model(), admin_site=admin_site)
self.client = Client(HTTP_HOST="localhost:8080") self.client = Client(HTTP_HOST="localhost:8080")
@ -915,9 +908,8 @@ class TestMyUserAdmin(MockDb):
self.staffuser = create_user() self.staffuser = create_user()
self.test_helper = GenericTestHelper(admin=self.admin) self.test_helper = GenericTestHelper(admin=self.admin)
@classmethod def tearDown(self):
def tearDownClass(self): super().tearDown()
super().tearDownClass()
DomainRequest.objects.all().delete() DomainRequest.objects.all().delete()
User.objects.all().delete() User.objects.all().delete()

File diff suppressed because it is too large Load diff

View file

@ -30,14 +30,10 @@ from .common import MockDb, MockEppLib, less_console_noise, get_time_aware_date
class CsvReportsTest(MockDb): class CsvReportsTest(MockDb):
"""Tests to determine if we are uploading our reports correctly. """Tests to determine if we are uploading our reports correctly.
These tests use MockDb, which runs setUpClass and tearDownClass to handle
creation of fake domain data.
setUp and tearDown in this class set up client and factory.
This is for efficiency purposes when running tests, but
also means that care must be taken to clean up within each test.
""" """
def setUp(self): def setUp(self):
"""setup fake comain data"""
super().setUp() super().setUp()
self.client = Client(HTTP_HOST="localhost:8080") self.client = Client(HTTP_HOST="localhost:8080")
self.factory = RequestFactory() self.factory = RequestFactory()
@ -202,10 +198,6 @@ class CsvReportsTest(MockDb):
class ExportDataTest(MockDb, MockEppLib): class ExportDataTest(MockDb, MockEppLib):
"""Test the ExportData class from csv_export. """Test the ExportData class from csv_export.
These tests use MockDb, which runs setUpClass and tearDownClass.
setUp and tearDown in this test run from MockEppLib to set up EPP mocks.
This is for efficiency purposes when running tests, but
also means that care must be taken to clean up within each test.
""" """
def test_export_domains_to_writer_security_emails_and_first_ready(self): def test_export_domains_to_writer_security_emails_and_first_ready(self):