def test_Client_update_sync(safe_tmpdir):
    """
    Cause the UI to update with the result of self.last_sync().
    """
    mock_gui = mock.MagicMock()
    mock_session = mock.MagicMock()
    cl = Client('http://localhost', mock_gui, mock_session, str(safe_tmpdir))
    cl.last_sync = mock.MagicMock()
    cl.update_sync()
    assert cl.last_sync.call_count == 1
    cl.gui.show_sync.assert_called_once_with(cl.last_sync())
def test_Client_update_sync(homedir, config, mocker):
    """
    Cause the UI to update with the result of self.last_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.last_sync = mocker.MagicMock()
    cl.update_sync()
    assert cl.last_sync.call_count == 1
    cl.gui.show_sync.assert_called_once_with(cl.last_sync())
def test_Client_last_sync_no_file(safe_tmpdir):
    """
    If there's no sync file, then just return None.
    """
    mock_gui = mock.MagicMock()
    mock_session = mock.MagicMock()
    cl = Client('http://localhost', mock_gui, mock_session, str(safe_tmpdir))
    with mock.patch("builtins.open", mock.MagicMock(side_effect=Exception())):
        assert cl.last_sync() is None
def test_Client_last_sync_no_file(homedir, config, mocker):
    """
    If there's no sync file, then just return None.
    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)
    mocker.patch("builtins.open", mocker.MagicMock(side_effect=Exception()))
    assert cl.last_sync() is None
def test_Client_last_sync_with_file(safe_tmpdir):
    """
    The flag indicating the time of the last sync with the API is stored in a
    dotfile in the user's home directory. If such a file exists, ensure an
    "arror" object (representing the date/time) is returned.
    """
    mock_gui = mock.MagicMock()
    mock_session = mock.MagicMock()
    cl = Client('http://localhost', mock_gui, mock_session, str(safe_tmpdir))
    timestamp = '2018-10-10 18:17:13+01:00'
    with mock.patch("builtins.open", mock.mock_open(read_data=timestamp)):
        result = cl.last_sync()
        assert isinstance(result, arrow.Arrow)
        assert result.format() == timestamp
def test_Client_last_sync_with_file(homedir, config, mocker):
    """
    The flag indicating the time of the last sync with the API is stored in a
    dotfile in the user's home directory. If such a file exists, ensure an
    "arrow" object (representing the date/time) is returned.
    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)
    timestamp = '2018-10-10 18:17:13+01:00'
    mocker.patch("builtins.open", mocker.mock_open(read_data=timestamp))
    result = cl.last_sync()
    assert isinstance(result, arrow.Arrow)
    assert result.format() == timestamp