diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 9053a4a8..4f2f4aed 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -3,9 +3,10 @@ Release history --------------- 0.6.x (unreleased) -++++++++++++++++++ +++++++++++++++++++++++ - improved: dnswanip error reporting now includes dns information - improved: fix for bug `#144 `_ +- improved: added tests for console script 0.6.0 (February 21st 2021) ++++++++++++++++++++++++++ diff --git a/dyndnsc/cli.py b/dyndnsc/cli.py index 578a4abd..9fa68b82 100644 --- a/dyndnsc/cli.py +++ b/dyndnsc/cli.py @@ -19,7 +19,7 @@ from .common.dynamiccli import parse_cmdline_args -def list_presets(cfg, out=sys.stdout): +def list_presets(cfg, out): """Write a human readable list of available presets to out. :param cfg: ConfigParser instance @@ -157,7 +157,7 @@ def main(): cfg = get_configuration(args.config) if args.listpresets: - list_presets(cfg) + list_presets(cfg, out=sys.stdout) return 0 if args.config: @@ -201,7 +201,3 @@ def main(): run_forever_callable() return 0 - - -if __name__ == "__main__": - sys.exit(main()) diff --git a/dyndnsc/tests/test_console_scripts.py b/dyndnsc/tests/test_console_scripts.py new file mode 100644 index 00000000..6222a570 --- /dev/null +++ b/dyndnsc/tests/test_console_scripts.py @@ -0,0 +1,73 @@ +# -*- coding: utf-8 -*- + +"""Tests for the console script using the pytest-console-scripts fixture.""" + +import pytest + +# flake8: noqa + + +@pytest.mark.script_launch_mode('inprocess') +def test_version(script_runner): + from dyndnsc import __version__ + ret = script_runner.run("dyndnsc", "--version") + assert ret.success + assert ret.stdout == "dyndnsc %s\n" % __version__ + assert ret.stderr == "" + + +@pytest.mark.script_launch_mode('inprocess') +def test_presets(script_runner): + ret = script_runner.run("dyndnsc", "--list-presets") + assert ret.success + assert "updater-url" in ret.stdout + assert ret.stderr == "" + + +@pytest.mark.script_launch_mode('inprocess') +def test_help(script_runner): + ret = script_runner.run("dyndnsc", "--help") + assert ret.success + assert "usage: dyndnsc" in ret.stdout + assert ret.stderr == "" + + +@pytest.mark.script_launch_mode('inprocess') +def test_null_dummy(script_runner): + ret = script_runner.run( + "dyndnsc", + "--detector-null", + "--updater-dummy", + "--updater-dummy-hostname", "example.com" + ) + assert ret.success + assert ret.stdout == "" + assert ret.stderr == "" + + +@pytest.mark.script_launch_mode('inprocess') +def test_null_dummy_debug(script_runner): + ret = script_runner.run( + "dyndnsc", + "--detector-null", + "--updater-dummy", + "--updater-dummy-hostname", "example.com", + "--debug" + ) + assert ret.success + assert ret.stdout == "" + assert "DEBUG" in ret.stderr + + +@pytest.mark.script_launch_mode('inprocess') +def test_null_dummy_logjson(script_runner): + ret = script_runner.run( + "dyndnsc", + "--detector-null", + "--updater-dummy", + "--updater-dummy-hostname", "example.com", + "--log-json", "--debug" + ) + assert ret.success + assert "{\"written_at\":" in ret.stdout + assert ret.stderr == "" diff --git a/dyndnsc/updater/dummy.py b/dyndnsc/updater/dummy.py index 47e43d38..39b6fd11 100644 --- a/dyndnsc/updater/dummy.py +++ b/dyndnsc/updater/dummy.py @@ -9,7 +9,6 @@ class UpdateProtocolDummy(UpdateProtocol): """The dummy update protocol.""" _updateurl = "http://localhost.nonexistant/nic/update" - _dont_register_arguments = True configuration_key = "dummy" def __init__(self, hostname, **kwargs): diff --git a/setup.py b/setup.py index d7ad9363..c50a0cb0 100644 --- a/setup.py +++ b/setup.py @@ -58,7 +58,8 @@ TESTS_REQUIRE = [ "bottle==0.12.13", - "pytest>=3.2.5" + "pytest>=4.0.0", + "pytest-console-scripts", ] EXTRAS_REQUIRE = {}