From 1acab5785665ec2cabeb17995472cca4fa958d0d Mon Sep 17 00:00:00 2001 From: Michael Prokop Date: Tue, 30 May 2017 18:30:19 +0200 Subject: [PATCH] TT#16903 Provide tests for 'ngcpcfg set' + 'ngcpcfg del' Change-Id: Icd7629daf73f43fa619e41b333c1adb95a8674f3 --- t/Dockerfile | 4 +- t/test_ngcpcfg_set_and_del.py | 375 ++++++++++++++++++++++++++++++++++ 2 files changed, 377 insertions(+), 2 deletions(-) create mode 100644 t/test_ngcpcfg_set_and_del.py diff --git a/t/Dockerfile b/t/Dockerfile index a6387182..3ad4120b 100644 --- a/t/Dockerfile +++ b/t/Dockerfile @@ -28,8 +28,8 @@ WORKDIR /code/ # % docker run --rm -i -t -v $(pwd)/..:/code:rw ngcpcfg-jessie:latest bash # # Use the existing docker image: -# % docker pull docker1.mgm.sipwise.com/ngcpcfg-jessie -# % docker run --rm -i -t -v $(pwd)/..:/code:rw docker1.mgm.sipwise.com/ngcpcfg-jessie:latest bash +# % docker pull docker.mgm.sipwise.com/ngcpcfg-jessie +# % docker run --rm -i -t -v $(pwd)/..:/code:rw docker.mgm.sipwise.com/ngcpcfg-jessie:latest bash # # Inside docker (the command is in history, just press UP button): # ./t/testrunner diff --git a/t/test_ngcpcfg_set_and_del.py b/t/test_ngcpcfg_set_and_del.py new file mode 100644 index 00000000..68735463 --- /dev/null +++ b/t/test_ngcpcfg_set_and_del.py @@ -0,0 +1,375 @@ +#!/usr/bin/env py.test-3 + +import pytest +import re +import tempfile + +############################################################### +# ngcpcfg set +############################################################### + + +@pytest.mark.tt_16903 +def test_set_action_missing_all_parameters(ngcpcfgcli, tmpdir): + tmpfile = tmpdir.join("tmpfile.txt") + tmpfile.write("---\n") + out = ngcpcfgcli("set") + assert tmpfile.read() == '''---\n''' + assert "" in out.stdout + assert "Usage: ngcpcfg set " in out.stderr + assert out.returncode == 1 + + +@pytest.mark.tt_16903 +def test_set_action_missing_first_parameter(ngcpcfgcli, tmpdir): + tmpfile = tmpdir.join("tmpfile.txt") + tmpfile.write("---\n") + out = ngcpcfgcli("set", "test=123") + assert tmpfile.read() == '''---\n''' + assert "" in out.stdout + assert "Usage: ngcpcfg set " in out.stderr + assert out.returncode == 1 + + +@pytest.mark.tt_16903 +def test_set_action_missing_second_parameter(ngcpcfgcli, tmpdir): + tmpfile = tmpdir.join("tmpfile.txt") + tmpfile.write("---\n") + out = ngcpcfgcli("set", str(tmpfile)) + assert tmpfile.read() == '''---\n''' + assert "" in out.stdout + assert "Usage: ngcpcfg set " in out.stderr + assert out.returncode == 1 + + +@pytest.mark.tt_16903 +def test_set_action_missing_option_value(ngcpcfgcli, tmpdir): + tmpfile = tmpdir.join("tmpfile.txt") + tmpfile.write("---\n") + out = ngcpcfgcli("set", str(tmpfile), "aaa.bbb=") + assert tmpfile.read() == '''---\n''' + assert "" in out.stdout + assert "Error: missing value to set. Exiting." in out.stderr + assert out.returncode == 1 + + +@pytest.mark.tt_16903 +def test_set_action_missing_option_name(ngcpcfgcli, tmpdir): + tmpfile = tmpdir.join("tmpfile.txt") + tmpfile.write("---\n") + out = ngcpcfgcli("set", str(tmpfile), "=123") + assert tmpfile.read() == '''---\n''' + assert "" in out.stdout + assert "Error: missing option to set. Exiting." in out.stderr + assert out.returncode == 1 + + +@pytest.mark.tt_16903 +def test_set_action_missing_file(ngcpcfgcli, tmpdir): + tmpfile = tmpdir.join("tmpfile.txt") + tmpfile.write("---\n") + out = ngcpcfgcli("set", "/tmp/non_existed_file", "aaa=123") + assert tmpfile.read() == '''---\n''' + assert "" in out.stdout + assert "Error: missing /tmp/non_existed_file. Exiting." in out.stderr + assert out.returncode == 1 + + +@pytest.mark.tt_16903 +def test_set_action_generate_dictionary_digits(ngcpcfgcli, tmpdir): + tmpfile = tmpdir.join("tmpfile.txt") + tmpfile.write("---\n") + out = ngcpcfgcli("set", str(tmpfile), "aaa.bbb=123") + assert tmpfile.read() == '''--- +aaa: + bbb: 123 +''' + assert "" in out.stdout + assert "" in out.stderr + assert out.returncode == 0 + + +@pytest.mark.tt_16903 +def test_set_action_generate_dictionary_bool_fail(ngcpcfgcli, tmpdir): + tmpfile = tmpdir.join("tmpfile.txt") + tmpfile.write("---\n") + out = ngcpcfgcli("set", str(tmpfile), "aaa.bbb=true") + assert tmpfile.read() == '''--- +aaa: + bbb: 'true' +''' + assert "" in out.stdout + assert "" in out.stderr + assert out.returncode == 0 + + +@pytest.mark.tt_16903 +def test_set_action_generate_dictionary_bool_ok(ngcpcfgcli, tmpdir): + tmpfile = tmpdir.join("tmpfile.txt") + tmpfile.write("---\n") + out = ngcpcfgcli("set", str(tmpfile), "aaa.bbb='true'") + assert tmpfile.read() == '''--- +aaa: + bbb: 'true' +''' + assert "" in out.stdout + assert "" in out.stderr + assert out.returncode == 0 + + +@pytest.mark.tt_16903 +def test_set_action_generate_dictionary_string(ngcpcfgcli, tmpdir): + tmpfile = tmpdir.join("tmpfile.txt") + tmpfile.write("---\n") + out = ngcpcfgcli("set", str(tmpfile), "aaa.bbb='on'") + assert tmpfile.read() == '''--- +aaa: + bbb: on +''' + assert "" in out.stdout + assert "" in out.stderr + assert out.returncode == 0 + + +@pytest.mark.tt_16903 +def test_set_action_generate_dictionary_string_change(ngcpcfgcli, tmpdir): + tmpfile = tmpdir.join("tmpfile.txt") + tmpfile.write("---\n") + out = ngcpcfgcli("set", str(tmpfile), "aaa.bbb='off'") + assert tmpfile.read() == '''--- +aaa: + bbb: off +''' + assert "" in out.stdout + assert "" in out.stderr + assert out.returncode == 0 + + +@pytest.mark.tt_16903 +def test_set_action_generate_dictionary_string_nochange(ngcpcfgcli, tmpdir): + tmpfile = tmpdir.join("tmpfile.txt") + tmpfile.write("---\n") + out = ngcpcfgcli("set", str(tmpfile), "aaa.bbb=off") + assert tmpfile.read() == '''--- +aaa: + bbb: off +''' + assert "" in out.stdout + assert "" in out.stderr + assert out.returncode == 0 + + +@pytest.mark.tt_16903 +def test_set_action_generate_dictionary_subsection(ngcpcfgcli, tmpdir): + tmpfile = tmpdir.join("tmpfile.txt") + tmpfile.write("---\n") + out = ngcpcfgcli("set", str(tmpfile), "aaa.bbb={'ccc','123','ddd','567'}") + assert tmpfile.read() == '''--- +aaa: + bbb: + ccc: '123' + ddd: '567' +''' + assert "" in out.stdout + assert "" in out.stderr + assert out.returncode == 0 + + +@pytest.mark.tt_16903 +def test_set_action_generate_list(ngcpcfgcli, tmpdir): + tmpfile = tmpdir.join("tmpfile.txt") + tmpfile.write("---\n") + out = ngcpcfgcli("set", str(tmpfile), "aaa.bbb=['ccc','123','ddd','567']") + assert tmpfile.read() == '''--- +aaa: + bbb: + - ccc + - '123' + - ddd + - '567' +''' + assert "" in out.stdout + assert "" in out.stderr + assert out.returncode == 0 + + +@pytest.mark.tt_16903 +def test_set_action_add_list(ngcpcfgcli, tmpdir): + tmpfile = tmpdir.join("tmpfile.txt") + tmpfile.write('''--- +ccc: + pytest-was-here: true +''') + out = ngcpcfgcli("set", str(tmpfile), "foo.bar=['ha','hi','he','ho']") + assert tmpfile.read() == '''--- +ccc: + pytest-was-here: 'true' +foo: + bar: + - ha + - hi + - he + - ho +''' + assert "" in out.stdout + assert "" in out.stderr + assert out.returncode == 0 + + +@pytest.mark.tt_16903 +def test_set_action_modify_list(ngcpcfgcli, tmpdir): + tmpfile = tmpdir.join("tmpfile.txt") + tmpfile.write('''--- +foo: + bar: 'true' + baz: 'true' +''') + out = ngcpcfgcli("set", str(tmpfile), "foo.bar=\'false\'") + assert tmpfile.read() == '''--- +foo: + bar: 'false' + baz: 'true' +''' + assert "" in out.stdout + assert "" in out.stderr + assert out.returncode == 0 + + +############################################################### +# ngcpcfg del +############################################################### + + +@pytest.mark.tt_16903 +def test_del_action_missing_all_parameters(ngcpcfgcli, tmpdir): + tmpfile = tmpdir.join("tmpfile.txt") + tmpfile.write("---\n") + out = ngcpcfgcli("del") + assert tmpfile.read() == '''---\n''' + assert "" in out.stdout + assert "Usage: ngcpcfg del