Skip to content

Commit

Permalink
Merge pull request #45 from jan-janssen/more_tests
Browse files Browse the repository at this point in the history
Add more unit tests
  • Loading branch information
jan-janssen committed Jul 4, 2023
2 parents 5384afc + 28ef007 commit 03d6bdc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
9 changes: 6 additions & 3 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ class TestCore(unittest.TestCase):
def setUpClass(cls):
cls.qr_code_png = "test.png"
cls.config_dict = {
"test": "otpauth://totp/Test%3A%20root%40github.com?secret=6IQXETC4ADOSMMUN&issuer=Test&period=60"
"test": "otpauth://totp/Test%3A%20root%40github.com?secret=6IQXETC4ADOSMMUN&issuer=Test&period=60&digits=6",
"test2": "otpauth://totp/Test%3A%20root%40github.com?secret=6IQXETC4ADOSMMUN"
}
generate_qrcode(
key="test",
Expand All @@ -32,7 +33,7 @@ def tearDownClass(cls):

def test_list_services(self):
service_lst = list_services(config_dict=self.config_dict)
self.assertEqual(["test"], service_lst)
self.assertEqual(["test", "test2"], service_lst)

def test_add_service(self):
config_file = "test_config.json"
Expand All @@ -43,12 +44,14 @@ def test_add_service(self):
config_file_to_write=config_file
)
config_reload = load_config(config_file_to_load=config_file)
self.assertDictEqual(config_reload, self.config_dict)
self.assertEqual(config_reload["test"], self.config_dict["test"])
os.remove(config_file)

def test_get_two_factor_code(self):
code = get_two_factor_code(key="test", config_dict=self.config_dict)
self.assertEqual(len(code), 6)
code = get_two_factor_code(key="test2", config_dict=self.config_dict)
self.assertEqual(len(code), 6)


if __name__ == '__main__':
Expand Down
4 changes: 4 additions & 0 deletions tests/test_share.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ def test_config(self):
)
self.assertDictEqual(test_no_dict, {})
os.remove(test_file_name)
test_dict_reload = load_config(
config_file_to_load=test_file_name
)
self.assertDictEqual({}, test_dict_reload)

def test_get_otpauth_dict(self):
otpauth_str = "otpauth://totp/Test%3A%20root%40github.com?secret=MAGICSECRET&issuer=Test"
Expand Down

0 comments on commit 03d6bdc

Please sign in to comment.