unit_test_acme_dns_tiny.py 1.45 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
"""Unit tests for the acme_dns_tiny script"""
import unittest
import sys
import os
import configparser
import dns.version
import acme_dns_tiny
from tests.config_factory import generate_acme_dns_tiny_unit_test_config

class TestACMEDNSTiny(unittest.TestCase):
    "Tests for acme_dns_tiny.get_crt()"

    @classmethod
    def setUpClass(cls):
        print("Init acme_dns_tiny with python modules:")
        print("  - python: {0}".format(sys.version))
        print("  - dns python: {0}".format(dns.version.version))
        cls.configs = generate_acme_dns_tiny_unit_test_config()
        sys.stdout.flush()
        super(TestACMEDNSTiny, cls).setUpClass()

    # Close correctly temporary files
    @classmethod
    def tearDownClass(cls):
        # close temp files correctly
        for conffile in cls.configs:
            parser = configparser.ConfigParser()
28
            parser.read(cls.configs[conffile])
29 30
            os.remove(parser["acmednstiny"]["AccountKeyFile"])
            os.remove(parser["acmednstiny"]["CSRFile"])
31
            os.remove(cls.configs[conffile])
32 33 34 35 36 37 38 39
        super(TestACMEDNSTiny, cls).tearDownClass()


    def test_failure_notcompleted_configuration(self):
        """ Configuration file have to be completed """
        self.assertRaisesRegex(ValueError, r"Some required settings are missing.",
                               acme_dns_tiny.main, [self.configs['missing_dns'], "--verbose"])

40
if __name__ == "__main__":  # pragma: no cover
41
    unittest.main()