From 4292c38b4705c9d7297afd925d273e1cbfbeb126 Mon Sep 17 00:00:00 2001 From: Alysia Broddrick Date: Tue, 12 Sep 2023 18:06:06 -0700 Subject: [PATCH] fixed linting and merge bug --- src/registrar/admin.py | 5 ++--- src/registrar/management/commands/load.py | 2 +- src/registrar/models/domain.py | 22 ++++++++++------------ src/registrar/tests/test_models_domain.py | 20 +++++++++++++------- src/registrar/tests/test_views.py | 2 +- 5 files changed, 27 insertions(+), 24 deletions(-) diff --git a/src/registrar/admin.py b/src/registrar/admin.py index 164bbe4aa..b29bbc24d 100644 --- a/src/registrar/admin.py +++ b/src/registrar/admin.py @@ -4,7 +4,6 @@ from django.contrib.auth.admin import UserAdmin as BaseUserAdmin from django.contrib.contenttypes.models import ContentType from django.http.response import HttpResponseRedirect from django.urls import reverse -from registrar.models.public_contact import PublicContact from registrar.models.utility.admin_sort_fields import AdminSortFields from . import models from auditlog.models import LogEntry # type: ignore @@ -220,7 +219,7 @@ class DomainAdmin(ListHeaderAdmin): "_remove_client_hold": self.do_remove_client_hold, "_edit_domain": self.do_edit_domain, "_delete_domain": self.do_delete_domain, - "_get_status": self.do_get_status + "_get_status": self.do_get_status, } # Check which action button was pressed and call the corresponding function @@ -243,7 +242,7 @@ class DomainAdmin(ListHeaderAdmin): ("Domain %s Should now be deleted " ". Thanks!") % obj.name, ) return HttpResponseRedirect(".") - + def do_get_status(self, request, obj): try: statuses = obj.statuses diff --git a/src/registrar/management/commands/load.py b/src/registrar/management/commands/load.py index 2253ce1a4..589d37260 100644 --- a/src/registrar/management/commands/load.py +++ b/src/registrar/management/commands/load.py @@ -17,4 +17,4 @@ class Command(BaseCommand): UserFixture.load() DomainApplicationFixture.load() DomainFixture.load() - logger.info("All fixtures loaded.") \ No newline at end of file + logger.info("All fixtures loaded.") diff --git a/src/registrar/models/domain.py b/src/registrar/models/domain.py index a67131633..3adc72aae 100644 --- a/src/registrar/models/domain.py +++ b/src/registrar/models/domain.py @@ -116,14 +116,11 @@ class Domain(TimeStampedModel, DomainHelper): READY = "ready" # Registrar manually changed state to client hold - ON_HOLD = "client hold" + ON_HOLD = "on hold" # previously existed but has been deleted from the registry DELETED = "deleted" - # when a domain is on hold - ONHOLD = "onhold" - class Cache(property): """ Python descriptor to turn class methods into properties. @@ -453,10 +450,13 @@ class Domain(TimeStampedModel, DomainHelper): try: contacts = self._get_property("contacts") for contact in contacts: - ##zander don't do this just to do the bare bones here - if "type" in contact.keys() and contact["type"] == PublicContact.ContactTypeChoices.SECURITY: - tempContact= self.get_default_security_contact() - tempContact.email=contact["email"] + # zander don't do this just to do the bare bones here + if ( + "type" in contact.keys() + and contact["type"] == PublicContact.ContactTypeChoices.SECURITY + ): + tempContact = self.get_default_security_contact() + tempContact.email = contact["email"] return tempContact except Exception as err: # use better error handling @@ -642,14 +642,12 @@ class Domain(TimeStampedModel, DomainHelper): def clientHoldStatus(self): return epp.Status(state=self.Status.CLIENT_HOLD, description="", lang="en") - @transition(field="state", source=[State.READY], target=State.ONHOLD) def _place_client_hold(self): """This domain should not be active. may raises RegistryError, should be caught or handled correctly by caller""" request = commands.UpdateDomain(name=self.name, add=[self.clientHoldStatus()]) registry.send(request) - @transition(field="state", source=[State.ONHOLD], target=State.READY) def _remove_client_hold(self): """This domain is okay to be active. may raises RegistryError, should be caught or handled correctly by caller""" @@ -793,7 +791,7 @@ class Domain(TimeStampedModel, DomainHelper): administrative_contact.save() @transition(field="state", source=State.DNS_NEEDED, target=State.ON_HOLD) - def clientHold(self): + def place_client_hold(self): """place a clienthold on a domain (no longer should resolve)""" # TODO - ensure all requirements for client hold are made here # (check prohibited statuses) @@ -1012,7 +1010,7 @@ class Domain(TimeStampedModel, DomainHelper): "up_date": getattr(data, "up_date", ...), "voice": getattr(data, "voice", ...), } - + cleaned["contacts"].append( {k: v for k, v in contact.items() if v is not ...} ) diff --git a/src/registrar/tests/test_models_domain.py b/src/registrar/tests/test_models_domain.py index 0ec630674..266ccc91d 100644 --- a/src/registrar/tests/test_models_domain.py +++ b/src/registrar/tests/test_models_domain.py @@ -154,9 +154,16 @@ class TestDomainCache(MockEppLib): self.assertEquals(domain._cache, {}) # send should have been called only once - self.mockedSendFunction.assert_has_calls([call(commands.InfoDomain(name='igorville.gov', auth_info=None), cleaned=True), - call(commands.InfoContact(id='123', auth_info=None), cleaned=True), - call(commands.InfoHost(name='fake.host.com'), cleaned=True)]) + self.mockedSendFunction.assert_has_calls( + [ + call( + commands.InfoDomain(name="igorville.gov", auth_info=None), + cleaned=True, + ), + call(commands.InfoContact(id="123", auth_info=None), cleaned=True), + call(commands.InfoHost(name="fake.host.com"), cleaned=True), + ] + ) def test_cache_used_when_avail(self): """Cache is pulled from if the object has already been accessed""" @@ -259,9 +266,8 @@ class TestDomainCreation(TestCase): def test_empty_domain_creation(self): """Can't create a completely empty domain.""" - #psycopg2.errors.NotNullViolation is being thrown - #which causes integrity error - with self.assertRaisesRegex(IntegrityError,): + + with self.assertRaises(IntegrityError): Domain.objects.create() def test_minimal_creation(self): @@ -271,7 +277,7 @@ class TestDomainCreation(TestCase): def test_duplicate_creation(self): """Can't create domain if name is not unique.""" Domain.objects.create(name="igorville.gov") - with self.assertRaisesRegex(IntegrityError): + with self.assertRaises(IntegrityError): Domain.objects.create(name="igorville.gov") @skip("cannot activate a domain without mock registry") diff --git a/src/registrar/tests/test_views.py b/src/registrar/tests/test_views.py index c0cd33164..ad47d4c8e 100644 --- a/src/registrar/tests/test_views.py +++ b/src/registrar/tests/test_views.py @@ -1132,7 +1132,7 @@ class TestDomainDetail(TestWithDomainPermissions, WebTest): self.app.set_user(self.user.username) self.client.force_login(self.user) -##here + ##here def test_domain_detail_link_works(self): home_page = self.app.get("/") self.assertContains(home_page, "igorville.gov")