Skip to content

Commit

Permalink
♻️ [maykinmedia/django-setup-configuration#1] replace get_or_create w…
Browse files Browse the repository at this point in the history
…ith update_or_create in config steps
  • Loading branch information
annashamray committed Apr 23, 2024
1 parent c5f3a1f commit 0ee3a7d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 13 deletions.
9 changes: 1 addition & 8 deletions src/objects/config/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,14 @@ def is_configured(self) -> bool:
return TokenAuth.objects.filter(token=settings.DEMO_TOKEN).exists()

def configure(self):
token_auth, created = TokenAuth.objects.get_or_create(
TokenAuth.objects.update_or_create(
token=settings.DEMO_TOKEN,
defaults={
"contact_person": settings.DEMO_PERSON,
"email": settings.DEMO_EMAIL,
"is_superuser": True,
},
)
if (
token_auth.contact_person != settings.DEMO_PERSON
or token_auth.email != settings.DEMO_EMAIL
):
token_auth.contact_person = settings.DEMO_PERSON
token_auth.email = settings.DEMO_EMAIL
token_auth.save(update_fields=["contact_person", "email"])

def test_configuration(self):
endpoint = reverse("v2:object-list")
Expand Down
6 changes: 1 addition & 5 deletions src/objects/config/objecttypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def is_configured(self) -> bool:
return Service.objects.filter(api_root=settings.OBJECTTYPES_API_ROOT).exists()

def configure(self) -> None:
service, created = Service.objects.update_or_create(
Service.objects.update_or_create(
api_root=settings.OBJECTTYPES_API_ROOT,
defaults={
"label": "Objecttypes API",
Expand All @@ -38,10 +38,6 @@ def configure(self) -> None:
"header_value": f"Token {settings.OBJECTS_OBJECTTYPES_TOKEN}",
},
)
if not created:
service.oas = settings.OBJECTTYPES_API_OAS
service.header_value = f"Token {settings.OBJECTS_OBJECTTYPES_TOKEN}"
service.save(update_fields=["oas", "header_value"])

def test_configuration(self) -> None:
"""
Expand Down

0 comments on commit 0ee3a7d

Please sign in to comment.