1
0
mirror of https://github.com/pi-hole/docker-pi-hole.git synced 2024-06-30 05:01:00 +02:00
docker-pi-hole/test/test_pihole_scripts.py

45 lines
2.0 KiB
Python
Raw Normal View History

import pytest
2016-11-06 22:12:11 +01:00
@pytest.fixture
2017-01-08 06:36:31 +01:00
def start_cmd():
2016-11-06 22:12:11 +01:00
''' broken by default, required override '''
return None
@pytest.fixture
2017-01-08 06:36:31 +01:00
def RunningPiHole(DockerPersist, Slow, persist_webserver, persist_tag, start_cmd):
2016-11-06 22:12:11 +01:00
''' Override the RunningPiHole to run and check for success of a
2017-01-08 06:36:31 +01:00
dnsmasq start based `pihole` script command '''
2017-05-05 05:37:26 +02:00
#print DockerPersist.run('ps -ef').stdout
2016-11-06 22:12:11 +01:00
Slow(lambda: DockerPersist.run('pgrep dnsmasq').rc == 0)
2017-05-05 05:37:26 +02:00
Slow(lambda: DockerPersist.run('pgrep {}'.format(persist_webserver)).rc == 0)
2016-11-06 22:12:11 +01:00
oldpid = DockerPersist.run('pidof dnsmasq')
2017-01-08 06:36:31 +01:00
cmd = DockerPersist.run('pihole {}'.format(start_cmd))
2016-11-06 22:12:11 +01:00
Slow(lambda: DockerPersist.run('pgrep dnsmasq').rc == 0)
newpid = DockerPersist.run('pidof dnsmasq')
for pid in [oldpid, newpid]:
assert pid != ''
2017-05-05 05:37:26 +02:00
# ensure a new pid for dnsmasq appeared due to service restart
assert oldpid != newpid
2016-11-06 22:12:11 +01:00
assert cmd.rc == 0
2017-01-08 06:36:31 +01:00
# Save out cmd result to check different stdout of start/enable/disable
2016-11-06 22:12:11 +01:00
DockerPersist.cmd = cmd
return DockerPersist
2017-01-08 06:36:31 +01:00
@pytest.mark.parametrize('start_cmd', ['start_cmd'])
def test_pihole_start_cmd(RunningPiHole, start_cmd, persist_tag):
''' the start_cmd tests are all built into the RunningPiHole fixture in this file '''
assert RunningPiHole.cmd.stdout == START_DNS_STDOUT[persist_tag]
2016-11-06 22:12:11 +01:00
2017-06-24 06:42:01 +02:00
@pytest.mark.parametrize('start_cmd,hostname,expected_ip, expected_message', [
('enable', 'pi.hole', '127.0.0.1', 'enabled'),
('disable 0', 'pi.hole', '127.0.0.1', 'disabled'),
2016-11-06 22:12:11 +01:00
])
2017-06-24 06:42:01 +02:00
def test_pihole_start_cmd(RunningPiHole, Dig, persist_tag, start_cmd, hostname, expected_ip, expected_message):
2017-01-08 06:36:31 +01:00
''' the start_cmd tests are all built into the RunningPiHole fixture in this file '''
2016-11-06 22:12:11 +01:00
dig_cmd = "dig +time=1 +noall +answer {} @test_pihole | awk '{{ print $5 }}'".format(hostname)
lookup = RunningPiHole.dig.run(dig_cmd).stdout.rstrip('\n')
assert lookup == expected_ip
2017-06-24 06:42:01 +02:00
stdout = "::: Blocking has been {}!\n".format(expected_message)
assert stdout in RunningPiHole.cmd.stdout