diff --git a/tests/functional/test_evaluate.py b/tests/functional/test_evaluate.py new file mode 100644 index 0000000..a97ba2f --- /dev/null +++ b/tests/functional/test_evaluate.py @@ -0,0 +1,21 @@ +# evaluation datastructure [ {digest: { input_image: [ { detail: {}, last_eval: "", policyid: "", status: "" } ] } ] +import pytest +import json +from conftest import ExitCode + +input_image = "centos:latest" + + +@pytest.fixture +def eval_command(admin_call): + def apply(sub_command, flags): + out, err, code = admin_call(["--json", "evaluate", sub_command] + flags) + return out, err, code + + return apply + + +def test_check(eval_command): + res, err, code = eval_command("check", [input_image]) + result = json.loads(res) + print(result) diff --git a/tests/functional/test_event.py b/tests/functional/test_event.py new file mode 100644 index 0000000..6801311 --- /dev/null +++ b/tests/functional/test_event.py @@ -0,0 +1,25 @@ +import pytest +import json + + +input_image = "alpine:latest" + + +@pytest.fixture +def event_command(admin_call): + def apply(sub_command, flags): + output, _, _ = admin_call(["--json", "event", sub_command] + flags) + return json.loads(output) + + return apply + + +class TestEvents: + def test_event_list(self): + pass + + def test_event_get(self): + pass + + def test_event_delete(self): + pass diff --git a/tests/functional/test_images.py b/tests/functional/test_images.py new file mode 100644 index 0000000..02e7d35 --- /dev/null +++ b/tests/functional/test_images.py @@ -0,0 +1,33 @@ +from conftest import call, ExitCode +import pytest +import json +import ipdb + + +input_image = "centos:latest" + + +@pytest.fixture +def image_command(admin_call): + def apply(sub_command, flags): + out, _, _ = admin_call(["--json", "image", sub_command] + flags) + return json.loads(out) + + return apply + + +def test_image_add(image_command): + result = image_command("add", [input_image]) + assert result[0]["image_status"] == "active" + assert result[0]["image_detail"][0]["fulltag"] == "docker.io/centos:latest" + + +def test_image_list(image_command): + result = image_command("list", []) + assert result[0]["image_status"] == "active" + assert result[0]["image_detail"][0]["fulltag"] == "docker.io/centos:latest" + + +def test_image_get(image_command): + result = image_command("get", [input_image]) + assert result[0]["image_detail"][0]["fulltag"] == "docker.io/centos:latest" diff --git a/tests/functional/test_policy.py b/tests/functional/test_policy.py new file mode 100644 index 0000000..fde5d1a --- /dev/null +++ b/tests/functional/test_policy.py @@ -0,0 +1,22 @@ +import pytest +import json + +input_policy = "foo" + + +@pytest.fixture +def policy_command(admin_call): + def apply(sub_command, flags): + out, _, _ = admin_call(["--json", "policy", sub_command] + flags) + return json.loads(out) + + return apply + + +class TestPolicyCMD: + def test_policy_add(self, policy_command): + result = policy_command("add", input_policy) + print(result) + + def test_policy_get(self, policy_command): + result = policy_command("get", input_policy_id) diff --git a/tests/functional/test_query.py b/tests/functional/test_query.py new file mode 100644 index 0000000..0d7b08f --- /dev/null +++ b/tests/functional/test_query.py @@ -0,0 +1,15 @@ +import pytest +import json + + +@pytest.fixture +def query_command(admin_call): + def apply(sub_command, flags): + out, _, _ = admin_call(["--json", "query", sub_command] + flags) + return json.loads(out) + + return apply + + +def test_image_by_vulnerability(query_command): + pass diff --git a/tests/functional/test_registry.py b/tests/functional/test_registry.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/functional/test_repo.py b/tests/functional/test_repo.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/functional/test_subscription.py b/tests/functional/test_subscription.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/functional/test_system.py b/tests/functional/test_system.py new file mode 100644 index 0000000..2709d8c --- /dev/null +++ b/tests/functional/test_system.py @@ -0,0 +1,30 @@ +import pytest +import json + + +@pytest.fixture +def system_command(admin_call): + def apply(sub_command, flags): + out, _, _ = admin_call(["--json", "system", sub_command] + flags) + return json.loads(out) + + return apply + + +class TestSystemStatus: + @staticmethod + def _search_dict(name, col): + for entry in col: + if entry["servicename"] == name: + return entry + + def test_system_status(self, system_command): + services = ["apiext", "catalog", "analyzer", "policy_engine", "simplequeue"] + result = system_command("status", []) + for srv_name in services: + asset = self._search_dict(srv_name, result["service_states"]) + assert asset["servicename"] == srv_name + assert asset["service_detail"]["message"] == "all good" + assert asset["service_detail"]["available"] + assert asset["status_message"] == "available" + assert asset["service_detail"]["up"]