mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-25 12:08:40 +02:00
unit tests completed
This commit is contained in:
parent
54c65a6d85
commit
af3877f2e3
1 changed files with 47 additions and 1 deletions
|
@ -21,6 +21,7 @@ from registrar.admin import (
|
|||
MyHostAdmin,
|
||||
UserDomainRoleAdmin,
|
||||
VerifiedByStaffAdmin,
|
||||
FsmModelResource,
|
||||
)
|
||||
from registrar.models import (
|
||||
Domain,
|
||||
|
@ -52,7 +53,7 @@ from .common import (
|
|||
)
|
||||
from django.contrib.sessions.backends.db import SessionStore
|
||||
from django.contrib.auth import get_user_model
|
||||
from unittest.mock import ANY, call, patch
|
||||
from unittest.mock import ANY, call, patch, Mock
|
||||
from unittest import skip
|
||||
|
||||
from django.conf import settings
|
||||
|
@ -62,6 +63,42 @@ import logging
|
|||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class TestFsmModelResource(TestCase):
|
||||
def setUp(self):
|
||||
self.resource = FsmModelResource()
|
||||
|
||||
def test_init_instance(self):
|
||||
"""Test initializing an instance of a class with a FSM field"""
|
||||
|
||||
# Mock a row with FSMField data
|
||||
row_data = {'state': 'ready'}
|
||||
|
||||
self.resource._meta.model = Domain
|
||||
|
||||
instance = self.resource.init_instance(row=row_data)
|
||||
|
||||
# Assert that the instance is initialized correctly
|
||||
self.assertIsInstance(instance, Domain)
|
||||
self.assertEqual(instance.state, 'ready')
|
||||
|
||||
def test_import_field(self):
|
||||
"""Test that importing a field does not import FSM field"""
|
||||
# Mock a field and object
|
||||
field_mock = Mock(attribute='state')
|
||||
obj_mock = Mock(_meta=Mock(fields=[Mock(name='state', spec=['name'], __class__=Mock)]))
|
||||
|
||||
# Mock the super() method
|
||||
super_mock = Mock()
|
||||
self.resource.import_field = super_mock
|
||||
|
||||
# Call the method with FSMField and non-FSMField
|
||||
self.resource.import_field(field_mock, obj_mock, data={}, is_m2m=False)
|
||||
|
||||
# Assert that super().import_field() is called only for non-FSMField
|
||||
super_mock.assert_called_once_with(field_mock, obj_mock, data={}, is_m2m=False)
|
||||
|
||||
|
||||
|
||||
class TestDomainAdmin(MockEppLib, WebTest):
|
||||
# csrf checks do not work with WebTest.
|
||||
# We disable them here. TODO for another ticket.
|
||||
|
@ -759,6 +796,15 @@ class TestDomainAdmin(MockEppLib, WebTest):
|
|||
def test_place_and_remove_hold_epp(self):
|
||||
raise
|
||||
|
||||
@override_settings(IS_PRODUCTION=True)
|
||||
def test_prod_only_shows_export(self):
|
||||
"""Test that production environment only displays export"""
|
||||
with less_console_noise():
|
||||
response = self.client.get("/admin/registrar/domain/")
|
||||
self.assertContains(response, ">Export<")
|
||||
# Now let's make sure the long description does not exist
|
||||
self.assertNotContains(response, ">Import<")
|
||||
|
||||
def tearDown(self):
|
||||
super().tearDown()
|
||||
PublicContact.objects.all().delete()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue