Skip to content

Commit

Permalink
✅ Add tests for JWTSecretsConfigurationStep
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenbal committed Dec 5, 2024
1 parent 6f5d37f commit 323f98a
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
1 change: 1 addition & 0 deletions testapp/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"simple_certmanager",
"zgw_consumers",
"notifications_api_common",
"django_setup_configuration",
"vng_api_common",
"vng_api_common.authorizations",
"vng_api_common.notifications",
Expand Down
7 changes: 7 additions & 0 deletions tests/files/setup_config_jwtsecrets.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
vng_api_common_credentials_config_enable: True
vng_api_common_credentials:
items:
- identifier: user-id
secret: super-secret
- identifier: user-id2
secret: super-secret2
62 changes: 62 additions & 0 deletions tests/test_configuration_steps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import pytest
from django_setup_configuration.test_utils import execute_single_step

from vng_api_common.contrib.setup_configuration.steps import JWTSecretsConfigurationStep
from vng_api_common.models import JWTSecret

CONFIG_FILE_PATH = "tests/files/setup_config_jwtsecrets.yaml"


@pytest.mark.django_db
def test_execute_configuration_step_success():
execute_single_step(JWTSecretsConfigurationStep, yaml_source=CONFIG_FILE_PATH)

assert JWTSecret.objects.count() == 2

credential1, credential2 = JWTSecret.objects.all()

assert credential1.identifier == "user-id"
assert credential1.secret == "super-secret"

assert credential2.identifier == "user-id2"
assert credential2.secret == "super-secret2"


@pytest.mark.django_db
def test_execute_configuration_step_update_existing():
JWTSecret.objects.create(identifier="user-id", secret="old")
JWTSecret.objects.create(identifier="user-id2", secret="old2")

execute_single_step(JWTSecretsConfigurationStep, yaml_source=CONFIG_FILE_PATH)

assert JWTSecret.objects.count() == 2

credential1, credential2 = JWTSecret.objects.all()

assert credential1.identifier == "user-id"
assert credential1.secret == "super-secret"

assert credential2.identifier == "user-id2"
assert credential2.secret == "super-secret2"


@pytest.mark.django_db
def test_execute_configuration_step_idempotent():
def make_assertions():
assert JWTSecret.objects.count() == 2

credential1, credential2 = JWTSecret.objects.all()

assert credential1.identifier == "user-id"
assert credential1.secret == "super-secret"

assert credential2.identifier == "user-id2"
assert credential2.secret == "super-secret2"

execute_single_step(JWTSecretsConfigurationStep, yaml_source=CONFIG_FILE_PATH)

make_assertions()

execute_single_step(JWTSecretsConfigurationStep, yaml_source=CONFIG_FILE_PATH)

make_assertions()

0 comments on commit 323f98a

Please sign in to comment.