-
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.
Merge pull request #1165 from maykinmedia/feature/2324-setup-config-t…
…ests ✅ [#2324] Add test for setup_configuration command
- Loading branch information
Showing
1 changed file
with
99 additions
and
0 deletions.
There are no files selected for viewing
99 changes: 99 additions & 0 deletions
99
src/open_inwoner/configurations/tests/bootstrap/test_setup_configuration.py
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 |
---|---|---|
@@ -0,0 +1,99 @@ | ||
from io import StringIO | ||
from unittest.mock import patch | ||
|
||
from django.core.management import call_command | ||
from django.test import override_settings | ||
|
||
from rest_framework.test import APITestCase | ||
|
||
from open_inwoner.configurations.bootstrap.auth import ( | ||
AdminOIDCConfigurationStep, | ||
DigiDConfigurationStep, | ||
DigiDOIDCConfigurationStep, | ||
eHerkenningConfigurationStep, | ||
eHerkenningOIDCConfigurationStep, | ||
) | ||
from open_inwoner.configurations.bootstrap.kic import ( | ||
ContactmomentenAPIConfigurationStep, | ||
KICAPIsConfigurationStep, | ||
KlantenAPIConfigurationStep, | ||
) | ||
from open_inwoner.configurations.bootstrap.siteconfig import SiteConfigurationStep | ||
from open_inwoner.configurations.bootstrap.zgw import ( | ||
CatalogiAPIConfigurationStep, | ||
DocumentenAPIConfigurationStep, | ||
FormulierenAPIConfigurationStep, | ||
ZakenAPIConfigurationStep, | ||
ZGWAPIsConfigurationStep, | ||
) | ||
|
||
STEPS_TO_CONFIGURE = [ | ||
ZakenAPIConfigurationStep(), | ||
CatalogiAPIConfigurationStep(), | ||
DocumentenAPIConfigurationStep(), | ||
FormulierenAPIConfigurationStep(), | ||
ZGWAPIsConfigurationStep(), | ||
KlantenAPIConfigurationStep(), | ||
ContactmomentenAPIConfigurationStep(), | ||
KICAPIsConfigurationStep(), | ||
SiteConfigurationStep(), | ||
DigiDOIDCConfigurationStep(), | ||
eHerkenningOIDCConfigurationStep(), | ||
AdminOIDCConfigurationStep(), | ||
DigiDConfigurationStep(), | ||
eHerkenningConfigurationStep(), | ||
] | ||
|
||
REQUIRED_SETTINGS = { | ||
setting_name: "SET" | ||
for step in STEPS_TO_CONFIGURE | ||
for setting_name in step.required_settings | ||
} | ||
|
||
|
||
@override_settings(**REQUIRED_SETTINGS) | ||
class SetupConfigurationTests(APITestCase): | ||
maxDiff = None | ||
|
||
def setUp(self): | ||
super().setUp() | ||
|
||
self.mocks = [] | ||
for step in STEPS_TO_CONFIGURE: | ||
mock_step = patch( | ||
f"{step.__class__.__module__}.{step.__class__.__qualname__}.configure" | ||
) | ||
self.mocks.append(mock_step) | ||
mock_step.start() | ||
|
||
def stop_mocks(): | ||
for mock_step in self.mocks: | ||
mock_step.stop() | ||
|
||
self.addCleanup(stop_mocks) | ||
|
||
def test_setup_configuration_success(self, *mocks): | ||
stdout = StringIO() | ||
|
||
call_command( | ||
"setup_configuration", | ||
no_selftest=True, | ||
stdout=stdout, | ||
no_color=True, | ||
) | ||
|
||
output_per_step = [] | ||
for step in STEPS_TO_CONFIGURE: | ||
output_per_step.append(f"Configuring {str(step)}...") | ||
output_per_step.append(f"{str(step)} is successfully configured") | ||
|
||
command_output = stdout.getvalue().splitlines() | ||
expected_output = [ | ||
"Configuration will be set up with following steps: " | ||
f"[{', '.join(str(step) for step in STEPS_TO_CONFIGURE)}]", | ||
*output_per_step, | ||
"Selftest is skipped.", | ||
"Instance configuration completed.", | ||
] | ||
|
||
self.assertEqual(command_output, expected_output) |