mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-08-21 16:51:08 +02:00
fix unit tests
This commit is contained in:
parent
7f34d50ae9
commit
5313ab33b3
3 changed files with 46 additions and 35 deletions
|
@ -149,7 +149,7 @@ class Command(BaseCommand):
|
||||||
self.di_to_update, self.di_failed_to_update, self.di_skipped, debug, log_header
|
self.di_to_update, self.di_failed_to_update, self.di_skipped, debug, log_header
|
||||||
)
|
)
|
||||||
|
|
||||||
def sync_organization_type(self, sender, instance, force_update=False):
|
def sync_organization_type(self, sender, instance):
|
||||||
"""
|
"""
|
||||||
Updates the organization_type (without saving) to match
|
Updates the organization_type (without saving) to match
|
||||||
the is_election_board and generic_organization_type fields.
|
the is_election_board and generic_organization_type fields.
|
||||||
|
@ -176,5 +176,5 @@ class Command(BaseCommand):
|
||||||
election_org_to_generic_org_map=election_org_map,
|
election_org_to_generic_org_map=election_org_map,
|
||||||
)
|
)
|
||||||
|
|
||||||
instance = org_type_helper.create_or_update_organization_type(force_update)
|
instance = org_type_helper.create_or_update_organization_type()
|
||||||
return instance
|
return instance
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import copy
|
import copy
|
||||||
from datetime import date, datetime, time
|
from datetime import date, datetime, time
|
||||||
from unittest import skip
|
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
|
@ -25,6 +24,7 @@ from epplibwrapper import commands, common
|
||||||
from .common import MockEppLib, less_console_noise, completed_domain_request
|
from .common import MockEppLib, less_console_noise, completed_domain_request
|
||||||
from api.tests.common import less_console_noise_decorator
|
from api.tests.common import less_console_noise_decorator
|
||||||
|
|
||||||
|
|
||||||
class TestPopulateOrganizationType(MockEppLib):
|
class TestPopulateOrganizationType(MockEppLib):
|
||||||
"""Tests for the populate_organization_type script"""
|
"""Tests for the populate_organization_type script"""
|
||||||
|
|
||||||
|
@ -86,7 +86,7 @@ class TestPopulateOrganizationType(MockEppLib):
|
||||||
Contact.objects.all().delete()
|
Contact.objects.all().delete()
|
||||||
Website.objects.all().delete()
|
Website.objects.all().delete()
|
||||||
|
|
||||||
#@less_console_noise_decorator
|
@less_console_noise_decorator
|
||||||
def run_populate_organization_type(self):
|
def run_populate_organization_type(self):
|
||||||
"""
|
"""
|
||||||
This method executes the populate_organization_type command.
|
This method executes the populate_organization_type command.
|
||||||
|
@ -114,15 +114,15 @@ class TestPopulateOrganizationType(MockEppLib):
|
||||||
|
|
||||||
# Test domain request
|
# Test domain request
|
||||||
with self.subTest(field="DomainRequest"):
|
with self.subTest(field="DomainRequest"):
|
||||||
self.assertEqual(domain_request.generic_org_type, expected_values['generic_org_type'])
|
self.assertEqual(domain_request.generic_org_type, expected_values["generic_org_type"])
|
||||||
self.assertEqual(domain_request.is_election_board, expected_values['is_election_board'])
|
self.assertEqual(domain_request.is_election_board, expected_values["is_election_board"])
|
||||||
self.assertEqual(domain_request.organization_type, expected_values['organization_type'])
|
self.assertEqual(domain_request.organization_type, expected_values["organization_type"])
|
||||||
|
|
||||||
# Test domain info
|
# Test domain info
|
||||||
with self.subTest(field="DomainInformation"):
|
with self.subTest(field="DomainInformation"):
|
||||||
self.assertEqual(domain_info.generic_org_type, expected_values['generic_org_type'])
|
self.assertEqual(domain_info.generic_org_type, expected_values["generic_org_type"])
|
||||||
self.assertEqual(domain_info.is_election_board, expected_values['is_election_board'])
|
self.assertEqual(domain_info.is_election_board, expected_values["is_election_board"])
|
||||||
self.assertEqual(domain_info.organization_type, expected_values['organization_type'])
|
self.assertEqual(domain_info.organization_type, expected_values["organization_type"])
|
||||||
|
|
||||||
def test_request_and_info_city_not_in_csv(self):
|
def test_request_and_info_city_not_in_csv(self):
|
||||||
"""Tests what happens to a city domain that is not defined in the CSV"""
|
"""Tests what happens to a city domain that is not defined in the CSV"""
|
||||||
|
@ -133,9 +133,9 @@ class TestPopulateOrganizationType(MockEppLib):
|
||||||
# Since the presave fixture is in effect, we should expect that
|
# Since the presave fixture is in effect, we should expect that
|
||||||
# is_election_board is equal to none, even though we tried to define it as "True"
|
# is_election_board is equal to none, even though we tried to define it as "True"
|
||||||
expected_values = {
|
expected_values = {
|
||||||
'is_election_board': False,
|
"is_election_board": False,
|
||||||
'generic_org_type': DomainRequest.OrganizationChoices.CITY,
|
"generic_org_type": DomainRequest.OrganizationChoices.CITY,
|
||||||
'organization_type': DomainRequest.OrgChoicesElectionOffice.CITY,
|
"organization_type": DomainRequest.OrgChoicesElectionOffice.CITY,
|
||||||
}
|
}
|
||||||
self.assert_expected_org_values_on_request_and_info(city_request, city_info, expected_values)
|
self.assert_expected_org_values_on_request_and_info(city_request, city_info, expected_values)
|
||||||
|
|
||||||
|
@ -157,9 +157,9 @@ class TestPopulateOrganizationType(MockEppLib):
|
||||||
# Since the presave fixture is in effect, we should expect that
|
# Since the presave fixture is in effect, we should expect that
|
||||||
# is_election_board is equal to none, even though we tried to define it as "True"
|
# is_election_board is equal to none, even though we tried to define it as "True"
|
||||||
expected_values = {
|
expected_values = {
|
||||||
'is_election_board': None,
|
"is_election_board": None,
|
||||||
'generic_org_type': DomainRequest.OrganizationChoices.FEDERAL,
|
"generic_org_type": DomainRequest.OrganizationChoices.FEDERAL,
|
||||||
'organization_type': DomainRequest.OrgChoicesElectionOffice.FEDERAL,
|
"organization_type": DomainRequest.OrgChoicesElectionOffice.FEDERAL,
|
||||||
}
|
}
|
||||||
self.assert_expected_org_values_on_request_and_info(federal_request, federal_info, expected_values)
|
self.assert_expected_org_values_on_request_and_info(federal_request, federal_info, expected_values)
|
||||||
|
|
||||||
|
@ -172,6 +172,10 @@ class TestPopulateOrganizationType(MockEppLib):
|
||||||
# All values should be the same
|
# All values should be the same
|
||||||
self.assert_expected_org_values_on_request_and_info(federal_request, federal_info, expected_values)
|
self.assert_expected_org_values_on_request_and_info(federal_request, federal_info, expected_values)
|
||||||
|
|
||||||
|
def do_nothing(self):
|
||||||
|
"""Does nothing for mocking purposes"""
|
||||||
|
pass
|
||||||
|
|
||||||
def test_request_and_info_tribal_add_election_office(self):
|
def test_request_and_info_tribal_add_election_office(self):
|
||||||
"""
|
"""
|
||||||
Tests if a tribal domain in the election csv changes organization_type to TRIBAL - ELECTION
|
Tests if a tribal domain in the election csv changes organization_type to TRIBAL - ELECTION
|
||||||
|
@ -181,16 +185,18 @@ class TestPopulateOrganizationType(MockEppLib):
|
||||||
# Set org type fields to none to mimic an environment without this data
|
# Set org type fields to none to mimic an environment without this data
|
||||||
tribal_request = self.domain_request_3
|
tribal_request = self.domain_request_3
|
||||||
tribal_request.organization_type = None
|
tribal_request.organization_type = None
|
||||||
tribal_request.save()
|
|
||||||
tribal_info = self.domain_info_3
|
tribal_info = self.domain_info_3
|
||||||
tribal_info.organization_type = None
|
tribal_info.organization_type = None
|
||||||
|
with patch.object(DomainRequest, "sync_organization_type", self.do_nothing):
|
||||||
|
with patch.object(DomainInformation, "sync_organization_type", self.do_nothing):
|
||||||
|
tribal_request.save()
|
||||||
tribal_info.save()
|
tribal_info.save()
|
||||||
|
|
||||||
# Make sure that all data is correct before proceeding.
|
# Make sure that all data is correct before proceeding.
|
||||||
expected_values = {
|
expected_values = {
|
||||||
'is_election_board': False,
|
"is_election_board": False,
|
||||||
'generic_org_type': DomainRequest.OrganizationChoices.TRIBAL,
|
"generic_org_type": DomainRequest.OrganizationChoices.TRIBAL,
|
||||||
'organization_type': None,
|
"organization_type": None,
|
||||||
}
|
}
|
||||||
self.assert_expected_org_values_on_request_and_info(tribal_request, tribal_info, expected_values)
|
self.assert_expected_org_values_on_request_and_info(tribal_request, tribal_info, expected_values)
|
||||||
|
|
||||||
|
@ -219,10 +225,12 @@ class TestPopulateOrganizationType(MockEppLib):
|
||||||
|
|
||||||
# Set org type fields to none to mimic an environment without this data
|
# Set org type fields to none to mimic an environment without this data
|
||||||
tribal_election_request = self.domain_request_4
|
tribal_election_request = self.domain_request_4
|
||||||
tribal_election_request.organization_type = None
|
|
||||||
tribal_election_request.save()
|
|
||||||
tribal_election_info = self.domain_info_4
|
tribal_election_info = self.domain_info_4
|
||||||
|
tribal_election_request.organization_type = None
|
||||||
tribal_election_info.organization_type = None
|
tribal_election_info.organization_type = None
|
||||||
|
with patch.object(DomainRequest, "sync_organization_type", self.do_nothing):
|
||||||
|
with patch.object(DomainInformation, "sync_organization_type", self.do_nothing):
|
||||||
|
tribal_election_request.save()
|
||||||
tribal_election_info.save()
|
tribal_election_info.save()
|
||||||
|
|
||||||
# Make sure that all data is correct before proceeding.
|
# Make sure that all data is correct before proceeding.
|
||||||
|
@ -230,11 +238,13 @@ class TestPopulateOrganizationType(MockEppLib):
|
||||||
# organization_type variable is already pre-populated. We will test what happens when
|
# organization_type variable is already pre-populated. We will test what happens when
|
||||||
# it is not in another test.
|
# it is not in another test.
|
||||||
expected_values = {
|
expected_values = {
|
||||||
'is_election_board': True,
|
"is_election_board": True,
|
||||||
'generic_org_type': DomainRequest.OrganizationChoices.TRIBAL,
|
"generic_org_type": DomainRequest.OrganizationChoices.TRIBAL,
|
||||||
'organization_type': None
|
"organization_type": None,
|
||||||
}
|
}
|
||||||
self.assert_expected_org_values_on_request_and_info(tribal_election_request, tribal_election_info, expected_values)
|
self.assert_expected_org_values_on_request_and_info(
|
||||||
|
tribal_election_request, tribal_election_info, expected_values
|
||||||
|
)
|
||||||
|
|
||||||
# Run the populate script
|
# Run the populate script
|
||||||
try:
|
try:
|
||||||
|
@ -248,7 +258,9 @@ class TestPopulateOrganizationType(MockEppLib):
|
||||||
expected_values["organization_type"] = DomainRequest.OrgChoicesElectionOffice.TRIBAL
|
expected_values["organization_type"] = DomainRequest.OrgChoicesElectionOffice.TRIBAL
|
||||||
tribal_election_request.refresh_from_db()
|
tribal_election_request.refresh_from_db()
|
||||||
tribal_election_info.refresh_from_db()
|
tribal_election_info.refresh_from_db()
|
||||||
self.assert_expected_org_values_on_request_and_info(tribal_election_request, tribal_election_info, expected_values)
|
self.assert_expected_org_values_on_request_and_info(
|
||||||
|
tribal_election_request, tribal_election_info, expected_values
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class TestPopulateFirstReady(TestCase):
|
class TestPopulateFirstReady(TestCase):
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from django.contrib.auth import get_user_model
|
from django.contrib.auth import get_user_model
|
||||||
from registrar.models import Contact, DomainRequest, Domain, DomainInformation
|
from registrar.models import Contact
|
||||||
from registrar.tests.common import completed_domain_request
|
|
||||||
|
|
||||||
|
|
||||||
class TestUserPostSave(TestCase):
|
class TestUserPostSave(TestCase):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue