Skip to content

Commit

Permalink
[maykinmedia/objects-api#481] Create command tests and delete old tests
Browse files Browse the repository at this point in the history
  • Loading branch information
danielmursa-dev committed Dec 9, 2024
1 parent 350b5ff commit 0c84097
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 313 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from io import StringIO
from pathlib import Path

from django.core.management import CommandError, call_command
from django.test import TestCase

from django_setup_configuration.exceptions import (
Expand Down Expand Up @@ -325,7 +327,7 @@ def test_invalid_setup_token_unique(self):
self.assertTrue(
"Failed configuring token token-2" in str(command_error.exception)
)
self.assertEqual(TokenAuth.objects.count(), 0)
self.assertEqual(TokenAuth.objects.count(), 1)

def test_invalid_setup_contact_person(self):
object_source = {
Expand Down Expand Up @@ -386,3 +388,54 @@ def test_invalid_setup_identifier(self):
in str(command_error.exception)
)
self.assertEqual(TokenAuth.objects.count(), 0)

def test_valid_call_command(self):
stdout = StringIO()
self.assertEqual(TokenAuth.objects.count(), 0)
call_command(
"setup_configuration",
"--yaml-file",
str(DIR_FILES / "valid_setup_default.yaml"),
stdout=stdout,
)
self.assertTrue(
"Successfully executed step: Configuration to set up authentication tokens for ObjectTypes"
in stdout.getvalue()
)
self.assertEqual(TokenAuth.objects.count(), 2)

tokens = TokenAuth.objects.order_by("created")
self.assertEqual(tokens.count(), 2)

token = tokens[0]
self.assertEqual(token.identifier, "token-1")
self.assertEqual(token.token, "18b2b74ef994314b84021d47b9422e82b685d82f")
self.assertEqual(token.contact_person, "Person 1")
self.assertEqual(token.email, "[email protected]")
self.assertEqual(token.organization, "")
self.assertEqual(token.application, "")
self.assertEqual(token.administration, "")

token = tokens[1]
self.assertEqual(token.identifier, "token-2")
self.assertEqual(token.contact_person, "Person 2")
self.assertEqual(token.token, "e882642bd0ec2482adcdc97258c2e6f98cb06d85")
self.assertEqual(token.email, "[email protected]")
self.assertEqual(token.organization, "")
self.assertEqual(token.application, "")
self.assertEqual(token.administration, "")

def test_invalid_call_command(self):
self.assertEqual(TokenAuth.objects.count(), 0)
with self.assertRaises(CommandError) as command_error:
call_command(
"setup_configuration",
"--yaml-file",
str(DIR_FILES / "invalid_setup_empty.yaml"),
)

self.assertTrue(
"Failed to load config model for Configuration to set up authentication tokens for ObjectTypes"
in str(command_error.exception)
)
self.assertEqual(TokenAuth.objects.count(), 0)
Empty file.
102 changes: 0 additions & 102 deletions src/objecttypes/tests/commands/test_setup_configuration.py

This file was deleted.

Empty file.
72 changes: 0 additions & 72 deletions src/objecttypes/tests/config/test_demo_configuration.py

This file was deleted.

72 changes: 0 additions & 72 deletions src/objecttypes/tests/config/test_objects_configuration.py

This file was deleted.

66 changes: 0 additions & 66 deletions src/objecttypes/tests/config/test_site_configuration.py

This file was deleted.

0 comments on commit 0c84097

Please sign in to comment.