Skip to content

Commit

Permalink
added tests for console script
Browse files Browse the repository at this point in the history
  • Loading branch information
infothrill committed Apr 2, 2021
1 parent e30eecd commit 44f64d1
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 9 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
Release history
---------------
0.6.x (unreleased)
++++++++++++++++++
++++++++++++++++++++++
- improved: dnswanip error reporting now includes dns information
- improved: fix for bug `#144 <https://github.com/infothrill/python-dyndnsc/issues/144>`_
- improved: added tests for console script

0.6.0 (February 21st 2021)
++++++++++++++++++++++++++
Expand Down
8 changes: 2 additions & 6 deletions dyndnsc/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -201,7 +201,3 @@ def main():
run_forever_callable()

return 0


if __name__ == "__main__":
sys.exit(main())
73 changes: 73 additions & 0 deletions dyndnsc/tests/test_console_scripts.py
Original file line number Diff line number Diff line change
@@ -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 == ""
1 change: 0 additions & 1 deletion dyndnsc/updater/dummy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@

TESTS_REQUIRE = [
"bottle==0.12.13",
"pytest>=3.2.5"
"pytest>=4.0.0",
"pytest-console-scripts",
]

EXTRAS_REQUIRE = {}
Expand Down

0 comments on commit 44f64d1

Please sign in to comment.