Files
dnsverify/dnsverify_tests.py
2021-08-30 12:58:04 +02:00

49 lines
1.7 KiB
Python

#!/bin/env python
'''
Unit tests for dnsverify
'''
import unittest
from dnsverify import do_check
from dnsverify import get_authoritative_ns
from dnsverify import get_domains_from_yaml
from dnsverify import verify_authoritative_ns
from pylint.lint import Run
from pylint.reporters import CollectingReporter
class TestDnsVerify(unittest.TestCase):
def test_do_check(self):
'''
... Test whether checks acutally fail when an error occures.
'''
self.assertEqual(do_check(['puzzle.ch'], ['ns1.google.com'], verbose=False),
False)
def test_get_authoritative_ns(self):
'''
... Test whether garbage queries trigger a stack trace.
'''
self.assertEqual(get_authoritative_ns('dinimer.lolwas'), [])
def test_get_domains_from_yaml(self):
'''
... Test whether missing files generate an empty list.
'''
self.assertEqual(get_domains_from_yaml(["notexist.yaml"]), [])
def test_verify_authoritative_ns(self):
'''
... Test whether false if check fails and test if type errors are handeled correctly.
'''
self.assertEqual(verify_authoritative_ns('ns1.google.com', ['ns2.google.com']), False)
self.assertRaises(TypeError, verify_authoritative_ns, 123, ['123'])
self.assertRaises(TypeError, verify_authoritative_ns, "123", "123")
def test_pylint(self):
'''
... Test whether the coding style is acceptable.
'''
rep = CollectingReporter()
results = Run(['dnsverify.py', '-sn'], reporter=rep, exit=False)
score = results.linter.stats['global_note']
self.assertGreaterEqual(score, 8, "Pylint score to low. Fix your code.")