Skip to content

Commit

Permalink
[#293] add test for verifying idempotent behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
SonnyBA committed Nov 29, 2024
1 parent 0e5ff83 commit dcadd08
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
tokens_config_enable: true

tokens_config:
group:
- identifier: token-1
contact_person: Person 1
email: [email protected]
organization: Organization XYZ
application: Application XYZ
administration: Administration XYZ

- identifier: token-2
contact_person: Person 2
email: [email protected]
organization: Organization ZYX
application: Application ZYX
administration: Administration ZYX
54 changes: 52 additions & 2 deletions src/openklant/setup_configuration/tests/test_token_auth_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,5 +173,55 @@ def test_validation_errors(self):
self.assertEqual(second_token.application, "Application ZYX")
self.assertEqual(second_token.administration, "Administration ZYX")

def test_impodent_configuration_step(self):
raise NotImplementedError
def test_idempotent_step(self):
test_file_path = str(TEST_FILES / "token_idempotent.yaml")

execute_single_step(
TokenAuthConfigurationStep, yaml_source=test_file_path
)

tokens = TokenAuth.objects.order_by("created")

self.assertEqual(tokens.count(), 2)

first_token: TokenAuth = tokens[0]

self.assertEqual(first_token.identifier, "token-1")
self.assertEqual(first_token.contact_person, "Person 1")
self.assertEqual(first_token.email, "[email protected]")
self.assertEqual(first_token.organization, "Organization XYZ")
self.assertEqual(first_token.application, "Application XYZ")
self.assertEqual(first_token.administration, "Administration XYZ")

second_token: TokenAuth = tokens[1]

self.assertEqual(second_token.identifier, "token-2")
self.assertEqual(second_token.contact_person, "Person 2")
self.assertEqual(second_token.email, "[email protected]")
self.assertEqual(second_token.organization, "Organization ZYX")
self.assertEqual(second_token.application, "Application ZYX")
self.assertEqual(second_token.administration, "Administration ZYX")

execute_single_step(
TokenAuthConfigurationStep, yaml_source=test_file_path
)

self.assertEqual(TokenAuth.objects.count(), 2)

first_token.refresh_from_db()

self.assertEqual(first_token.identifier, "token-1")
self.assertEqual(first_token.contact_person, "Person 1")
self.assertEqual(first_token.email, "[email protected]")
self.assertEqual(first_token.organization, "Organization XYZ")
self.assertEqual(first_token.application, "Application XYZ")
self.assertEqual(first_token.administration, "Administration XYZ")

second_token.refresh_from_db()

self.assertEqual(second_token.identifier, "token-2")
self.assertEqual(second_token.contact_person, "Person 2")
self.assertEqual(second_token.email, "[email protected]")
self.assertEqual(second_token.organization, "Organization ZYX")
self.assertEqual(second_token.application, "Application ZYX")
self.assertEqual(second_token.administration, "Administration ZYX")

0 comments on commit dcadd08

Please sign in to comment.