Пример #1
0
 def test_verify_user_from_opts_prompts_password_if_password_empty(self):
     self.opts.password = ''
     verify_user_from_opts(self.mock_auth, self.opts)
     self.assertFalse(self.mock_prompt.called)
     self.assertTrue(self.mock_getpass.called)
     self.mock_verify.assert_called_once_with(self.mock_auth, 'testuser',
                                              'fromgetpass')
Пример #2
0
    def test_verify_user_from_opts_raises_valerr_when_passowrd_is_empty_in_opts_and_passfile(
            self):
        self.opts.password_file = '/tmp/password_file'
        self.opts.password = ''
        self.mock_read_lines.return_value = ['']

        with self.assertRaises(ValueError):
            verify_user_from_opts(self.mock_auth, self.opts)
Пример #3
0
    def test_verify_user_from_opts_raises_valerr_when_user_is_empty_in_opts_and_creds_file(
            self):
        self.opts.creds_file = '/tmp/creds_file'
        self.opts.user = ''
        self.mock_read_lines.return_value = ['', 'passline']

        with self.assertRaises(ValueError):
            verify_user_from_opts(self.mock_auth, self.opts)
Пример #4
0
    def test_verify_user_from_opts_reads_password_from_password_file_if_password_empty(
            self):
        self.opts.password_file = '/tmp/password_file'
        self.opts.password = ''
        self.mock_read_lines.return_value = ['passline']

        verify_user_from_opts(self.mock_auth, self.opts)

        self.mock_read_lines.assert_called_once_with('/tmp/password_file', 1)
        self.assertFalse(self.mock_prompt.called)
        self.assertFalse(self.mock_getpass.called)
        self.mock_verify.assert_called_once_with(self.mock_auth, 'testuser',
                                                 'passline')
Пример #5
0
 def test_verify_user_from_opts_gets_user_password_from_opts_calls_verify(
         self):
     self.assertEqual(verify_user_from_opts(self.mock_auth, self.opts),
                      EX_OK)
     self.mock_verify.assert_called_once_with(self.mock_auth, 'testuser',
                                              'testpassword')
     self.assertFalse(self.mock_prompt.called)
     self.assertFalse(self.mock_getpass.called)
     self.assertFalse(self.mock_read_lines.called)