Coverage for tests/admin/test_lbutils.py: 100%

42 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2024-04-05 20:41 +0000

1# The MIT License (MIT) 

2# 

3# Copyright (c) 2021 RSK Labs Ltd 

4# 

5# Permission is hereby granted, free of charge, to any person obtaining a copy of 

6# this software and associated documentation files (the "Software"), to deal in 

7# the Software without restriction, including without limitation the rights to 

8# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 

9# of the Software, and to permit persons to whom the Software is furnished to do 

10# so, subject to the following conditions: 

11# 

12# The above copyright notice and this permission notice shall be included in all 

13# copies or substantial portions of the Software. 

14# 

15# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 

16# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 

17# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 

18# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 

19# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 

20# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 

21# SOFTWARE. 

22 

23from unittest import TestCase 

24from unittest.mock import call, patch 

25from lbutils import main 

26 

27import logging 

28 

29logging.disable(logging.CRITICAL) 

30 

31 

32@patch("runpy.run_module") 

33class TestLbutils(TestCase): 

34 def test_load(self, run_module): 

35 with patch('sys.argv', ['lbutils.py', 'load']): 

36 with self.assertRaises(SystemExit) as e: 

37 main() 

38 

39 self.assertTrue(run_module.called) 

40 self.assertEqual([call('ledgerblue.loadApp', run_name='__main__')], 

41 run_module.call_args_list) 

42 self.assertEqual(e.exception.code, 0) 

43 

44 def test_delete(self, run_module): 

45 with patch('sys.argv', ['lbutils.py', 'delete']): 

46 with self.assertRaises(SystemExit) as e: 

47 main() 

48 

49 self.assertTrue(run_module.called) 

50 self.assertEqual([call('ledgerblue.deleteApp', run_name='__main__')], 

51 run_module.call_args_list) 

52 self.assertEqual(e.exception.code, 0) 

53 

54 def test_setup_ca(self, run_module): 

55 with patch('sys.argv', ['lbutils.py', 'setupCA']): 

56 with self.assertRaises(SystemExit) as e: 

57 main() 

58 

59 self.assertTrue(run_module.called) 

60 self.assertEqual([call('ledgerblue.setupCustomCA', run_name='__main__')], 

61 run_module.call_args_list) 

62 self.assertEqual(e.exception.code, 0) 

63 

64 def test_reset_ca(self, run_module): 

65 with patch('sys.argv', ['lbutils.py', 'resetCA']): 

66 with self.assertRaises(SystemExit) as e: 

67 main() 

68 

69 self.assertTrue(run_module.called) 

70 self.assertEqual([call('ledgerblue.resetCustomCA', run_name='__main__')], 

71 run_module.call_args_list) 

72 self.assertEqual(e.exception.code, 0) 

73 

74 def test_gen_ca(self, run_module): 

75 with patch('sys.argv', ['lbutils.py', 'genCA']): 

76 with self.assertRaises(SystemExit) as e: 

77 main() 

78 

79 self.assertTrue(run_module.called) 

80 self.assertEqual([call('ledgerblue.genCAPair', run_name='__main__')], 

81 run_module.call_args_list) 

82 self.assertEqual(e.exception.code, 0)