mirror of
https://github.com/yavook/kiwi-scp.git
synced 2024-11-22 04:43:00 +00:00
Test classes
This commit is contained in:
parent
0ecee93241
commit
8d2c1e1fac
3 changed files with 431 additions and 482 deletions
|
@ -16,7 +16,8 @@ class UnCoercible:
|
||||||
raise ValueError
|
raise ValueError
|
||||||
|
|
||||||
|
|
||||||
def test_default():
|
class TestDefault:
|
||||||
|
def test(self):
|
||||||
import toml
|
import toml
|
||||||
|
|
||||||
c = KiwiConfig()
|
c = KiwiConfig()
|
||||||
|
@ -56,33 +57,24 @@ def test_default():
|
||||||
assert c.kiwi_yml == yml_string
|
assert c.kiwi_yml == yml_string
|
||||||
|
|
||||||
|
|
||||||
#########
|
class TestVersion:
|
||||||
# VERSION
|
def test_valid(self):
|
||||||
#########
|
|
||||||
|
|
||||||
def test_version_valid():
|
|
||||||
c = KiwiConfig(version="0.0.0")
|
c = KiwiConfig(version="0.0.0")
|
||||||
|
|
||||||
assert c.version == "0.0.0"
|
assert c.version == "0.0.0"
|
||||||
|
|
||||||
c = KiwiConfig(version="0.0")
|
c = KiwiConfig(version="0.0")
|
||||||
|
|
||||||
assert c.version == "0.0"
|
assert c.version == "0.0"
|
||||||
|
|
||||||
c = KiwiConfig(version="0")
|
c = KiwiConfig(version="0")
|
||||||
|
|
||||||
assert c.version == "0"
|
assert c.version == "0"
|
||||||
|
|
||||||
c = KiwiConfig(version=1.0)
|
c = KiwiConfig(version=1.0)
|
||||||
|
|
||||||
assert c.version == "1.0"
|
assert c.version == "1.0"
|
||||||
|
|
||||||
c = KiwiConfig(version=1)
|
c = KiwiConfig(version=1)
|
||||||
|
|
||||||
assert c.version == "1"
|
assert c.version == "1"
|
||||||
|
|
||||||
|
def test_invalid(self):
|
||||||
def test_version_invalid():
|
|
||||||
# definitely not a version
|
# definitely not a version
|
||||||
with pytest.raises(ValidationError) as exc_info:
|
with pytest.raises(ValidationError) as exc_info:
|
||||||
KiwiConfig(version="dnaf")
|
KiwiConfig(version="dnaf")
|
||||||
|
@ -92,7 +84,7 @@ def test_version_invalid():
|
||||||
assert error["msg"].find("string does not match regex") != -1
|
assert error["msg"].find("string does not match regex") != -1
|
||||||
assert error["type"] == "value_error.str.regex"
|
assert error["type"] == "value_error.str.regex"
|
||||||
|
|
||||||
# barely a version
|
# almost a version
|
||||||
with pytest.raises(ValidationError) as exc_info:
|
with pytest.raises(ValidationError) as exc_info:
|
||||||
c = KiwiConfig(version="0.0.0alpha")
|
c = KiwiConfig(version="0.0.0alpha")
|
||||||
print(c.version)
|
print(c.version)
|
||||||
|
@ -103,19 +95,15 @@ def test_version_invalid():
|
||||||
assert error["type"] == "value_error.str.regex"
|
assert error["type"] == "value_error.str.regex"
|
||||||
|
|
||||||
|
|
||||||
########
|
class TestShells:
|
||||||
# SHELLS
|
def test_empty(self):
|
||||||
########
|
|
||||||
|
|
||||||
def test_shells_empty():
|
|
||||||
c = KiwiConfig(shells=None)
|
c = KiwiConfig(shells=None)
|
||||||
|
|
||||||
assert c == KiwiConfig(shells=[])
|
assert c == KiwiConfig(shells=[])
|
||||||
|
|
||||||
assert c.shells == []
|
assert c.shells == []
|
||||||
|
|
||||||
|
def test_list(self):
|
||||||
def test_shells_list():
|
|
||||||
c = KiwiConfig(shells=["/bin/sh", "sh"])
|
c = KiwiConfig(shells=["/bin/sh", "sh"])
|
||||||
|
|
||||||
assert len(c.shells) == 2
|
assert len(c.shells) == 2
|
||||||
|
@ -127,15 +115,13 @@ def test_shells_list():
|
||||||
assert len(c.shells) == 1
|
assert len(c.shells) == 1
|
||||||
assert c.shells[0] == Path("/bin/bash")
|
assert c.shells[0] == Path("/bin/bash")
|
||||||
|
|
||||||
|
def test_dict(self):
|
||||||
def test_shells_dict():
|
|
||||||
c = KiwiConfig(shells={"/bin/bash": None})
|
c = KiwiConfig(shells={"/bin/bash": None})
|
||||||
|
|
||||||
assert len(c.shells) == 1
|
assert len(c.shells) == 1
|
||||||
assert c.shells[0] == Path("/bin/bash")
|
assert c.shells[0] == Path("/bin/bash")
|
||||||
|
|
||||||
|
def test_coercible(self):
|
||||||
def test_shells_coercible():
|
|
||||||
c = KiwiConfig(shells="/bin/bash")
|
c = KiwiConfig(shells="/bin/bash")
|
||||||
|
|
||||||
assert c == KiwiConfig(shells=Path("/bin/bash"))
|
assert c == KiwiConfig(shells=Path("/bin/bash"))
|
||||||
|
@ -148,8 +134,7 @@ def test_shells_coercible():
|
||||||
assert len(c.shells) == 1
|
assert len(c.shells) == 1
|
||||||
assert c.shells[0] == Path("123")
|
assert c.shells[0] == Path("123")
|
||||||
|
|
||||||
|
def test_uncoercible(self):
|
||||||
def test_shells_uncoercible():
|
|
||||||
with pytest.raises(ValidationError) as exc_info:
|
with pytest.raises(ValidationError) as exc_info:
|
||||||
KiwiConfig(shells=UnCoercible())
|
KiwiConfig(shells=UnCoercible())
|
||||||
|
|
||||||
|
@ -167,19 +152,15 @@ def test_shells_uncoercible():
|
||||||
assert error["type"] == "type_error.path"
|
assert error["type"] == "type_error.path"
|
||||||
|
|
||||||
|
|
||||||
##########
|
class TestProject:
|
||||||
# PROJECTS
|
def test_empty(self):
|
||||||
##########
|
|
||||||
|
|
||||||
def test_proj_empty():
|
|
||||||
c = KiwiConfig(projects=None)
|
c = KiwiConfig(projects=None)
|
||||||
|
|
||||||
assert c == KiwiConfig(projects=[])
|
assert c == KiwiConfig(projects=[])
|
||||||
|
|
||||||
assert c.projects == []
|
assert c.projects == []
|
||||||
|
|
||||||
|
def test_long(self):
|
||||||
def test_proj_long():
|
|
||||||
kiwi_dict = {
|
kiwi_dict = {
|
||||||
"name": "project",
|
"name": "project",
|
||||||
"enabled": False,
|
"enabled": False,
|
||||||
|
@ -195,8 +176,7 @@ def test_proj_long():
|
||||||
|
|
||||||
assert c.kiwi_dict["projects"][0] == kiwi_dict
|
assert c.kiwi_dict["projects"][0] == kiwi_dict
|
||||||
|
|
||||||
|
def test_storage_str(self):
|
||||||
def test_proj_storage_str():
|
|
||||||
kiwi_dict = {
|
kiwi_dict = {
|
||||||
"name": "project",
|
"name": "project",
|
||||||
"enabled": False,
|
"enabled": False,
|
||||||
|
@ -210,8 +190,7 @@ def test_proj_storage_str():
|
||||||
assert not p.enabled
|
assert not p.enabled
|
||||||
assert p.override_storage is not None
|
assert p.override_storage is not None
|
||||||
|
|
||||||
|
def test_storage_list(self):
|
||||||
def test_proj_storage_list():
|
|
||||||
kiwi_dict = {
|
kiwi_dict = {
|
||||||
"name": "project",
|
"name": "project",
|
||||||
"enabled": False,
|
"enabled": False,
|
||||||
|
@ -225,8 +204,7 @@ def test_proj_storage_list():
|
||||||
assert not p.enabled
|
assert not p.enabled
|
||||||
assert p.override_storage is not None
|
assert p.override_storage is not None
|
||||||
|
|
||||||
|
def test_storage_invalid(self):
|
||||||
def test_proj_storage_invalid():
|
|
||||||
kiwi_dict = {
|
kiwi_dict = {
|
||||||
"name": "project",
|
"name": "project",
|
||||||
"enabled": False,
|
"enabled": False,
|
||||||
|
@ -240,8 +218,7 @@ def test_proj_storage_invalid():
|
||||||
assert error["msg"] == "Invalid Storage Format"
|
assert error["msg"] == "Invalid Storage Format"
|
||||||
assert error["type"] == "value_error"
|
assert error["type"] == "value_error"
|
||||||
|
|
||||||
|
def test_short(self):
|
||||||
def test_proj_short():
|
|
||||||
kiwi_dict = {
|
kiwi_dict = {
|
||||||
"project": False,
|
"project": False,
|
||||||
}
|
}
|
||||||
|
@ -254,8 +231,7 @@ def test_proj_short():
|
||||||
assert p.override_storage is None
|
assert p.override_storage is None
|
||||||
assert p.kiwi_dict == kiwi_dict
|
assert p.kiwi_dict == kiwi_dict
|
||||||
|
|
||||||
|
def test_dict(self):
|
||||||
def test_proj_dict():
|
|
||||||
c = KiwiConfig(projects={"name": "project"})
|
c = KiwiConfig(projects={"name": "project"})
|
||||||
|
|
||||||
assert c == KiwiConfig(projects=[{"name": "project"}])
|
assert c == KiwiConfig(projects=[{"name": "project"}])
|
||||||
|
@ -266,8 +242,7 @@ def test_proj_dict():
|
||||||
assert p.enabled
|
assert p.enabled
|
||||||
assert p.override_storage is None
|
assert p.override_storage is None
|
||||||
|
|
||||||
|
def test_invalid_dict(self):
|
||||||
def test_proj_invalid_dict():
|
|
||||||
with pytest.raises(ValidationError) as exc_info:
|
with pytest.raises(ValidationError) as exc_info:
|
||||||
KiwiConfig(projects={
|
KiwiConfig(projects={
|
||||||
"random key 1": "random value 1",
|
"random key 1": "random value 1",
|
||||||
|
@ -279,8 +254,7 @@ def test_proj_invalid_dict():
|
||||||
assert error["msg"] == "Invalid Project Format"
|
assert error["msg"] == "Invalid Project Format"
|
||||||
assert error["type"] == "value_error"
|
assert error["type"] == "value_error"
|
||||||
|
|
||||||
|
def test_coercible(self):
|
||||||
def test_proj_coercible():
|
|
||||||
c = KiwiConfig(projects="project")
|
c = KiwiConfig(projects="project")
|
||||||
|
|
||||||
assert c == KiwiConfig(projects=["project"])
|
assert c == KiwiConfig(projects=["project"])
|
||||||
|
@ -291,8 +265,7 @@ def test_proj_coercible():
|
||||||
assert p.enabled
|
assert p.enabled
|
||||||
assert p.override_storage is None
|
assert p.override_storage is None
|
||||||
|
|
||||||
|
def test_uncoercible(self):
|
||||||
def test_proj_uncoercible():
|
|
||||||
with pytest.raises(ValidationError) as exc_info:
|
with pytest.raises(ValidationError) as exc_info:
|
||||||
KiwiConfig(projects=["valid", UnCoercible()])
|
KiwiConfig(projects=["valid", UnCoercible()])
|
||||||
|
|
||||||
|
@ -310,17 +283,13 @@ def test_proj_uncoercible():
|
||||||
assert error["type"] == "value_error"
|
assert error["type"] == "value_error"
|
||||||
|
|
||||||
|
|
||||||
#############
|
class TestEnvironment:
|
||||||
# ENVIRONMENT
|
def test_empty(self):
|
||||||
#############
|
|
||||||
|
|
||||||
def test_env_empty():
|
|
||||||
c = KiwiConfig(environment=None)
|
c = KiwiConfig(environment=None)
|
||||||
|
|
||||||
assert c.environment == {}
|
assert c.environment == {}
|
||||||
|
|
||||||
|
def test_dict(self):
|
||||||
def test_env_dict():
|
|
||||||
c = KiwiConfig(environment={})
|
c = KiwiConfig(environment={})
|
||||||
|
|
||||||
assert c.environment == {}
|
assert c.environment == {}
|
||||||
|
@ -334,8 +303,7 @@ def test_env_dict():
|
||||||
|
|
||||||
assert c.kiwi_dict["environment"] == kiwi_dict
|
assert c.kiwi_dict["environment"] == kiwi_dict
|
||||||
|
|
||||||
|
def test_list(self):
|
||||||
def test_env_list():
|
|
||||||
c = KiwiConfig(environment=[])
|
c = KiwiConfig(environment=[])
|
||||||
|
|
||||||
assert c.environment == {}
|
assert c.environment == {}
|
||||||
|
@ -364,8 +332,7 @@ def test_env_list():
|
||||||
assert "123" in c.environment
|
assert "123" in c.environment
|
||||||
assert c.environment["123"] is None
|
assert c.environment["123"] is None
|
||||||
|
|
||||||
|
def test_coercible(self):
|
||||||
def test_env_coercible():
|
|
||||||
c = KiwiConfig(environment="variable=value")
|
c = KiwiConfig(environment="variable=value")
|
||||||
|
|
||||||
assert len(c.environment) == 1
|
assert len(c.environment) == 1
|
||||||
|
@ -390,8 +357,7 @@ def test_env_coercible():
|
||||||
assert "123.4" in c.environment
|
assert "123.4" in c.environment
|
||||||
assert c.environment["123.4"] is None
|
assert c.environment["123.4"] is None
|
||||||
|
|
||||||
|
def test_uncoercible(self):
|
||||||
def test_env_uncoercible():
|
|
||||||
with pytest.raises(ValidationError) as exc_info:
|
with pytest.raises(ValidationError) as exc_info:
|
||||||
KiwiConfig(environment=UnCoercible())
|
KiwiConfig(environment=UnCoercible())
|
||||||
|
|
||||||
|
@ -409,11 +375,8 @@ def test_env_uncoercible():
|
||||||
assert error["type"] == "value_error"
|
assert error["type"] == "value_error"
|
||||||
|
|
||||||
|
|
||||||
#########
|
class TestStorage:
|
||||||
# STORAGE
|
def test_empty(self):
|
||||||
#########
|
|
||||||
|
|
||||||
def test_storage_empty():
|
|
||||||
with pytest.raises(ValidationError) as exc_info:
|
with pytest.raises(ValidationError) as exc_info:
|
||||||
KiwiConfig(storage=None)
|
KiwiConfig(storage=None)
|
||||||
|
|
||||||
|
@ -422,16 +385,14 @@ def test_storage_empty():
|
||||||
assert error["msg"] == "No Storage Given"
|
assert error["msg"] == "No Storage Given"
|
||||||
assert error["type"] == "value_error"
|
assert error["type"] == "value_error"
|
||||||
|
|
||||||
|
def test_dict(self):
|
||||||
def test_storage_dict():
|
|
||||||
kiwi_dict = {"directory": "/test/directory"}
|
kiwi_dict = {"directory": "/test/directory"}
|
||||||
c = KiwiConfig(storage=kiwi_dict)
|
c = KiwiConfig(storage=kiwi_dict)
|
||||||
|
|
||||||
assert c.storage.directory == Path("/test/directory")
|
assert c.storage.directory == Path("/test/directory")
|
||||||
assert c.storage.kiwi_dict == kiwi_dict
|
assert c.storage.kiwi_dict == kiwi_dict
|
||||||
|
|
||||||
|
def test_invalid_dict(self):
|
||||||
def test_storage_invalid_dict():
|
|
||||||
with pytest.raises(ValidationError) as exc_info:
|
with pytest.raises(ValidationError) as exc_info:
|
||||||
KiwiConfig(storage={"random key": "random value"})
|
KiwiConfig(storage={"random key": "random value"})
|
||||||
|
|
||||||
|
@ -440,20 +401,17 @@ def test_storage_invalid_dict():
|
||||||
assert error["msg"] == "Invalid Storage Format"
|
assert error["msg"] == "Invalid Storage Format"
|
||||||
assert error["type"] == "value_error"
|
assert error["type"] == "value_error"
|
||||||
|
|
||||||
|
def test_str(self):
|
||||||
def test_storage_str():
|
|
||||||
c = KiwiConfig(storage="/test/directory")
|
c = KiwiConfig(storage="/test/directory")
|
||||||
|
|
||||||
assert c.storage.directory == Path("/test/directory")
|
assert c.storage.directory == Path("/test/directory")
|
||||||
|
|
||||||
|
def test_list(self):
|
||||||
def test_storage_list():
|
|
||||||
c = KiwiConfig(storage=["/test/directory"])
|
c = KiwiConfig(storage=["/test/directory"])
|
||||||
|
|
||||||
assert c.storage.directory == Path("/test/directory")
|
assert c.storage.directory == Path("/test/directory")
|
||||||
|
|
||||||
|
def test_invalid(self):
|
||||||
def test_storage_invalid():
|
|
||||||
with pytest.raises(ValidationError) as exc_info:
|
with pytest.raises(ValidationError) as exc_info:
|
||||||
KiwiConfig(storage=True)
|
KiwiConfig(storage=True)
|
||||||
|
|
||||||
|
@ -463,11 +421,8 @@ def test_storage_invalid():
|
||||||
assert error["type"] == "value_error"
|
assert error["type"] == "value_error"
|
||||||
|
|
||||||
|
|
||||||
#########
|
class TestNetwork:
|
||||||
# NETWORK
|
def test_empty(self):
|
||||||
#########
|
|
||||||
|
|
||||||
def test_network_empty():
|
|
||||||
with pytest.raises(ValidationError) as exc_info:
|
with pytest.raises(ValidationError) as exc_info:
|
||||||
KiwiConfig(network=None)
|
KiwiConfig(network=None)
|
||||||
|
|
||||||
|
@ -476,8 +431,7 @@ def test_network_empty():
|
||||||
assert error["msg"] == "No Network Given"
|
assert error["msg"] == "No Network Given"
|
||||||
assert error["type"] == "value_error"
|
assert error["type"] == "value_error"
|
||||||
|
|
||||||
|
def test_dict(self):
|
||||||
def test_network_dict():
|
|
||||||
kiwi_dict = {
|
kiwi_dict = {
|
||||||
"name": "test_hub",
|
"name": "test_hub",
|
||||||
"cidr": "1.2.3.4/32",
|
"cidr": "1.2.3.4/32",
|
||||||
|
@ -493,8 +447,7 @@ def test_network_dict():
|
||||||
assert c.network.cidr == IPv4Network("1.2.3.4/32")
|
assert c.network.cidr == IPv4Network("1.2.3.4/32")
|
||||||
assert c.network.kiwi_dict == kiwi_dict
|
assert c.network.kiwi_dict == kiwi_dict
|
||||||
|
|
||||||
|
def test_invalid_dict(self):
|
||||||
def test_network_invalid_dict():
|
|
||||||
with pytest.raises(ValidationError) as exc_info:
|
with pytest.raises(ValidationError) as exc_info:
|
||||||
KiwiConfig(network={"name": "test_hub"})
|
KiwiConfig(network={"name": "test_hub"})
|
||||||
|
|
||||||
|
@ -514,8 +467,7 @@ def test_network_invalid_dict():
|
||||||
assert error["msg"] == "value is not a valid IPv4 network"
|
assert error["msg"] == "value is not a valid IPv4 network"
|
||||||
assert error["type"] == "value_error.ipv4network"
|
assert error["type"] == "value_error.ipv4network"
|
||||||
|
|
||||||
|
def test_invalid(self):
|
||||||
def test_network_invalid():
|
|
||||||
with pytest.raises(ValidationError) as exc_info:
|
with pytest.raises(ValidationError) as exc_info:
|
||||||
KiwiConfig(network=True)
|
KiwiConfig(network=True)
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,8 @@ from pathlib import Path
|
||||||
from kiwi_scp.instance import Instance
|
from kiwi_scp.instance import Instance
|
||||||
|
|
||||||
|
|
||||||
def test_example():
|
class TestDefault:
|
||||||
|
def test_example(self):
|
||||||
i = Instance(Path("example"))
|
i = Instance(Path("example"))
|
||||||
|
|
||||||
assert i.config is not None
|
assert i.config is not None
|
||||||
|
@ -13,15 +14,13 @@ def test_example():
|
||||||
|
|
||||||
assert p.name == "hello-world.project"
|
assert p.name == "hello-world.project"
|
||||||
|
|
||||||
|
def test_empty(self):
|
||||||
def test_empty():
|
|
||||||
i = Instance()
|
i = Instance()
|
||||||
|
|
||||||
assert i.config is not None
|
assert i.config is not None
|
||||||
assert len(i.config.projects) == 0
|
assert len(i.config.projects) == 0
|
||||||
|
|
||||||
|
def test_no_such_dir(self):
|
||||||
def test_no_such_dir():
|
|
||||||
nonexistent_path = Path("nonexistent")
|
nonexistent_path = Path("nonexistent")
|
||||||
i = Instance(nonexistent_path)
|
i = Instance(nonexistent_path)
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,8 @@ from pathlib import Path
|
||||||
from kiwi_scp.instance import Service
|
from kiwi_scp.instance import Service
|
||||||
|
|
||||||
|
|
||||||
def test_no_description():
|
class TestDefault:
|
||||||
|
def test_no_description(self):
|
||||||
s = Service.from_description(
|
s = Service.from_description(
|
||||||
name="s",
|
name="s",
|
||||||
description={},
|
description={},
|
||||||
|
@ -12,8 +13,7 @@ def test_no_description():
|
||||||
assert s.name == "s"
|
assert s.name == "s"
|
||||||
assert s.configs == []
|
assert s.configs == []
|
||||||
|
|
||||||
|
def test_no_configs(self):
|
||||||
def test_no_configs():
|
|
||||||
s = Service.from_description(
|
s = Service.from_description(
|
||||||
name="s",
|
name="s",
|
||||||
description={
|
description={
|
||||||
|
@ -24,8 +24,7 @@ def test_no_configs():
|
||||||
assert s.name == "s"
|
assert s.name == "s"
|
||||||
assert s.configs == []
|
assert s.configs == []
|
||||||
|
|
||||||
|
def test_no_configs_in_volumes(self):
|
||||||
def test_no_configs_in_volumes():
|
|
||||||
s = Service.from_description(
|
s = Service.from_description(
|
||||||
name="s",
|
name="s",
|
||||||
description={
|
description={
|
||||||
|
@ -41,8 +40,7 @@ def test_no_configs_in_volumes():
|
||||||
assert s.name == "s"
|
assert s.name == "s"
|
||||||
assert s.configs == []
|
assert s.configs == []
|
||||||
|
|
||||||
|
def test_with_configs(self):
|
||||||
def test_with_configs():
|
|
||||||
s = Service.from_description(
|
s = Service.from_description(
|
||||||
name="s",
|
name="s",
|
||||||
description={
|
description={
|
||||||
|
|
Loading…
Reference in a new issue