Esempio n. 1
0
 def test_main_configures_logger_with_stream_handler_debug_level_on_verbose(
         self):
     main(['--verbose', 'verify', 'testuser', 'testpassword']),
     self.assertEqual(self.mock_logger.addHandler.call_count, 1)
     handler = self.mock_logger.addHandler.call_args[0][0]
     self.assertIsInstance(handler, StreamHandler)
     self.assertEqual(handler.level, DEBUG)
Esempio n. 2
0
 def test_main_calls_enable_user_on_enable_action_returns_the_result(self):
     self.assertEqual(main(['enable', '--ignore-missing', 'testuser']),
                      EX_OK)
     self.assertTrue(self.mock_enable.called)
     auth, user, ignore_missing = self.mock_enable.call_args[0]
     self.assertEqual(user, 'testuser')
     self.assertTrue(ignore_missing)
     self.assertIsInstance(auth, MiniAuth)
Esempio n. 3
0
 def test_main_calls_verify_on_verify_action_returns_the_result(self):
     self.assertEqual(main(['verify', 'testuser', 'testpassword']),
                      EX_VERIFYFAILD)
     self.assertTrue(self.mock_verify.called)
     auth, opts = self.mock_verify.call_args[0]
     self.assertEqual(opts.user, 'testuser')
     self.assertEqual(opts.password, 'testpassword')
     self.assertIsInstance(auth, MiniAuth)
Esempio n. 4
0
    def test_main_configures_logger_with_log_handler_debug_level_also_when_log_set(
            self):
        mock_file_handler = Mock()
        patched_file_handler = self.patch('miniauth.main.FileHandler')
        patched_file_handler.return_value = mock_file_handler

        main([
            '--log', '/tmp/testminiauthlog.txt', 'verify', 'testuser',
            'testpassword'
        ]),

        self.assertEqual(self.mock_logger.addHandler.call_count, 2)
        self.assertEqual(self.mock_logger.addHandler.call_args_list[0][0][0],
                         mock_file_handler)
        mock_file_handler.setLevel.assert_called_once_with(DEBUG)
        stream_handler = self.mock_logger.addHandler.call_args_list[1][0][0]
        self.assertIsInstance(stream_handler, StreamHandler)
        self.assertEqual(stream_handler.level, INFO)
Esempio n. 5
0
 def test_main_prompts_password_if_password_is_not_set(self):
     self.assertEqual(main(['save', 'testuser']), EX_OK)
     self.assertTrue(self.mock_getpass.called)
     self.assertTrue(self.mock_save.called)
     auth, user, password, hash_, force = self.mock_save.call_args[0]
     self.assertEqual(user, 'testuser')
     self.assertEqual(password, 'fromgetpass')
     self.assertFalse(force)
     self.assertEqual(hash_, 'sha512')
     self.assertIsInstance(auth, MiniAuth)
Esempio n. 6
0
 def test_main_calls_save_user_on_save_action_returns_the_result(self):
     self.assertEqual(
         main([
             'save', '-p', 'testpassword', '--force', '--hash', 'sha256',
             'testuser'
         ]), EX_OK)
     self.assertTrue(self.mock_save.called)
     auth, user, password, hash_, force = self.mock_save.call_args[0]
     self.assertEqual(user, 'testuser')
     self.assertEqual(password, 'testpassword')
     self.assertTrue(force)
     self.assertEqual(hash_, 'sha256')
     self.assertIsInstance(auth, MiniAuth)
Esempio n. 7
0
 def test_main_configures_logger_with_null_handler_in_quiet_mode(self):
     main(['--quiet', 'verify', 'testuser', 'testpassword']),
     self.assertEqual(self.mock_logger.addHandler.call_count, 1)
     handler = self.mock_logger.addHandler.call_args[0][0]
     self.assertIsInstance(handler, NullHandler)
Esempio n. 8
0
 def test_main_configures_logger_with_stream_handler_by_default(self):
     main(['verify', 'testuser', 'testpassword']),
     self.assertEqual(self.mock_logger.addHandler.call_count, 1)
     handler = self.mock_logger.addHandler.call_args[0][0]
     self.assertIsInstance(handler, StreamHandler)
     self.assertEqual(handler.level, INFO)