Commit 1808bd9d authored by Adrien Dorsaz's avatar Adrien Dorsaz

tests: split out unit test from staging test

parent a2d5f8cf
......@@ -50,6 +50,19 @@ def generate_config():
return account_key.name, domain_key.name, domain_csr.name, parser
def generate_acme_dns_tiny_unit_test_config():
"""Genereate acme_dns_tiny configurations used for unit tests"""
# Configuration missing DNS section
_, domain_key, _, config = generate_config()
os.remove(domain_key)
missing_dns = NamedTemporaryFile(delete=False)
config["DNS"] = {}
with open(missing_dns.name, 'w') as configfile:
config.write(configfile)
return {"missing_dns": missing_dns.name}
def generate_acme_dns_tiny_config(): #pylint: disable=too-many-locals,too-many-statements
"""Generate acme_dns_tiny configuration with account and domain keys"""
# Simple configuration with good options
......@@ -169,15 +182,6 @@ def generate_acme_dns_tiny_config(): #pylint: disable=too-many-locals,too-many-s
with open(invalid_tsig_name.name, 'w') as configfile:
config.write(configfile)
# Create config parser from the good default config to generate custom configs
account_key, domain_key, _, config = generate_config()
os.remove(domain_key)
missing_dns = NamedTemporaryFile(delete=False)
config["DNS"] = {}
with open(missing_dns.name, 'w') as configfile:
config.write(configfile)
return {
# configs
"good_cname": good_cname.name,
......@@ -190,7 +194,6 @@ def generate_acme_dns_tiny_config(): #pylint: disable=too-many-locals,too-many-s
"weak_key": weak_key.name,
"account_as_domain": account_as_domain.name,
"invalid_tsig_name": invalid_tsig_name.name,
"missing_dns": missing_dns.name,
# cname CSR file to use with good_cname_without_csr as argument
"cname_csr": cname_csr,
}
......
"""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()
parser.read(conffile)
os.remove(parser["acmednstiny"]["AccountKeyFile"])
os.remove(parser["acmednstiny"]["CSRFile"])
os.remove(conffile)
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"])
if __name__ == "__main__":
unittest.main()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment