-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[maykinmedia/objects-api#481] Create command tests and delete old tests
- Loading branch information
1 parent
350b5ff
commit 0c84097
Showing
7 changed files
with
54 additions
and
313 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ( | ||
|
@@ -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 = { | ||
|
@@ -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
102
src/objecttypes/tests/commands/test_setup_configuration.py
This file was deleted.
Oops, something went wrong.
Empty file.
This file was deleted.
Oops, something went wrong.
72 changes: 0 additions & 72 deletions
72
src/objecttypes/tests/config/test_objects_configuration.py
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.