Coverage for tests/unit_test_acme_dns_tiny.py: 83%

36 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2024-05-24 19:15 +0000

1"""Unit tests for the acme_dns_tiny script""" 

2import unittest 

3import sys 

4import os 

5import configparser 

6import dns.version 

7import acme_dns_tiny 

8from tests.config_factory import generate_acme_dns_tiny_unit_test_config 

9 

10 

11class TestACMEDNSTiny(unittest.TestCase): 

12 "Tests for acme_dns_tiny.get_crt()" 

13 

14 @classmethod 

15 def setUpClass(cls): 

16 print("Init acme_dns_tiny with python modules:") 

17 print(" - python: {0}".format(sys.version)) 

18 print(" - dns python: {0}".format(dns.version.version)) 

19 cls.configs = generate_acme_dns_tiny_unit_test_config() 

20 sys.stdout.flush() 

21 super(TestACMEDNSTiny, cls).setUpClass() 

22 

23 # Close correctly temporary files 

24 @classmethod 

25 def tearDownClass(cls): 

26 # close temp files correctly 

27 for file in cls.configs.values(): 

28 parser = configparser.ConfigParser() 

29 parser.read(file) 

30 try: 

31 os.remove(parser["acmednstiny"]["AccountKeyFile"]) 

32 except: 

33 pass 

34 try: 

35 os.remove(parser["acmednstiny"]["CSRFile"]) 

36 except: 

37 pass 

38 try: 

39 os.remove(file) 

40 except: 

41 pass 

42 super(TestACMEDNSTiny, cls).tearDownClass() 

43 

44 def test_failure_notcompleted_configuration(self): 

45 """ Configuration file have to be completed """ 

46 self.assertRaisesRegex(ValueError, r"Some required settings are missing.", 

47 acme_dns_tiny.main, [self.configs['missing_tsigkeyring'], 

48 "--verbose"]) 

49 

50 

51if __name__ == "__main__": # pragma: no cover 

52 unittest.main()