Page MenuHomeDevCentral

No OneTemporary

diff --git a/_tests/Makefile b/_tests/Makefile
index 66d111f..bf7df8e 100644
--- a/_tests/Makefile
+++ b/_tests/Makefile
@@ -1,25 +1,34 @@
+CURRENT_DIR != pwd
+MODULES_DIR = ${CURRENT_DIR}/../_modules
+
test: test-python test-roles test-bats
-test-python:
- python -m unittest discover modules
+test-python: test-modules test-pillar test-python-scripts
+
+test-modules:
+ PYTHONPATH="${CURRENT_DIR}:${MODULES_DIR}" python -m unittest discover modules
+
+test-pillar:
python -m unittest discover pillar
- python -m unittest discover scripts/python
+
+test-python-scripts:
+ PYTHONPATH="${CURRENT_DIR}" python -m unittest discover scripts/python
test-bats:
bats scripts/bats/test_edit_acme_dns_accounts.sh
# -------------------------------------------------------------
# Tests for roles
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
test-roles: test-roles-dns
test-roles-dns:
roles/python/dns/run_test_dns_zones.sh
# -------------------------------------------------------------
# Configuration test specific to the primary server
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
test-config:
cd config/salt-primary && make test
diff --git a/_tests/helpers.py b/_tests/helpers.py
new file mode 100644
index 0000000..1b8fe9a
--- /dev/null
+++ b/_tests/helpers.py
@@ -0,0 +1,30 @@
+# -------------------------------------------------------------
+# Helper utilities for tests suite
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+# Project: Nasqueron
+# License: 0BSD for import_from_path
+# Reference: http://docs.python.org/3/library/importlib.html
+# -------------------------------------------------------------
+
+
+import importlib.util
+import sys
+
+
+# -------------------------------------------------------------
+# Import mechanics
+#
+# Supersede importlib.machinery.SourceFileLoader load_module use
+# to maintain compatibility with Python 3.12+
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+
+def import_from_path(module_name, file_path):
+ file_final_path = "../" + file_path
+ spec = importlib.util.spec_from_file_location(module_name, file_final_path)
+
+ module = importlib.util.module_from_spec(spec)
+ sys.modules[module_name] = module
+ spec.loader.exec_module(module)
+
+ return module
diff --git a/_tests/modules/test_convert.py b/_tests/modules/test_convert.py
index 1fe702d..ef0e93c 100755
--- a/_tests/modules/test_convert.py
+++ b/_tests/modules/test_convert.py
@@ -1,22 +1,21 @@
#!/usr/bin/env python3
-from importlib.machinery import SourceFileLoader
import unittest
-salt_test_case = SourceFileLoader("salt_test_case", "salt_test_case.py").load_module()
-convert = SourceFileLoader("rust", "../_modules/convert.py").load_module()
+import salt_test_case
+import convert
class Testinstance(unittest.TestCase, salt_test_case.SaltTestCase):
def setUp(self):
self.initialize_mocks()
self.instance = convert
def test_to_flags(self):
features = ["foo", "bar"]
self.assertEqual("enable-foo enable-bar", convert.to_flags(features))
if __name__ == "__main__":
unittest.main()
diff --git a/_tests/modules/test_forest.py b/_tests/modules/test_forest.py
index 445e099..02e2f10 100755
--- a/_tests/modules/test_forest.py
+++ b/_tests/modules/test_forest.py
@@ -1,52 +1,50 @@
#!/usr/bin/env python3
-from importlib.machinery import SourceFileLoader
import unittest
-
-salt_test_case = SourceFileLoader("salt_test_case", "salt_test_case.py").load_module()
-forest = SourceFileLoader("forest", "../_modules/forest.py").load_module()
+import salt_test_case
+import forest
class Testinstance(unittest.TestCase, salt_test_case.SaltTestCase):
def setUp(self):
self.initialize_mocks()
self.instance = forest
self.mock_pillar("data/forests.yaml")
self.mock_grains()
self.grains["id"] = "egladil"
def test_exists(self):
self.assertTrue(forest.exists("lothlorien"))
self.assertFalse(forest.exists("notexisting"))
def test_get(self):
self.assertEqual("lothlorien", forest.get())
def test_get_when_key_not_exists(self):
self.grains["id"] = "notexisting"
self.assertRaises(KeyError, forest.get)
def test_list_groups(self):
self.assertEqual(["caras_galadhon", "ubiquity"], sorted(forest.list_groups()))
def test_list_groups_when_there_are_none_for_the_forest(self):
self.grains["id"] = "entwash"
self.assertEqual(["ubiquity"], forest.list_groups())
def test_get_groups(self):
self.assertEqual(
["caras_galadhon", "ubiquity"], sorted(forest.get_groups().keys())
)
def test_list_users(self):
self.assertEqual(["amdir", "amroth"], sorted(forest.list_users()))
def test_get_users(self):
self.assertEqual(["amdir", "amroth"], sorted(forest.get_users().keys()))
if __name__ == "__main__":
unittest.main()
diff --git a/_tests/modules/test_jails.py b/_tests/modules/test_jails.py
index 57cad76..7867f80 100755
--- a/_tests/modules/test_jails.py
+++ b/_tests/modules/test_jails.py
@@ -1,41 +1,39 @@
#!/usr/bin/env python3
-from importlib.machinery import SourceFileLoader
import unittest
-
-salt_test_case = SourceFileLoader("salt_test_case", "salt_test_case.py").load_module()
-jails = SourceFileLoader("jails", "../_modules/jails.py").load_module()
+import salt_test_case
+import jails
class Testinstance(unittest.TestCase, salt_test_case.SaltTestCase):
def setUp(self):
self.initialize_mocks()
self.instance = jails
self.mock_pillar("data/jails.yaml")
self.mock_grains()
self.grains["id"] = "host"
def test_get_default_group(self):
self.assertEqual("host", jails._get_default_group())
def test_get_all_jails(self):
self.assertEqual(["anotherhost", "host"], sorted(jails._get_all_jails().keys()))
def test_list_jails(self):
self.assertEqual(["guest1", "guest2"], sorted(jails.list_jails()))
def test_list_for_a_group(self):
self.assertEqual(["guest3"], sorted(jails.list_jails("anotherhost")))
def test_flatlist(self):
self.assertEqual("guest1 guest2", jails.flatlist())
def test_flatlist_for_a_group(self):
self.assertEqual("guest3", jails.flatlist("anotherhost"))
if __name__ == "__main__":
unittest.main()
diff --git a/_tests/modules/test_nano.py b/_tests/modules/test_nano.py
index 447d3b0..7e3cbdf 100755
--- a/_tests/modules/test_nano.py
+++ b/_tests/modules/test_nano.py
@@ -1,53 +1,51 @@
#!/usr/bin/env python3
-from importlib.machinery import SourceFileLoader
import unittest
-
-salt_test_case = SourceFileLoader("salt_test_case", "salt_test_case.py").load_module()
-nano = SourceFileLoader("nano", "../_modules/nano.py").load_module()
+import salt_test_case
+import nano
DATA_DIR = "data/nanorc_dir"
EXPECTED_INCLUDES = [
"include data/nanorc_dir/bar.nanorc",
"include data/nanorc_dir/foo.nanorc",
]
EXTRA_SETTINGS = ["set foo bar"]
EXPECTED_FULL_CONFIG = [""] * 2 + EXPECTED_INCLUDES + EXTRA_SETTINGS
class Testinstance(unittest.TestCase, salt_test_case.SaltTestCase):
def test_get_rc_contents(self):
actual_includes = nano._get_rc_content(DATA_DIR)
self.assertEqual(EXPECTED_INCLUDES, sorted(actual_includes.strip().split("\n")))
def test_get_rc_contents_full(self):
actual_includes = nano._get_rc_content(DATA_DIR, extra_settings=EXTRA_SETTINGS)
self.assertEqual(
EXPECTED_FULL_CONFIG, sorted(actual_includes.strip().split("\n"))
)
def test_get_rc_includes(self):
self.assertEqual(EXPECTED_INCLUDES, sorted(nano._get_rc_includes(DATA_DIR)))
def check_rc_up_to_date_when_it_is(self):
self.assertTrue(
nano.check_rc_up_to_date(name="data/nanorc_ok", nanorc_dir=DATA_DIR)
)
def check_rc_up_to_date_when_it_is_not(self):
self.assertFalse(
nano.check_rc_up_to_date(name="data/nanorc_not_ok", nanorc_dir=DATA_DIR)
)
def check_rc_up_to_date_when_it_is_does_not_exist(self):
self.assertFalse(
nano.check_rc_up_to_date(name="/not/existing", nanorc_dir=DATA_DIR)
)
if __name__ == "__main__":
unittest.main()
diff --git a/_tests/modules/test_network.py b/_tests/modules/test_network.py
index 8ea6ce1..b5c51f2 100755
--- a/_tests/modules/test_network.py
+++ b/_tests/modules/test_network.py
@@ -1,75 +1,73 @@
#!/usr/bin/env python3
-from importlib.machinery import SourceFileLoader
from unittest_data_provider import data_provider
import unittest
-
-salt_test_case = SourceFileLoader("salt_test_case", "salt_test_case.py").load_module()
-network = SourceFileLoader("network", "../_modules/network_utils.py").load_module()
+import salt_test_case
+import network_utils as network
class Testinstance(unittest.TestCase, salt_test_case.SaltTestCase):
cidr_prefixes = lambda: (
("255.255.255.255", 32),
("255.255.255.254", 31),
("255.255.255.252", 30),
("255.255.255.240", 28),
("255.255.255.224", 27),
("255.255.255.0", 24),
("255.252.0.0", 14),
)
valid_netmasks = lambda: (
("255.255.255.255",),
("255.255.255.254",),
("255.255.255.252",),
("255.255.255.240",),
)
invalid_netmasks = lambda: (
# In binary, it's not a suite of 1 then a suite of 0
("255.255.255.209",),
# By definition, netmask MUST be strictly greater than 0
("0.0.0.0",),
)
@data_provider(cidr_prefixes)
def test_netmask_to_cidr_prefix(self, netmask, expected_prefix):
actual_prefix = network.netmask_to_cidr_prefix(netmask)
self.assertTrue(actual_prefix == expected_prefix)
@data_provider(valid_netmasks)
def test_is_valid_netmask(self, netmask):
self.assertTrue(network.is_valid_netmask(netmask))
@data_provider(invalid_netmasks)
def test_is_valid_netmask_when_it_is_not(self, netmask):
self.assertFalse(network.is_valid_netmask(netmask))
def test_ipv6_address_to_prefix(self):
prefix = network._ipv6_address_to_prefix(
"2001:41d0:0303:d9ff:00ff:00ff:00ff:00ff", 64
)
self.assertEqual("2001:41d0:303:d9ff::", prefix.network_address.compressed)
def test_can_directly_be_discovered(self):
self.assertFalse(
network.can_directly_be_discovered(
"2001:41d0:0303:d9ff:00ff:00ff:00ff:00ff",
"2001:41d0:303:d971::517e:c0de",
64,
)
)
self.assertTrue(
network.can_directly_be_discovered(
"2001:41d0:0303:d971:00ff:00ff:00ff:00ff",
"2001:41d0:303:d971::517e:c0de",
64,
)
)
if __name__ == "__main__":
unittest.main()
diff --git a/_tests/modules/test_node.py b/_tests/modules/test_node.py
index d9d26eb..921df74 100755
--- a/_tests/modules/test_node.py
+++ b/_tests/modules/test_node.py
@@ -1,153 +1,151 @@
#!/usr/bin/env python3
-from importlib.machinery import SourceFileLoader
from unittest_data_provider import data_provider
import unittest
-
-salt_test_case = SourceFileLoader("salt_test_case", "salt_test_case.py").load_module()
-node = SourceFileLoader("node", "../_modules/node.py").load_module()
+import salt_test_case
+import node
class Testinstance(unittest.TestCase, salt_test_case.SaltTestCase):
def setUp(self):
self.initialize_mocks()
self.instance = node
self.mock_pillar("data/forests.yaml")
self.mock_grains()
self.grains["id"] = "egladil"
def test_get_wwwroot(self):
self.assertEqual("wwwroot/lothlorien.forest/egladil", node.get_wwwroot())
self.assertEqual("wwwroot/entwash.node/www", node.get_wwwroot("entwash"))
def test_filter_by_role(self):
node_key = self.grains["id"]
self.assertEqual(["Caras Galadhon"], node.filter_by_role("items_by_role"))
self.assertEqual(["Onodlo"], node.filter_by_role("items_by_role", "entwash"))
# No role
self.pillar["nodes"][node_key]["roles"] = []
self.assertEqual([], node.filter_by_role("items_by_role"))
# More than one role
self.pillar["nodes"][node_key]["roles"] = ["border", "treecity"]
self.assertEqual(
["Caras Galadhon", "Onodlo"], sorted(node.filter_by_role("items_by_role"))
)
def test_filter_by_role_with_star(self):
node_key = self.grains["id"]
self.assertEqual(
["Air", "Caras Galadhon"], node.filter_by_role("items_by_role_with_star")
)
self.assertEqual(
["Air", "Onodlo"], node.filter_by_role("items_by_role_with_star", "entwash")
)
# No role
self.pillar["nodes"][node_key]["roles"] = []
self.assertEqual(["Air"], node.filter_by_role("items_by_role_with_star"))
# More than one role
self.pillar["nodes"][node_key]["roles"] = ["border", "treecity"]
self.assertEqual(
["Air", "Caras Galadhon", "Onodlo"],
sorted(node.filter_by_role("items_by_role_with_star")),
)
def test_filter_by_name(self):
self.assertEqual(["Caras Galadhon"], node.filter_by_name("items_by_name"))
self.assertEqual(
["Caras Galadhon"], node.filter_by_name("items_by_name", "egladil")
)
self.grains["id"] = "entwash"
self.assertEqual([], node.filter_by_name("items_by_name"))
def test_filter_by_name_with_star(self):
self.assertEqual(
["Air", "Caras Galadhon"], node.filter_by_name("items_by_name_with_star")
)
self.assertEqual(
["Air", "Caras Galadhon"],
node.filter_by_name("items_by_name_with_star", "egladil"),
)
self.grains["id"] = "entwash"
self.assertEqual(["Air"], node.filter_by_name("items_by_name_with_star"))
def test_get_ipv6_list(self):
self.grains["ipv6"] = [
"::1",
"2001:470:1f13:ce7:ca5:cade:fab:1e",
"2001:470:1f12:ce7::2",
]
self.assertEqual(
"[::1] [2001:470:1f13:ce7:ca5:cade:fab:1e] [2001:470:1f12:ce7::2]",
node.get_ipv6_list(),
)
resolved_networks = lambda: (
(
"egladil",
{
"ipv4_address": "1.2.3.4",
"ipv4_gateway": "1.2.3.254",
},
),
(
"entwash",
{
"ipv4_address": "172.27.27.5",
"ipv4_gateway": "172.27.27.1",
},
),
)
@data_provider(resolved_networks)
def test_resolve_network(self, id, expected):
self.grains["id"] = id
self.assertIsSubsetDict(expected, node.resolve_network())
def test_resolve_network_without_gateway(self):
expected = {
"ipv4_address": "172.27.27.5",
"ipv4_gateway": "",
}
self.grains["id"] = "entwash"
del self.pillar["nodes"]["entwash"]["network"]["interfaces"]["net02"]["ipv4"][
"gateway"
]
self.assertIsSubsetDict(expected, node.resolve_network())
def test_resolve_network_without_any_network(self):
expected = {
"ipv4_address": "",
"ipv4_gateway": "",
}
self.grains["id"] = "entwash"
del self.pillar["nodes"]["entwash"]["network"]
self.assertIsSubsetDict(expected, node.resolve_network())
def assertIsSubsetDict(self, expected, actual):
for k, v in expected.items():
self.assertIn(k, actual)
self.assertEqual(v, actual[k], f"Unexpected value for key {k} in {actual}")
if __name__ == "__main__":
unittest.main()
diff --git a/_tests/modules/test_paas_docker.py b/_tests/modules/test_paas_docker.py
index a78d0f3..c7aaa86 100755
--- a/_tests/modules/test_paas_docker.py
+++ b/_tests/modules/test_paas_docker.py
@@ -1,87 +1,86 @@
#!/usr/bin/env python3
-from importlib.machinery import SourceFileLoader
import os
import unittest
-salt_test_case = SourceFileLoader("salt_test_case", "salt_test_case.py").load_module()
-docker = SourceFileLoader("docker", "../_modules/paas_docker.py").load_module()
+import salt_test_case
+import paas_docker as docker
class Testinstance(unittest.TestCase, salt_test_case.SaltTestCase):
def setUp(self):
self.initialize_mocks()
self.instance = docker
self.mock_pillar("data/paas_docker.yaml")
self.mock_grains()
self.grains["id"] = "egladil"
self.mock_salt()
self.salt["slsutil.file_exists"] = lambda file: os.path.exists(file)
def test_get_image(self):
container = {"image": "foo", "version": "42"}
self.assertEqual("foo:42", docker.get_image("not_foo", container))
def test_list_images(self):
expected = {"foo", "bar", "quux"}
self.assertEqual(expected, docker.list_images())
def test_get_image_without_version(self):
container = {
"image": "foo",
}
self.assertEqual("foo", docker.get_image("not_foo", container))
def test_get_image_without_image(self):
container = {"version": "42"}
self.assertEqual("not_foo:42", docker.get_image("not_foo", container))
def test_get_image_without_anything(self):
self.assertEqual("not_foo", docker.get_image("not_foo", {}))
def test_get_image_with_numeric_version(self):
container = {"image": "foo", "version": 2.5}
self.assertEqual("foo:2.5", docker.get_image("not_foo", container))
def test_resolve_vhost_config_file(self):
config_file = docker.resolve_vhost_config_file("empty", dir="data")
self.assertEqual("data/empty.conf", config_file)
def test_resolve_vhost_config_file_when_not_existing(self):
config_file = docker.resolve_vhost_config_file("foo", dir="notexisting")
self.assertEqual("notexisting/_default.conf", config_file)
def test_get_subnets(self):
expected = ["172.18.1.0/24", "172.18.2.0/24", "172.17.0.0/16"]
self.assertEqual(expected, docker.get_subnets())
def test_get_subnets_when_none_are_defined(self):
# Only the default Docker one
expected = ["172.17.0.0/16"]
self.grains["id"] = "voidserver"
self.pillar["docker_networks"] = {}
self.assertEqual(expected, docker.get_subnets())
def test_format_env_list(self):
expression = {"foo": "bar", "quux": 42}
expected = "foo: bar; quux: 42"
self.assertEqual(
expected, docker.format_env_list(expression, assign_op=": ", separator="; ")
)
if __name__ == "__main__":
unittest.main()
diff --git a/_tests/modules/test_prometheus.py b/_tests/modules/test_prometheus.py
index 49726cb..192f9f2 100755
--- a/_tests/modules/test_prometheus.py
+++ b/_tests/modules/test_prometheus.py
@@ -1,50 +1,49 @@
#!/usr/bin/env python3
-from importlib.machinery import SourceFileLoader
import unittest
-salt_test_case = SourceFileLoader("salt_test_case", "salt_test_case.py").load_module()
-prometheus = SourceFileLoader("prometheus", "../_modules/prometheus.py").load_module()
+import salt_test_case
+import prometheus
class Testinstance(unittest.TestCase, salt_test_case.SaltTestCase):
def setUp(self):
self.initialize_mocks()
self.instance = prometheus
self.mock_pillar("data/prometheus.yaml")
self.mock_salt()
self.mock_salt_pillar_get()
def test_resolve_service(self):
service = {
"service": "green",
"port": "9090",
}
self.assertEqual("emerald:9090", prometheus._resolve_service(service))
def test_resolve_service_list(self):
service = {
"service": "blue:all",
"port": "9090",
}
expected = [
"cyan:9090",
"turquoise:9090",
"ultramarine:9090",
]
self.assertEqual(expected, prometheus._resolve_service_list(service))
def test_get_scrape_configs(self):
expected = self.import_data_from_yaml("data/prometheus_scrape_configs.yml")
actual = prometheus.get_scrape_configs()
self.assertEqual(expected, actual)
if __name__ == "__main__":
unittest.main()
diff --git a/_tests/modules/test_rabbitmq.py b/_tests/modules/test_rabbitmq.py
index c8504d8..1298d26 100755
--- a/_tests/modules/test_rabbitmq.py
+++ b/_tests/modules/test_rabbitmq.py
@@ -1,16 +1,14 @@
#!/usr/bin/env python3
-from importlib.machinery import SourceFileLoader
import unittest
-
-salt_test_case = SourceFileLoader("salt_test_case", "salt_test_case.py").load_module()
-rabbitmq = SourceFileLoader("rabbitmq", "../_modules/rabbitmq_api.py").load_module()
+import salt_test_case
+import rabbitmq_api
class Testinstance(unittest.TestCase, salt_test_case.SaltTestCase):
def test_compute_password_hash_with_salt(self):
self.assertEqual(
"kI3GCqW5JLMJa4iX1lo7X4D6XbYqlLgxIs30+P6tENUV2POR",
- rabbitmq.compute_password_hash_with_salt(0x908DC60A, "test12"),
+ rabbitmq_api.compute_password_hash_with_salt(0x908DC60A, "test12"),
)
diff --git a/_tests/modules/test_rust.py b/_tests/modules/test_rust.py
index bbc4bb2..7a4d70c 100755
--- a/_tests/modules/test_rust.py
+++ b/_tests/modules/test_rust.py
@@ -1,27 +1,26 @@
#!/usr/bin/env python3
-from importlib.machinery import SourceFileLoader
import unittest
from salt.modules import cmdmod
-salt_test_case = SourceFileLoader("salt_test_case", "salt_test_case.py").load_module()
-rust = SourceFileLoader("rust", "../_modules/rust.py").load_module()
+import salt_test_case
+import rust
class Testinstance(unittest.TestCase, salt_test_case.SaltTestCase):
def setUp(self):
self.initialize_mocks()
self.instance = rust
self.mock_salt()
self.salt["cmd.shell"] = cmdmod.shell
def test_get_rustc_triplet(self):
triplet = rust.get_rustc_triplet()
self.assertTrue(len(triplet.split("-")) > 2)
if __name__ == "__main__":
unittest.main()
diff --git a/_tests/salt_test_case.py b/_tests/salt_test_case.py
index abf7ec4..b5fe9a2 100644
--- a/_tests/salt_test_case.py
+++ b/_tests/salt_test_case.py
@@ -1,54 +1,54 @@
-from importlib.machinery import SourceFileLoader
import yaml
+from mocks.dunder import dunder
+
class SaltTestCase:
def initialize_mocks(self):
- source = SourceFileLoader("dunder", "mocks/dunder.py").load_module()
- self.pillar = source.dunder()
- self.salt = source.dunder()
- self.grains = source.dunder()
+ self.pillar = dunder()
+ self.salt = dunder()
+ self.grains = dunder()
@staticmethod
def import_data_from_yaml(filename):
with open(filename, "r") as fd:
return yaml.safe_load(fd.read())
def mock_pillar(self, filename=None, target=None):
if not target:
target = self.instance
if filename:
self.pillar.data = self.import_data_from_yaml(filename)
target.__pillar__ = self.pillar
def mock_grains(self, target=None):
if not target:
target = self.instance
target.__grains__ = self.grains
def mock_salt(self, target=None):
if not target:
target = self.instance
target.__salt__ = self.salt
def mock_salt_pillar_get(self, target=None):
if not target:
target = self.instance
target.__salt__["pillar.get"] = lambda key: pillar_get(target.__pillar__, key)
def pillar_get(pillar, key, default=""):
if ":" not in key:
return pillar.get(key, default)
keys = key.split(":")
data = pillar[keys[0]]
remaining_key = ":".join(keys[1:])
return pillar_get(data, remaining_key, default)
diff --git a/_tests/scripts/python/test_clear_video_queue.py b/_tests/scripts/python/test_clear_video_queue.py
index 863faa4..dd55650 100755
--- a/_tests/scripts/python/test_clear_video_queue.py
+++ b/_tests/scripts/python/test_clear_video_queue.py
@@ -1,21 +1,22 @@
#!/usr/bin/env python3
-from importlib.machinery import SourceFileLoader
import unittest
+from helpers import import_from_path
-path = "roles/paas-docker/containers/files/mastodon/clear-video-queue.py"
-script = SourceFileLoader("script", "../" + path).load_module()
+
+script_path = "roles/paas-docker/containers/files/mastodon/clear-video-queue.py"
+script = import_from_path("script", script_path)
class Testinstance(unittest.TestCase):
def test_extract_pids(self):
with open("data/T1492-ps-x-sample.txt", "r") as fd:
ps_data = [line.strip() for line in fd]
expected_pids = [11562, 11693, 11895]
self.assertEqual(expected_pids, script.extract_pids(ps_data))
if __name__ == "__main__":
unittest.main()
diff --git a/_tests/scripts/python/test_edit_acme_dns_accounts.py b/_tests/scripts/python/test_edit_acme_dns_accounts.py
index d65347b..b1b9c54 100755
--- a/_tests/scripts/python/test_edit_acme_dns_accounts.py
+++ b/_tests/scripts/python/test_edit_acme_dns_accounts.py
@@ -1,47 +1,50 @@
#!/usr/bin/env python3
-from importlib.machinery import SourceFileLoader
+
import os
import unittest
+from helpers import import_from_path
-os.environ["ACME_ACCOUNTS"] = "/path/to/acmedns.json"
-path = "roles/core/certificates/files/edit-acme-dns-accounts.py"
-script = SourceFileLoader("script", "../" + path).load_module()
+script_path = "roles/core/certificates/files/edit-acme-dns-accounts.py"
+script = import_from_path("script", script_path)
+
+
+os.environ["ACME_ACCOUNTS"] = "/path/to/acmedns.json"
class TestInstance(unittest.TestCase):
def setUp(self):
self.testAccounts = script.AcmeAccounts("/dev/null")
pass
def test_read_path_from_environment(self):
self.assertEqual("/path/to/acmedns.json", script.get_acme_accounts_path())
def test_accounts_are_empty_on_init(self):
self.assertEqual({}, self.testAccounts.accounts)
def test_add(self):
self.testAccounts.add("foo.tld", {})
self.assertEqual(1, len(self.testAccounts.accounts))
self.assertIn("foo.tld", self.testAccounts.accounts)
def test_remove_existing(self):
self.testAccounts.add("foo.tld", {})
self.assertTrue(self.testAccounts.remove("foo.tld"))
self.assertEqual(0, len(self.testAccounts.accounts))
def test_remove_non_existing(self):
self.assertFalse(self.testAccounts.remove("not-existing.tld"))
def test_merge(self):
accounts_to_merge = script.AcmeAccounts("/dev/null").add("bar.tld", {})
self.testAccounts.add("foo.tld", {}).merge_with(accounts_to_merge)
self.assertEqual(2, len(self.testAccounts.accounts))
if __name__ == "__main__":
unittest.main()

File Metadata

Mime Type
text/x-diff
Expires
Wed, Mar 18, 13:29 (11 h, 9 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3540027
Default Alt Text
(27 KB)

Event Timeline