identity: refactor requirements tests
This commit is contained in:
parent
88f8b21633
commit
7fedee55fa
|
@ -20,6 +20,7 @@ from subiquity.server.autoinstall import AutoinstallError
|
||||||
from subiquity.server.controllers.identity import IdentityController
|
from subiquity.server.controllers.identity import IdentityController
|
||||||
from subiquitycore.tests import SubiTestCase
|
from subiquitycore.tests import SubiTestCase
|
||||||
from subiquitycore.tests.mocks import make_app
|
from subiquitycore.tests.mocks import make_app
|
||||||
|
from subiquitycore.tests.parameterized import parameterized
|
||||||
|
|
||||||
|
|
||||||
class TestIdentityController(SubiTestCase):
|
class TestIdentityController(SubiTestCase):
|
||||||
|
@ -41,50 +42,44 @@ class TestControllerUserCreationFlows(SubiTestCase):
|
||||||
self.ic = IdentityController(self.app)
|
self.ic = IdentityController(self.app)
|
||||||
self.ic.model.user = None
|
self.ic.model.user = None
|
||||||
|
|
||||||
async def test_server_requires_identity_case_4a1(self):
|
# Test cases for 4a1. Copied for 4a2 but all cases should be valid for desktop.
|
||||||
self.app.base_model.source.current.variant = "server"
|
test_cases = [
|
||||||
|
# (autoinstall config, valid)
|
||||||
# Autoinstall: no identity or user data and identity is not interactive
|
#
|
||||||
self.app.autoinstall_config = {"interactive-sections": ["not-identity"]}
|
# No identity or user data section and identity is not interactive
|
||||||
with self.assertRaises(AutoinstallError):
|
({"interactive-sections": ["not-identity"]}, False),
|
||||||
self.ic.load_autoinstall_data(None)
|
|
||||||
|
|
||||||
async def test_server_requires_identity_case_4a1__ok_interactive(self):
|
|
||||||
"""Test no require identity for interactive identity"""
|
|
||||||
self.app.base_model.source.current.variant = "server"
|
|
||||||
|
|
||||||
# Explicitly interactive
|
# Explicitly interactive
|
||||||
self.app.autoinstall_config = {"interactive-sections": ["identity"]}
|
({"interactive-sections": ["identity"]}, True),
|
||||||
self.ic.load_autoinstall_data(None)
|
|
||||||
|
|
||||||
# Implicitly interactive
|
# Implicitly interactive
|
||||||
self.app.autoinstall_config = {"interactive-sections": ["*"]}
|
({"interactive-sections": ["*"]}, True),
|
||||||
self.ic.load_autoinstall_data(None)
|
|
||||||
|
|
||||||
# No Autoinstall => interactive
|
# No Autoinstall => interactive
|
||||||
self.app.autoinstall_config = {}
|
({}, True),
|
||||||
self.ic.load_autoinstall_data(None)
|
# Can be missing if reset-parition-only specified
|
||||||
|
({"storage": {"layout": {"reset-partition-only": True}}}, True),
|
||||||
|
# Can't be missing if reset-parition-only is not specified
|
||||||
|
({"storage": {"layout": {}}}, False),
|
||||||
|
# user-data passed instead
|
||||||
|
({"user-data": "..."}, True),
|
||||||
|
]
|
||||||
|
|
||||||
async def test_server_requires_identity_case_4a1__reset_only_true(self):
|
@parameterized.expand(test_cases)
|
||||||
"""Test no require identity for reset-partition-only=yes."""
|
async def test_server_requires_identity_case_4a1(self, config, valid):
|
||||||
|
"""Test require identity section on Server"""
|
||||||
self.app.base_model.source.current.variant = "server"
|
self.app.base_model.source.current.variant = "server"
|
||||||
|
|
||||||
# No raise if reset-parition-only specified
|
self.app.autoinstall_config = config
|
||||||
self.app.autoinstall_config = {
|
|
||||||
"storage": {"layout": {"reset-partition-only": True}}
|
|
||||||
}
|
|
||||||
self.ic.load_autoinstall_data(None)
|
|
||||||
|
|
||||||
async def test_server_requires_identity_case_4a1__reset_only_false(self):
|
if not valid:
|
||||||
"""Test require identity for reset-partition-only=no."""
|
|
||||||
self.app.base_model.source.current.variant = "server"
|
|
||||||
|
|
||||||
# raises if no reset-parition-only in storage:layout:
|
|
||||||
self.app.autoinstall_config = {"storage": {"layout": {}}}
|
|
||||||
with self.assertRaises(AutoinstallError):
|
with self.assertRaises(AutoinstallError):
|
||||||
self.ic.load_autoinstall_data(None)
|
self.ic.load_autoinstall_data(None)
|
||||||
|
else:
|
||||||
async def test_desktop_does_not_require_identity_case_4a2(self):
|
self.ic.load_autoinstall_data(None)
|
||||||
self.app.base_model.source.current.variant = "desktop"
|
|
||||||
|
@parameterized.expand(test_cases)
|
||||||
|
async def test_desktop_does_not_require_identity_case_4a2(self, config, valid):
|
||||||
|
"""Test require identity section on Desktop"""
|
||||||
|
self.app.base_model.source.current.variant = "desktop"
|
||||||
|
|
||||||
|
self.app.autoinstall_config = config
|
||||||
|
# should never raise
|
||||||
self.ic.load_autoinstall_data(None)
|
self.ic.load_autoinstall_data(None)
|
||||||
# should not raise
|
|
||||||
|
|
Loading…
Reference in New Issue