diff --git a/tests/test_config.py b/tests/test_config.py index 143b7b1..459079c 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -16,510 +16,462 @@ class UnCoercible: raise ValueError -def test_default(): - import toml +class TestDefault: + def test(self): + import toml - c = KiwiConfig() - version = toml.load("./pyproject.toml")["tool"]["poetry"]["version"] + c = KiwiConfig() + version = toml.load("./pyproject.toml")["tool"]["poetry"]["version"] - assert c == KiwiConfig.from_default() + assert c == KiwiConfig.from_default() - assert c.version == version - assert len(c.shells) == 1 - assert c.shells[0] == Path("/bin/bash") - assert c.projects == [] - assert c.environment == {} - assert c.storage.directory == Path("/var/local/kiwi") - assert c.network.name == "kiwi_hub" - assert c.network.cidr == IPv4Network("10.22.46.0/24") + assert c.version == version + assert len(c.shells) == 1 + assert c.shells[0] == Path("/bin/bash") + assert c.projects == [] + assert c.environment == {} + assert c.storage.directory == Path("/var/local/kiwi") + assert c.network.name == "kiwi_hub" + assert c.network.cidr == IPv4Network("10.22.46.0/24") - kiwi_dict = { - "version": version, - "shells": ["/bin/bash"], - "storage": {"directory": "/var/local/kiwi"}, - "network": { - "name": "kiwi_hub", - "cidr": "10.22.46.0/24", - }, - } - assert c.kiwi_dict == kiwi_dict + kiwi_dict = { + "version": version, + "shells": ["/bin/bash"], + "storage": {"directory": "/var/local/kiwi"}, + "network": { + "name": "kiwi_hub", + "cidr": "10.22.46.0/24", + }, + } + assert c.kiwi_dict == kiwi_dict - yml = ruamel.yaml.YAML() - yml.indent(offset=2) + yml = ruamel.yaml.YAML() + yml.indent(offset=2) - sio = io.StringIO() - from kiwi_scp.misc import _format_kiwi_yml - yml.dump(kiwi_dict, stream=sio, transform=_format_kiwi_yml) - yml_string = sio.getvalue() - sio.close() + sio = io.StringIO() + from kiwi_scp.misc import _format_kiwi_yml + yml.dump(kiwi_dict, stream=sio, transform=_format_kiwi_yml) + yml_string = sio.getvalue() + sio.close() - assert c.kiwi_yml == yml_string + assert c.kiwi_yml == yml_string -######### -# VERSION -######### +class TestVersion: + def test_valid(self): + c = KiwiConfig(version="0.0.0") + assert c.version == "0.0.0" -def test_version_valid(): - c = KiwiConfig(version="0.0.0") + c = KiwiConfig(version="0.0") + assert c.version == "0.0" - assert c.version == "0.0.0" + c = KiwiConfig(version="0") + assert c.version == "0" - c = KiwiConfig(version="0.0") + c = KiwiConfig(version=1.0) + assert c.version == "1.0" - assert c.version == "0.0" + c = KiwiConfig(version=1) + assert c.version == "1" - c = KiwiConfig(version="0") + def test_invalid(self): + # definitely not a version + with pytest.raises(ValidationError) as exc_info: + KiwiConfig(version="dnaf") - assert c.version == "0" + assert len(exc_info.value.errors()) == 1 + error = exc_info.value.errors()[0] + assert error["msg"].find("string does not match regex") != -1 + assert error["type"] == "value_error.str.regex" - c = KiwiConfig(version=1.0) + # almost a version + with pytest.raises(ValidationError) as exc_info: + c = KiwiConfig(version="0.0.0alpha") + print(c.version) - assert c.version == "1.0" + assert len(exc_info.value.errors()) == 1 + error = exc_info.value.errors()[0] + assert error["msg"].find("string does not match regex") != -1 + assert error["type"] == "value_error.str.regex" - c = KiwiConfig(version=1) - assert c.version == "1" +class TestShells: + def test_empty(self): + c = KiwiConfig(shells=None) + assert c == KiwiConfig(shells=[]) -def test_version_invalid(): - # definitely not a version - with pytest.raises(ValidationError) as exc_info: - KiwiConfig(version="dnaf") + assert c.shells == [] - assert len(exc_info.value.errors()) == 1 - error = exc_info.value.errors()[0] - assert error["msg"].find("string does not match regex") != -1 - assert error["type"] == "value_error.str.regex" + def test_list(self): + c = KiwiConfig(shells=["/bin/sh", "sh"]) - # barely a version - with pytest.raises(ValidationError) as exc_info: - c = KiwiConfig(version="0.0.0alpha") - print(c.version) + assert len(c.shells) == 2 + assert c.shells[0] == Path("/bin/sh") + assert c.shells[1] == Path("sh") - assert len(exc_info.value.errors()) == 1 - error = exc_info.value.errors()[0] - assert error["msg"].find("string does not match regex") != -1 - assert error["type"] == "value_error.str.regex" + c = KiwiConfig(shells=["/bin/bash"]) + + assert len(c.shells) == 1 + assert c.shells[0] == Path("/bin/bash") + def test_dict(self): + c = KiwiConfig(shells={"/bin/bash": None}) -######## -# SHELLS -######## + assert len(c.shells) == 1 + assert c.shells[0] == Path("/bin/bash") + + def test_coercible(self): + c = KiwiConfig(shells="/bin/bash") + + assert c == KiwiConfig(shells=Path("/bin/bash")) + + assert len(c.shells) == 1 + assert c.shells[0] == Path("/bin/bash") + + c = KiwiConfig(shells=123) + + assert len(c.shells) == 1 + assert c.shells[0] == Path("123") -def test_shells_empty(): - c = KiwiConfig(shells=None) + def test_uncoercible(self): + with pytest.raises(ValidationError) as exc_info: + KiwiConfig(shells=UnCoercible()) - assert c == KiwiConfig(shells=[]) + assert len(exc_info.value.errors()) == 1 + error = exc_info.value.errors()[0] + assert error["msg"] == "Invalid Shells Format" + assert error["type"] == "value_error" - assert c.shells == [] + with pytest.raises(ValidationError) as exc_info: + KiwiConfig(shells=["/bin/bash", UnCoercible()]) + assert len(exc_info.value.errors()) == 1 + error = exc_info.value.errors()[0] + assert error["msg"] == "value is not a valid path" + assert error["type"] == "type_error.path" -def test_shells_list(): - c = KiwiConfig(shells=["/bin/sh", "sh"]) - assert len(c.shells) == 2 - assert c.shells[0] == Path("/bin/sh") - assert c.shells[1] == Path("sh") +class TestProject: + def test_empty(self): + c = KiwiConfig(projects=None) - c = KiwiConfig(shells=["/bin/bash"]) + assert c == KiwiConfig(projects=[]) + + assert c.projects == [] - assert len(c.shells) == 1 - assert c.shells[0] == Path("/bin/bash") + def test_long(self): + kiwi_dict = { + "name": "project", + "enabled": False, + "override_storage": {"directory": "/test/directory"}, + } + c = KiwiConfig(projects=[kiwi_dict]) + + assert len(c.projects) == 1 + p = c.projects[0] + assert p.name == "project" + assert not p.enabled + assert p.override_storage is not None + + assert c.kiwi_dict["projects"][0] == kiwi_dict + + def test_storage_str(self): + kiwi_dict = { + "name": "project", + "enabled": False, + "override_storage": "/test/directory", + } + c = KiwiConfig(projects=[kiwi_dict]) + assert len(c.projects) == 1 + p = c.projects[0] + assert p.name == "project" + assert not p.enabled + assert p.override_storage is not None -def test_shells_dict(): - c = KiwiConfig(shells={"/bin/bash": None}) + def test_storage_list(self): + kiwi_dict = { + "name": "project", + "enabled": False, + "override_storage": ["/test/directory"], + } + c = KiwiConfig(projects=[kiwi_dict]) - assert len(c.shells) == 1 - assert c.shells[0] == Path("/bin/bash") + assert len(c.projects) == 1 + p = c.projects[0] + assert p.name == "project" + assert not p.enabled + assert p.override_storage is not None + def test_storage_invalid(self): + kiwi_dict = { + "name": "project", + "enabled": False, + "override_storage": True, + } + with pytest.raises(ValidationError) as exc_info: + KiwiConfig(projects=[kiwi_dict]) -def test_shells_coercible(): - c = KiwiConfig(shells="/bin/bash") + assert len(exc_info.value.errors()) == 1 + error = exc_info.value.errors()[0] + assert error["msg"] == "Invalid Storage Format" + assert error["type"] == "value_error" - assert c == KiwiConfig(shells=Path("/bin/bash")) + def test_short(self): + kiwi_dict = { + "project": False, + } + c = KiwiConfig(projects=[kiwi_dict]) - assert len(c.shells) == 1 - assert c.shells[0] == Path("/bin/bash") + assert len(c.projects) == 1 + p = c.projects[0] + assert p.name == "project" + assert not p.enabled + assert p.override_storage is None + assert p.kiwi_dict == kiwi_dict + + def test_dict(self): + c = KiwiConfig(projects={"name": "project"}) + + assert c == KiwiConfig(projects=[{"name": "project"}]) + + assert len(c.projects) == 1 + p = c.projects[0] + assert p.name == "project" + assert p.enabled + assert p.override_storage is None + + def test_invalid_dict(self): + with pytest.raises(ValidationError) as exc_info: + KiwiConfig(projects={ + "random key 1": "random value 1", + "random key 2": "random value 2", + }) + + assert len(exc_info.value.errors()) == 1 + error = exc_info.value.errors()[0] + assert error["msg"] == "Invalid Project Format" + assert error["type"] == "value_error" + + def test_coercible(self): + c = KiwiConfig(projects="project") + + assert c == KiwiConfig(projects=["project"]) + + assert len(c.projects) == 1 + p = c.projects[0] + assert p.name == "project" + assert p.enabled + assert p.override_storage is None + + def test_uncoercible(self): + with pytest.raises(ValidationError) as exc_info: + KiwiConfig(projects=["valid", UnCoercible()]) + + assert len(exc_info.value.errors()) == 1 + error = exc_info.value.errors()[0] + assert error["msg"] == "Invalid Projects Format" + assert error["type"] == "value_error" - c = KiwiConfig(shells=123) + with pytest.raises(ValidationError) as exc_info: + KiwiConfig(projects=UnCoercible()) + + assert len(exc_info.value.errors()) == 1 + error = exc_info.value.errors()[0] + assert error["msg"] == "Invalid Projects Format" + assert error["type"] == "value_error" - assert len(c.shells) == 1 - assert c.shells[0] == Path("123") +class TestEnvironment: + def test_empty(self): + c = KiwiConfig(environment=None) -def test_shells_uncoercible(): - with pytest.raises(ValidationError) as exc_info: - KiwiConfig(shells=UnCoercible()) + assert c.environment == {} - assert len(exc_info.value.errors()) == 1 - error = exc_info.value.errors()[0] - assert error["msg"] == "Invalid Shells Format" - assert error["type"] == "value_error" + def test_dict(self): + c = KiwiConfig(environment={}) - with pytest.raises(ValidationError) as exc_info: - KiwiConfig(shells=["/bin/bash", UnCoercible()]) + assert c.environment == {} - assert len(exc_info.value.errors()) == 1 - error = exc_info.value.errors()[0] - assert error["msg"] == "value is not a valid path" - assert error["type"] == "type_error.path" + kiwi_dict = {"variable": "value"} + c = KiwiConfig(environment=kiwi_dict) + assert len(c.environment) == 1 + assert "variable" in c.environment + assert c.environment["variable"] == "value" -########## -# PROJECTS -########## + assert c.kiwi_dict["environment"] == kiwi_dict -def test_proj_empty(): - c = KiwiConfig(projects=None) + def test_list(self): + c = KiwiConfig(environment=[]) - assert c == KiwiConfig(projects=[]) + assert c.environment == {} - assert c.projects == [] + c = KiwiConfig(environment=[ + "variable=value", + ]) + assert len(c.environment) == 1 + assert "variable" in c.environment + assert c.environment["variable"] == "value" -def test_proj_long(): - kiwi_dict = { - "name": "project", - "enabled": False, - "override_storage": {"directory": "/test/directory"}, - } - c = KiwiConfig(projects=[kiwi_dict]) + c = KiwiConfig(environment=[ + "variable", + ]) - assert len(c.projects) == 1 - p = c.projects[0] - assert p.name == "project" - assert not p.enabled - assert p.override_storage is not None + assert len(c.environment) == 1 + assert "variable" in c.environment + assert c.environment["variable"] is None - assert c.kiwi_dict["projects"][0] == kiwi_dict + c = KiwiConfig(environment=[ + 123, + ]) + assert len(c.environment) == 1 + assert "123" in c.environment + assert c.environment["123"] is None -def test_proj_storage_str(): - kiwi_dict = { - "name": "project", - "enabled": False, - "override_storage": "/test/directory", - } - c = KiwiConfig(projects=[kiwi_dict]) + def test_coercible(self): + c = KiwiConfig(environment="variable=value") - assert len(c.projects) == 1 - p = c.projects[0] - assert p.name == "project" - assert not p.enabled - assert p.override_storage is not None + assert len(c.environment) == 1 + assert "variable" in c.environment + assert c.environment["variable"] == "value" + c = KiwiConfig(environment="variable") -def test_proj_storage_list(): - kiwi_dict = { - "name": "project", - "enabled": False, - "override_storage": ["/test/directory"], - } - c = KiwiConfig(projects=[kiwi_dict]) + assert len(c.environment) == 1 + assert "variable" in c.environment + assert c.environment["variable"] is None - assert len(c.projects) == 1 - p = c.projects[0] - assert p.name == "project" - assert not p.enabled - assert p.override_storage is not None + c = KiwiConfig(environment=123) + assert len(c.environment) == 1 + assert "123" in c.environment + assert c.environment["123"] is None -def test_proj_storage_invalid(): - kiwi_dict = { - "name": "project", - "enabled": False, - "override_storage": True, - } - with pytest.raises(ValidationError) as exc_info: - KiwiConfig(projects=[kiwi_dict]) + c = KiwiConfig(environment=123.4) - assert len(exc_info.value.errors()) == 1 - error = exc_info.value.errors()[0] - assert error["msg"] == "Invalid Storage Format" - assert error["type"] == "value_error" + assert len(c.environment) == 1 + assert "123.4" in c.environment + assert c.environment["123.4"] is None + def test_uncoercible(self): + with pytest.raises(ValidationError) as exc_info: + KiwiConfig(environment=UnCoercible()) -def test_proj_short(): - kiwi_dict = { - "project": False, - } - c = KiwiConfig(projects=[kiwi_dict]) + assert len(exc_info.value.errors()) == 1 + error = exc_info.value.errors()[0] + assert error["msg"] == "Invalid Environment Format" + assert error["type"] == "value_error" - assert len(c.projects) == 1 - p = c.projects[0] - assert p.name == "project" - assert not p.enabled - assert p.override_storage is None - assert p.kiwi_dict == kiwi_dict + with pytest.raises(ValidationError) as exc_info: + KiwiConfig(environment=["valid", UnCoercible()]) + assert len(exc_info.value.errors()) == 1 + error = exc_info.value.errors()[0] + assert error["msg"] == "Invalid Environment Format" + assert error["type"] == "value_error" -def test_proj_dict(): - c = KiwiConfig(projects={"name": "project"}) - assert c == KiwiConfig(projects=[{"name": "project"}]) +class TestStorage: + def test_empty(self): + with pytest.raises(ValidationError) as exc_info: + KiwiConfig(storage=None) - assert len(c.projects) == 1 - p = c.projects[0] - assert p.name == "project" - assert p.enabled - assert p.override_storage is None + assert len(exc_info.value.errors()) == 1 + error = exc_info.value.errors()[0] + assert error["msg"] == "No Storage Given" + assert error["type"] == "value_error" + def test_dict(self): + kiwi_dict = {"directory": "/test/directory"} + c = KiwiConfig(storage=kiwi_dict) -def test_proj_invalid_dict(): - with pytest.raises(ValidationError) as exc_info: - KiwiConfig(projects={ - "random key 1": "random value 1", - "random key 2": "random value 2", - }) + assert c.storage.directory == Path("/test/directory") + assert c.storage.kiwi_dict == kiwi_dict - assert len(exc_info.value.errors()) == 1 - error = exc_info.value.errors()[0] - assert error["msg"] == "Invalid Project Format" - assert error["type"] == "value_error" + def test_invalid_dict(self): + with pytest.raises(ValidationError) as exc_info: + KiwiConfig(storage={"random key": "random value"}) + assert len(exc_info.value.errors()) == 1 + error = exc_info.value.errors()[0] + assert error["msg"] == "Invalid Storage Format" + assert error["type"] == "value_error" -def test_proj_coercible(): - c = KiwiConfig(projects="project") + def test_str(self): + c = KiwiConfig(storage="/test/directory") - assert c == KiwiConfig(projects=["project"]) + assert c.storage.directory == Path("/test/directory") - assert len(c.projects) == 1 - p = c.projects[0] - assert p.name == "project" - assert p.enabled - assert p.override_storage is None + def test_list(self): + c = KiwiConfig(storage=["/test/directory"]) + assert c.storage.directory == Path("/test/directory") -def test_proj_uncoercible(): - with pytest.raises(ValidationError) as exc_info: - KiwiConfig(projects=["valid", UnCoercible()]) + def test_invalid(self): + with pytest.raises(ValidationError) as exc_info: + KiwiConfig(storage=True) - assert len(exc_info.value.errors()) == 1 - error = exc_info.value.errors()[0] - assert error["msg"] == "Invalid Projects Format" - assert error["type"] == "value_error" + assert len(exc_info.value.errors()) == 1 + error = exc_info.value.errors()[0] + assert error["msg"] == "Invalid Storage Format" + assert error["type"] == "value_error" - with pytest.raises(ValidationError) as exc_info: - KiwiConfig(projects=UnCoercible()) - assert len(exc_info.value.errors()) == 1 - error = exc_info.value.errors()[0] - assert error["msg"] == "Invalid Projects Format" - assert error["type"] == "value_error" +class TestNetwork: + def test_empty(self): + with pytest.raises(ValidationError) as exc_info: + KiwiConfig(network=None) + assert len(exc_info.value.errors()) == 1 + error = exc_info.value.errors()[0] + assert error["msg"] == "No Network Given" + assert error["type"] == "value_error" -############# -# ENVIRONMENT -############# - -def test_env_empty(): - c = KiwiConfig(environment=None) - - assert c.environment == {} - - -def test_env_dict(): - c = KiwiConfig(environment={}) - - assert c.environment == {} - - kiwi_dict = {"variable": "value"} - c = KiwiConfig(environment=kiwi_dict) - - assert len(c.environment) == 1 - assert "variable" in c.environment - assert c.environment["variable"] == "value" - - assert c.kiwi_dict["environment"] == kiwi_dict - - -def test_env_list(): - c = KiwiConfig(environment=[]) - - assert c.environment == {} - - c = KiwiConfig(environment=[ - "variable=value", - ]) - - assert len(c.environment) == 1 - assert "variable" in c.environment - assert c.environment["variable"] == "value" - - c = KiwiConfig(environment=[ - "variable", - ]) - - assert len(c.environment) == 1 - assert "variable" in c.environment - assert c.environment["variable"] is None - - c = KiwiConfig(environment=[ - 123, - ]) - - assert len(c.environment) == 1 - assert "123" in c.environment - assert c.environment["123"] is None - - -def test_env_coercible(): - c = KiwiConfig(environment="variable=value") - - assert len(c.environment) == 1 - assert "variable" in c.environment - assert c.environment["variable"] == "value" - - c = KiwiConfig(environment="variable") - - assert len(c.environment) == 1 - assert "variable" in c.environment - assert c.environment["variable"] is None - - c = KiwiConfig(environment=123) - - assert len(c.environment) == 1 - assert "123" in c.environment - assert c.environment["123"] is None - - c = KiwiConfig(environment=123.4) - - assert len(c.environment) == 1 - assert "123.4" in c.environment - assert c.environment["123.4"] is None - - -def test_env_uncoercible(): - with pytest.raises(ValidationError) as exc_info: - KiwiConfig(environment=UnCoercible()) - - assert len(exc_info.value.errors()) == 1 - error = exc_info.value.errors()[0] - assert error["msg"] == "Invalid Environment Format" - assert error["type"] == "value_error" - - with pytest.raises(ValidationError) as exc_info: - KiwiConfig(environment=["valid", UnCoercible()]) - - assert len(exc_info.value.errors()) == 1 - error = exc_info.value.errors()[0] - assert error["msg"] == "Invalid Environment Format" - assert error["type"] == "value_error" - - -######### -# STORAGE -######### - -def test_storage_empty(): - with pytest.raises(ValidationError) as exc_info: - KiwiConfig(storage=None) - - assert len(exc_info.value.errors()) == 1 - error = exc_info.value.errors()[0] - assert error["msg"] == "No Storage Given" - assert error["type"] == "value_error" - - -def test_storage_dict(): - kiwi_dict = {"directory": "/test/directory"} - c = KiwiConfig(storage=kiwi_dict) - - assert c.storage.directory == Path("/test/directory") - assert c.storage.kiwi_dict == kiwi_dict - - -def test_storage_invalid_dict(): - with pytest.raises(ValidationError) as exc_info: - KiwiConfig(storage={"random key": "random value"}) - - assert len(exc_info.value.errors()) == 1 - error = exc_info.value.errors()[0] - assert error["msg"] == "Invalid Storage Format" - assert error["type"] == "value_error" - - -def test_storage_str(): - c = KiwiConfig(storage="/test/directory") - - assert c.storage.directory == Path("/test/directory") - - -def test_storage_list(): - c = KiwiConfig(storage=["/test/directory"]) - - assert c.storage.directory == Path("/test/directory") - - -def test_storage_invalid(): - with pytest.raises(ValidationError) as exc_info: - KiwiConfig(storage=True) - - assert len(exc_info.value.errors()) == 1 - error = exc_info.value.errors()[0] - assert error["msg"] == "Invalid Storage Format" - assert error["type"] == "value_error" - - -######### -# NETWORK -######### - -def test_network_empty(): - with pytest.raises(ValidationError) as exc_info: - KiwiConfig(network=None) - - assert len(exc_info.value.errors()) == 1 - error = exc_info.value.errors()[0] - assert error["msg"] == "No Network Given" - assert error["type"] == "value_error" - - -def test_network_dict(): - kiwi_dict = { - "name": "test_hub", - "cidr": "1.2.3.4/32", - } - c = KiwiConfig(network=kiwi_dict) - - assert c == KiwiConfig(network={ - "name": "TEST_HUB", - "cidr": "1.2.3.4/32", - }) - - assert c.network.name == "test_hub" - assert c.network.cidr == IPv4Network("1.2.3.4/32") - assert c.network.kiwi_dict == kiwi_dict - - -def test_network_invalid_dict(): - with pytest.raises(ValidationError) as exc_info: - KiwiConfig(network={"name": "test_hub"}) - - assert len(exc_info.value.errors()) == 1 - error = exc_info.value.errors()[0] - assert error["msg"] == "field required" - assert error["type"] == "value_error.missing" - - with pytest.raises(ValidationError) as exc_info: - KiwiConfig(network={ + def test_dict(self): + kiwi_dict = { "name": "test_hub", - "cidr": "1.2.3.4/123", + "cidr": "1.2.3.4/32", + } + c = KiwiConfig(network=kiwi_dict) + + assert c == KiwiConfig(network={ + "name": "TEST_HUB", + "cidr": "1.2.3.4/32", }) - assert len(exc_info.value.errors()) == 1 - error = exc_info.value.errors()[0] - assert error["msg"] == "value is not a valid IPv4 network" - assert error["type"] == "value_error.ipv4network" + assert c.network.name == "test_hub" + assert c.network.cidr == IPv4Network("1.2.3.4/32") + assert c.network.kiwi_dict == kiwi_dict + def test_invalid_dict(self): + with pytest.raises(ValidationError) as exc_info: + KiwiConfig(network={"name": "test_hub"}) -def test_network_invalid(): - with pytest.raises(ValidationError) as exc_info: - KiwiConfig(network=True) + assert len(exc_info.value.errors()) == 1 + error = exc_info.value.errors()[0] + assert error["msg"] == "field required" + assert error["type"] == "value_error.missing" - assert len(exc_info.value.errors()) == 1 - error = exc_info.value.errors()[0] - assert error["msg"] == "Invalid Network Format" - assert error["type"] == "value_error" + with pytest.raises(ValidationError) as exc_info: + KiwiConfig(network={ + "name": "test_hub", + "cidr": "1.2.3.4/123", + }) + + assert len(exc_info.value.errors()) == 1 + error = exc_info.value.errors()[0] + assert error["msg"] == "value is not a valid IPv4 network" + assert error["type"] == "value_error.ipv4network" + + def test_invalid(self): + with pytest.raises(ValidationError) as exc_info: + KiwiConfig(network=True) + + assert len(exc_info.value.errors()) == 1 + error = exc_info.value.errors()[0] + assert error["msg"] == "Invalid Network Format" + assert error["type"] == "value_error" diff --git a/tests/test_instance.py b/tests/test_instance.py index d008748..68f4280 100644 --- a/tests/test_instance.py +++ b/tests/test_instance.py @@ -3,28 +3,27 @@ from pathlib import Path from kiwi_scp.instance import Instance -def test_example(): - i = Instance(Path("example")) +class TestDefault: + def test_example(self): + i = Instance(Path("example")) - assert i.config is not None - assert len(i.config.projects) == 1 + assert i.config is not None + assert len(i.config.projects) == 1 - p = i.config.projects[0] + p = i.config.projects[0] - assert p.name == "hello-world.project" + assert p.name == "hello-world.project" + def test_empty(self): + i = Instance() -def test_empty(): - i = Instance() + assert i.config is not None + assert len(i.config.projects) == 0 - assert i.config is not None - assert len(i.config.projects) == 0 + def test_no_such_dir(self): + nonexistent_path = Path("nonexistent") + i = Instance(nonexistent_path) - -def test_no_such_dir(): - nonexistent_path = Path("nonexistent") - i = Instance(nonexistent_path) - - assert i.directory == nonexistent_path - assert i.config is not None - assert len(i.config.projects) == 0 + assert i.directory == nonexistent_path + assert i.config is not None + assert len(i.config.projects) == 0 diff --git a/tests/test_service.py b/tests/test_service.py index b44bba8..d0198a7 100644 --- a/tests/test_service.py +++ b/tests/test_service.py @@ -3,60 +3,58 @@ from pathlib import Path from kiwi_scp.instance import Service -def test_no_description(): - s = Service.from_description( - name="s", - description={}, - ) +class TestDefault: + def test_no_description(self): + s = Service.from_description( + name="s", + description={}, + ) - assert s.name == "s" - assert s.configs == [] + assert s.name == "s" + assert s.configs == [] + def test_no_configs(self): + s = Service.from_description( + name="s", + description={ + "image": "repo/image:tag", + }, + ) -def test_no_configs(): - s = Service.from_description( - name="s", - description={ - "image": "repo/image:tag", - }, - ) + assert s.name == "s" + assert s.configs == [] - assert s.name == "s" - assert s.configs == [] + def test_no_configs_in_volumes(self): + s = Service.from_description( + name="s", + description={ + "image": "repo/image:tag", + "volumes": [ + "docker_volume/third/dir:/path/to/third/mountpoint", + "${TARGETDIR}/some/dir:/path/to/some/mountpoint", + "$TARGETDIR/other/dir:/path/to/other/mountpoint", + ] + }, + ) + assert s.name == "s" + assert s.configs == [] -def test_no_configs_in_volumes(): - s = Service.from_description( - name="s", - description={ - "image": "repo/image:tag", - "volumes": [ - "docker_volume/third/dir:/path/to/third/mountpoint", - "${TARGETDIR}/some/dir:/path/to/some/mountpoint", - "$TARGETDIR/other/dir:/path/to/other/mountpoint", - ] - }, - ) + def test_with_configs(self): + s = Service.from_description( + name="s", + description={ + "image": "repo/image:tag", + "volumes": [ + "${CONFDIR}/some/config:/path/to/some/config", + "$CONFDIR/other/config:/path/to/other/config", + ] + }, + ) - assert s.name == "s" - assert s.configs == [] - - -def test_with_configs(): - s = Service.from_description( - name="s", - description={ - "image": "repo/image:tag", - "volumes": [ - "${CONFDIR}/some/config:/path/to/some/config", - "$CONFDIR/other/config:/path/to/other/config", - ] - }, - ) - - assert s.name == "s" - assert len(s.configs) == 2 - assert s.configs == [ - Path("some/config"), - Path("other/config"), - ] + assert s.name == "s" + assert len(s.configs) == 2 + assert s.configs == [ + Path("some/config"), + Path("other/config"), + ]