Ejemplo n.º 1
0
def test_Client_login(safe_tmpdir):
    """
    Ensures the API is called in the expected manner for logging in the user
    given the username, password and 2fa token.
    """
    mock_gui = mock.MagicMock()
    mock_session = mock.MagicMock()
    cl = Client('http://localhost', mock_gui, mock_session, str(safe_tmpdir))
    cl.call_api = mock.MagicMock()
    with mock.patch('securedrop_client.logic.sdclientapi.API') as mock_api:
        cl.login('username', 'password', '123456')
        cl.call_api.assert_called_once_with(mock_api().authenticate,
                                            cl.on_authenticate,
                                            cl.on_login_timeout)
def test_Client_login(homedir, config, mocker):
    """
    Ensures the API is called in the expected manner for logging in the user
    given the username, password and 2fa token.
    Using the `config` fixture to ensure the config is written to disk.
    """
    mock_gui = mocker.MagicMock()
    mock_session = mocker.MagicMock()
    cl = Client('http://localhost', mock_gui, mock_session, homedir)
    cl.call_api = mocker.MagicMock()
    mock_api = mocker.patch('securedrop_client.logic.sdclientapi.API')
    cl.login('username', 'password', '123456')
    cl.call_api.assert_called_once_with(mock_api().authenticate,
                                        cl.on_authenticate,
                                        cl.on_login_timeout)