From 345bf83517f18047662367e22d1509dac2a90c73 Mon Sep 17 00:00:00 2001 From: Nikhil Dhandre Date: Fri, 19 Apr 2019 13:14:25 +0530 Subject: [PATCH 1/2] move miqsel_cmd to test entry dir Signed-off-by: Nikhil Dhandre --- tests/__init__.py | 18 ++++++++++++++++++ tests/conftest.py | 2 +- tests/test_status.py | 18 +----------------- 3 files changed, 20 insertions(+), 18 deletions(-) create mode 100644 tests/__init__.py diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..6d0a724 --- /dev/null +++ b/tests/__init__.py @@ -0,0 +1,18 @@ +import subprocess + + +def miqsel_cmd(cmd): + """ + Runs a miqsel shell command, and returns the output, err, returncode + """ + ret = subprocess.Popen( + cmd, + shell=True, + stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + close_fds=True, + ) + out, err = ret.communicate() + returncode = ret.returncode + return out.decode(), err.decode(), returncode diff --git a/tests/conftest.py b/tests/conftest.py index 7fd5e02..49d8a24 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,5 +1,5 @@ import os -from subprocess import Popen, PIPE +from subprocess import PIPE, Popen import pytest diff --git a/tests/test_status.py b/tests/test_status.py index e5a5f57..aedd65c 100644 --- a/tests/test_status.py +++ b/tests/test_status.py @@ -1,22 +1,6 @@ import os -import subprocess - -def miqsel_cmd(cmd): - """ - Runs a miqsel shell command, and returns the output, err, returncode - """ - ret = subprocess.Popen( - cmd, - shell=True, - stdin=subprocess.PIPE, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, - close_fds=True, - ) - out, err = ret.communicate() - returncode = ret.returncode - return out.decode(), err.decode(), returncode +from tests import miqsel_cmd def test_miqsel_help(): From f55621b8b166cbcd7e3868a416e5f4a4b2f99e17 Mon Sep 17 00:00:00 2001 From: Nikhil Dhandre Date: Fri, 19 Apr 2019 13:35:30 +0530 Subject: [PATCH 2/2] test start stop Signed-off-by: Nikhil Dhandre --- tests/conftest.py | 15 +++++++++++++++ tests/test_miqsel.py | 18 ++++++++++++++++++ tests/test_status.py | 2 +- 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 tests/test_miqsel.py diff --git a/tests/conftest.py b/tests/conftest.py index 49d8a24..68ae52d 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -2,6 +2,7 @@ from subprocess import PIPE, Popen import pytest +from tests import miqsel_cmd @pytest.fixture(scope="module") @@ -16,3 +17,17 @@ def config(): yield if os.path.isdir("conf"): os.rmdir("conf") + + +@pytest.fixture(scope="module") +def ensure_stopped(config): + out, _, _ = miqsel_cmd("miqsel status") + if out.strip() == "running": + miqsel_cmd("miqsel stop") + + +@pytest.fixture(scope="module") +def ensure_running(config): + out, _, _ = miqsel_cmd("miqsel status") + if out.strip() != "running": + miqsel_cmd("miqsel start") diff --git a/tests/test_miqsel.py b/tests/test_miqsel.py new file mode 100644 index 0000000..92bab31 --- /dev/null +++ b/tests/test_miqsel.py @@ -0,0 +1,18 @@ +from tests import miqsel_cmd + + +def test_miqsel_start(ensure_stopped): + """Check start of miqsel""" + + out, err, returncode = miqsel_cmd("miqsel start") + assert "miq_sel container started" in out + out, err, returncode = miqsel_cmd("miqsel status") + assert out.strip() == "running" + + +def test_miqsel_stop(ensure_running): + """Check stop of miqsel""" + + miqsel_cmd("miqsel stop") + out, _, _ = miqsel_cmd("miqsel status") + assert out.strip() == "Not running..." diff --git a/tests/test_status.py b/tests/test_status.py index aedd65c..d20dd12 100644 --- a/tests/test_status.py +++ b/tests/test_status.py @@ -21,7 +21,7 @@ def test_miqsel_unconfigured(): ) -def test_miqsel_configured(config): +def test_miqsel_configured(ensure_stopped): out, err, returncode = miqsel_cmd("miqsel status") assert returncode == 0 assert out.strip() == "Not running..."