#!/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 if 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 if garbage queries trigger a stack trace. ''' self.assertEqual(get_authoritative_ns('dinimer.lolwas'), []) def test_get_domains_from_yaml(self): ''' ... Test wheter missing files generate an empty list. ''' self.assertEqual(get_domains_from_yaml(["notexist.yaml"]), []) def test_verify_authoritative_ns(self): ''' ... Test wheter false is returned when the ns does not match the list. 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 wheter 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.")