def test_Client_authenticated_no_api(safe_tmpdir): """ If the API is authenticated return True. """ mock_gui = mock.MagicMock() mock_session = mock.MagicMock() cl = Client('http://localhost', mock_gui, mock_session, str(safe_tmpdir)) cl.api = None assert cl.authenticated() is False
def test_Client_authenticated_yes(safe_tmpdir): """ If the API is authenticated return True. """ mock_gui = mock.MagicMock() mock_session = mock.MagicMock() cl = Client('http://localhost', mock_gui, mock_session, str(safe_tmpdir)) cl.api = mock.MagicMock() cl.api.token = {'token': 'foo'} assert cl.authenticated() is True
def test_Client_authenticated_no_api(homedir, config, mocker): """ If the API is authenticated return True. 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.api = None assert cl.authenticated() is False
def test_Client_authenticated_no(): """ If the API is authenticated return True. """ mock_gui = mock.MagicMock() mock_session = mock.MagicMock() cl = Client('http://localhost', mock_gui, mock_session) cl.api = mock.MagicMock() cl.api.token = {'token': ''} assert cl.authenticated() is False
def test_Client_sync_api_not_authenticated(safe_tmpdir): """ If the API isn't authenticated, don't sync. """ mock_gui = mock.MagicMock() mock_session = mock.MagicMock() cl = Client('http://localhost', mock_gui, mock_session, str(safe_tmpdir)) cl.authenticated = mock.MagicMock(return_value=False) cl.call_api = mock.MagicMock() cl.sync_api() assert cl.call_api.call_count == 0
def test_Client_sync_api(safe_tmpdir): """ Sync the API is authenticated. """ mock_gui = mock.MagicMock() mock_session = mock.MagicMock() cl = Client('http://localhost', mock_gui, mock_session, str(safe_tmpdir)) cl.authenticated = mock.MagicMock(return_value=True) cl.call_api = mock.MagicMock() cl.sync_api() cl.call_api.assert_called_once_with(storage.get_remote_data, cl.on_synced, cl.on_sync_timeout, cl.api)
def test_Client_sync_api_not_authenticated(homedir, config, mocker): """ If the API isn't authenticated, don't sync. 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.authenticated = mocker.MagicMock(return_value=False) cl.call_api = mocker.MagicMock() cl.sync_api() assert cl.call_api.call_count == 0
def test_Client_sync_api(homedir, config, mocker): """ Sync the API is authenticated. 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.authenticated = mocker.MagicMock(return_value=True) cl.call_api = mocker.MagicMock() cl.sync_api() cl.call_api.assert_called_once_with(storage.get_remote_data, cl.on_synced, cl.on_sync_timeout, cl.api)