|
| 1 | +import unittest |
| 2 | +import os |
| 3 | +import subprocess |
| 4 | +import json |
| 5 | +from pyauthenticator.share import expand_path, write_config, config_file |
| 6 | + |
| 7 | + |
| 8 | +class MyTestCase(unittest.TestCase): |
| 9 | + @classmethod |
| 10 | + def setUpClass(cls): |
| 11 | + cls.config_dict = { |
| 12 | + "test": "otpauth://totp/Test%3A%20root%40github.com?secret=6IQXETC4ADOSMMUN&issuer=Test" |
| 13 | + } |
| 14 | + cls.config_path = expand_path(config_file) |
| 15 | + if not os.path.exists(cls.config_path): |
| 16 | + write_config( |
| 17 | + config_dict=cls.config_dict |
| 18 | + ) |
| 19 | + |
| 20 | + def test_main_generate_two_factor(self): |
| 21 | + code = subprocess.check_output( |
| 22 | + ["coverage", "run", "-a", "pyauthenticator", "test"], |
| 23 | + universal_newlines=True |
| 24 | + ) |
| 25 | + self.assertEqual(len(code.replace("\n", "")), 6) |
| 26 | + |
| 27 | + def test_main_generate_qr_code(self): |
| 28 | + subprocess.check_output( |
| 29 | + ["coverage", "run", "-a", "pyauthenticator", "-qr", "test"], |
| 30 | + universal_newlines=True |
| 31 | + ) |
| 32 | + self.assertTrue(os.path.exists("test.png")) |
| 33 | + subprocess.check_output( |
| 34 | + ["coverage", "run", "-a", "pyauthenticator", "-a", "test.png", "test2"], |
| 35 | + universal_newlines=True |
| 36 | + ) |
| 37 | + with open(self.config_path, "r") as f: |
| 38 | + config_dict = json.load(f) |
| 39 | + self.assertEqual(len(config_dict.keys()), 2) |
| 40 | + |
| 41 | + |
| 42 | +if __name__ == '__main__': |
| 43 | + unittest.main() |
0 commit comments