Esempio n. 1
0
def test_nothing_to_sync_from_clean_state(adapter_mock, workerpool_mock,
                                          connection_lifekeeper,
                                          disconnectedstate_cls_mock,
                                          downloadstate_cls_mock):

    from filerockclient.serversession.states.register import StateRegister
    from FileRockSharedLibraries.Communication.Messages import SYNC_FILES_LIST

    components = setup_server_session(__file__, adapter_mock, workerpool_mock,
                                      connection_lifekeeper,
                                      disconnectedstate_cls_mock,
                                      downloadstate_cls_mock)

    # Note: the StateRegister singleton has been initialized by
    # ServerSession's constructor
    syncstart_state = StateRegister.get('SyncStartState')

    def terminate():
        components['real']['server_session'].terminate()
        return syncstart_state

    # DisconnectedState is the default initial state, but we want to start
    # from SyncStartState
    disconnected_state_mock = disconnectedstate_cls_mock()
    disconnected_state_mock.do_execute.return_value = syncstart_state

    # Stop the test when we get to SyncDownloadingLeavesState
    download_state_mock = downloadstate_cls_mock()
    download_state_mock.do_execute.side_effect = terminate

    # There is nothing in the warebox
    components['mock']['warebox'].get_content.return_value = []

    # Send ServerSession a scenario with no data on the storage.
    components['real']['metadata'].set('trusted_basis', 'TRUSTEDBASIS')
    msg = SYNC_FILES_LIST(
        'SYNC_FILES_LIST', {
            'basis': 'TRUSTEDBASIS',
            'dataset': [],
            'last_commit_client_id': '0',
            'last_commit_client_hostname': 'myhostname',
            'last_commit_client_platform': 'myplatform',
            'last_commit_timestamp': 'mytimestamp',
            'user_quota': '0',
            'used_space': '100'
        })
    components['real']['input_queue'].put(msg, 'servermessage')

    components['real']['server_session'].start()
    components['real']['server_session'].join()

    # No data on the storage, in the warebox or in the storage cache.
    # We expect that nothing has happened.
    assert_false(components['mock']['ui_controller'].ask_for_user_input.called)
    assert_equal(components['real']['storage_cache'].get_all_records(), [])
    assert_true(components['real']['input_queue'].empty(['operation']))
def test_nothing_to_sync_from_clean_state(
                        adapter_mock, workerpool_mock, connection_lifekeeper,
                        disconnectedstate_cls_mock, downloadstate_cls_mock):

    from filerockclient.serversession.states.register import StateRegister
    from FileRockSharedLibraries.Communication.Messages import SYNC_FILES_LIST

    components = setup_server_session(
                        __file__,
                        adapter_mock, workerpool_mock, connection_lifekeeper,
                        disconnectedstate_cls_mock, downloadstate_cls_mock)

    # Note: the StateRegister singleton has been initialized by
    # ServerSession's constructor
    syncstart_state = StateRegister.get('SyncStartState')

    def terminate():
        components['real']['server_session'].terminate()
        return syncstart_state

    # DisconnectedState is the default initial state, but we want to start
    # from SyncStartState
    disconnected_state_mock = disconnectedstate_cls_mock()
    disconnected_state_mock.do_execute.return_value = syncstart_state

    # Stop the test when we get to SyncDownloadingLeavesState
    download_state_mock = downloadstate_cls_mock()
    download_state_mock.do_execute.side_effect = terminate

    # There is nothing in the warebox
    components['mock']['warebox'].get_content.return_value = []

    # Send ServerSession a scenario with no data on the storage.
    components['real']['metadata'].set('trusted_basis', 'TRUSTEDBASIS')
    msg = SYNC_FILES_LIST('SYNC_FILES_LIST', {
                'basis': 'TRUSTEDBASIS',
                'dataset': [],
                'last_commit_client_id': '0',
                'last_commit_client_hostname': 'myhostname',
                'last_commit_client_platform': 'myplatform',
                'last_commit_timestamp': 'mytimestamp',
                'user_quota': '0',
                'used_space': '100'
                })
    components['real']['input_queue'].put(msg, 'servermessage')

    components['real']['server_session'].start()
    components['real']['server_session'].join()

    # No data on the storage, in the warebox or in the storage cache.
    # We expect that nothing has happened.
    assert_false(components['mock']['ui_controller'].ask_for_user_input.called)
    assert_equal(components['real']['storage_cache'].get_all(), [])
    assert_true(components['real']['input_queue'].empty(['operation']))
Esempio n. 3
0
def setup_fixtures(adapter_mock, workerpool_mock, connection_lifekeeper,
                   disconnectedstate_cls_mock, downloadstate_cls_mock):

    from filerockclient.serversession.states.register import StateRegister

    components = setup_server_session(__file__, adapter_mock, workerpool_mock,
                                      connection_lifekeeper,
                                      disconnectedstate_cls_mock,
                                      downloadstate_cls_mock)

    # Note: the StateRegister singleton has been initialized by
    # ServerSession's constructor
    syncstart_state = StateRegister.get('SyncStartState')

    # DisconnectedState is the default initial state, but we want to start
    # from SyncStartState
    disconnected_state_mock = disconnectedstate_cls_mock()
    disconnected_state_mock.do_execute.return_value = syncstart_state

    def fail():
        msg = "ServerSession has attempted to start downloading although an" \
              " integrity error was expected"
        assert_true(False, msg)

    # If we get into SyncDownloadingLeavesState, it means we have
    # passed the integrity check. But we shouldn't had to!
    download_state_mock = downloadstate_cls_mock()
    download_state_mock.do_execute.side_effect = fail

    def ask_user(what, content, client_basis, server_basis):
        if what == 'accept_sync':
            msg = "The user has been asked to accept the synchronization" \
              " although an integrity error was expected"
            assert_true(False, msg)
        return 'ok'

    # If the sync dialog is shown to the user, it means we have
    # passed the integrity check. But we shouldn't had to!
    components['mock'][
        'ui_controller'].ask_for_user_input.side_effect = ask_user

    def terminate():
        components['real']['server_session'].terminate()
        return integrity_failure_state

    # If the integrity check fails, it's fine
    integrity_failure_state = StateRegister.get('BasisMismatchState')
    integrity_failure_state.do_execute = MagicMock(side_effect=terminate)
    components['mock']['integrity_failure_state'] = integrity_failure_state
    components['mock']['downloading_state'] = download_state_mock

    return components
def setup_fixtures(adapter_mock, workerpool_mock, connection_lifekeeper,
                   disconnectedstate_cls_mock, downloadstate_cls_mock):

    from filerockclient.serversession.states.register import StateRegister

    components = setup_server_session(
                        __file__,
                        adapter_mock, workerpool_mock, connection_lifekeeper,
                        disconnectedstate_cls_mock, downloadstate_cls_mock)

    # Note: the StateRegister singleton has been initialized by
    # ServerSession's constructor
    syncstart_state = StateRegister.get('SyncStartState')

    # DisconnectedState is the default initial state, but we want to start
    # from SyncStartState
    disconnected_state_mock = disconnectedstate_cls_mock()
    disconnected_state_mock.do_execute.return_value = syncstart_state

    def fail():
        msg = "ServerSession has attempted to start downloading although an" \
              " integrity error was expected"
        assert_true(False, msg)

    # If we get into SyncDownloadingLeavesState, it means we have
    # passed the integrity check. But we shouldn't had to!
    download_state_mock = downloadstate_cls_mock()
    download_state_mock.do_execute.side_effect = fail

    def ask_user(what, content, client_basis, server_basis):
        if what == 'accept_sync':
            msg = "The user has been asked to accept the synchronization" \
              " although an integrity error was expected"
            assert_true(False, msg)
        return 'ok'

    # If the sync dialog is shown to the user, it means we have
    # passed the integrity check. But we shouldn't had to!
    components['mock']['ui_controller'].ask_for_user_input.side_effect = ask_user

    def terminate():
        components['real']['server_session'].terminate()
        return integrity_failure_state

    # If the integrity check fails, it's fine
    integrity_failure_state = StateRegister.get('BasisMismatchState')
    integrity_failure_state.do_execute = MagicMock(side_effect=terminate)
    components['mock']['integrity_failure_state'] = integrity_failure_state
    components['mock']['downloading_state'] = download_state_mock

    return components
def test_download_operations_from_clean_state(
                        adapter_mock, workerpool_mock, connection_lifekeeper,
                        disconnectedstate_cls_mock, downloadstate_cls_mock):

    from filerockclient.serversession.states.register import StateRegister
    from FileRockSharedLibraries.Communication.Messages import SYNC_FILES_LIST
    from filerockclient.interfaces import PStatuses

    components = setup_server_session(
                        __file__,
                        adapter_mock, workerpool_mock, connection_lifekeeper,
                        disconnectedstate_cls_mock, downloadstate_cls_mock)

    # Note: the StateRegister singleton has been initialized by
    # ServerSession's constructor
    syncstart_state = StateRegister.get('SyncStartState')

    def terminate():
        components['real']['server_session'].terminate()
        return syncstart_state

    # DisconnectedState is the default initial state, but we want to start
    # from SyncStartState
    disconnected_state_mock = disconnectedstate_cls_mock()
    disconnected_state_mock.do_execute.return_value = syncstart_state

    # Stop the test when we get to SyncDownloadingLeavesState
    download_state_mock = downloadstate_cls_mock()
    download_state_mock.do_execute.side_effect = terminate

    # There is nothing in the warebox
    components['mock']['warebox'].get_content.return_value = []

    components['real']['metadata'].set('trusted_basis', 'TRUSTEDBASIS')

    # Send ServerSession a scenario with one file to download.
    storage_content = [
        {
            u'key': u'File.txt',
            u'etag': u'"d41d8cd98f00b204e9800998ecf8427e"',
            u'lmtime': u'1970-01-01T10:00:00.000Z',
            u'size': u'1'
        }
    ]
    msg = SYNC_FILES_LIST('SYNC_FILES_LIST', {
                'basis': 'NEWBASIS',
                'dataset': storage_content,
                'last_commit_client_id': '0',
                'last_commit_client_hostname': 'myhostname',
                'last_commit_client_platform': 'myplatform',
                'last_commit_timestamp': 'mytimestamp',
                'user_quota': '0',
                'used_space': '100'
                })
    components['real']['input_queue'].put(msg, 'servermessage')

    def user_accepts_sync(what, content, client_basis, server_basis):
        assert_equal(client_basis, 'TRUSTEDBASIS')
        assert_equal(server_basis, 'NEWBASIS')
        assert_equal(len(content), 1)
        assert_equal(content[0]['pathname'], 'File.txt')
        assert_equal(content[0]['status'], PStatuses.DOWNLOADNEEDED)
        assert_equal(content[0]['size'], 1)
        return 'ok'

    components['mock']['ui_controller'].ask_for_user_input.side_effect = user_accepts_sync

    components['real']['server_session'].start()
    components['real']['server_session'].join()

    # We expect to download a file
    assert_true(components['mock']['ui_controller'].ask_for_user_input.called)
    assert_equal(components['real']['storage_cache'].get_all(), [])
    assert_false(components['real']['input_queue'].empty(['operation']))
    operation, _ = components['real']['input_queue'].get(['operation'])
    assert_equal(operation.pathname, 'File.txt')
    assert_equal(operation.verb, 'DOWNLOAD')
Esempio n. 6
0
def test_download_operations_from_clean_state(adapter_mock, workerpool_mock,
                                              connection_lifekeeper,
                                              disconnectedstate_cls_mock,
                                              downloadstate_cls_mock):

    from filerockclient.serversession.states.register import StateRegister
    from FileRockSharedLibraries.Communication.Messages import SYNC_FILES_LIST
    from filerockclient.interfaces import PStatuses

    components = setup_server_session(__file__, adapter_mock, workerpool_mock,
                                      connection_lifekeeper,
                                      disconnectedstate_cls_mock,
                                      downloadstate_cls_mock)

    # Note: the StateRegister singleton has been initialized by
    # ServerSession's constructor
    syncstart_state = StateRegister.get('SyncStartState')

    def terminate():
        components['real']['server_session'].terminate()
        return syncstart_state

    # DisconnectedState is the default initial state, but we want to start
    # from SyncStartState
    disconnected_state_mock = disconnectedstate_cls_mock()
    disconnected_state_mock.do_execute.return_value = syncstart_state

    # Stop the test when we get to SyncDownloadingLeavesState
    download_state_mock = downloadstate_cls_mock()
    download_state_mock.do_execute.side_effect = terminate

    # There is nothing in the warebox
    components['mock']['warebox'].get_content.return_value = []

    components['real']['metadata'].set('trusted_basis', 'TRUSTEDBASIS')

    # Send ServerSession a scenario with one file to download.
    storage_content = [{
        u'key': u'File.txt',
        u'etag': u'"d41d8cd98f00b204e9800998ecf8427e"',
        u'lmtime': u'1970-01-01T10:00:00.000Z',
        u'size': u'1'
    }]
    msg = SYNC_FILES_LIST(
        'SYNC_FILES_LIST', {
            'basis': 'NEWBASIS',
            'dataset': storage_content,
            'last_commit_client_id': '0',
            'last_commit_client_hostname': 'myhostname',
            'last_commit_client_platform': 'myplatform',
            'last_commit_timestamp': 'mytimestamp',
            'user_quota': '0',
            'used_space': '100'
        })
    components['real']['input_queue'].put(msg, 'servermessage')

    def user_accepts_sync(what, content, client_basis, server_basis):
        assert_equal(client_basis, 'TRUSTEDBASIS')
        assert_equal(server_basis, 'NEWBASIS')
        assert_equal(len(content), 1)
        assert_equal(content[0]['pathname'], 'File.txt')
        assert_equal(content[0]['status'], PStatuses.DOWNLOADNEEDED)
        assert_equal(content[0]['size'], 1)
        return 'ok'

    components['mock'][
        'ui_controller'].ask_for_user_input.side_effect = user_accepts_sync

    components['real']['server_session'].start()
    components['real']['server_session'].join()

    # We expect to download a file
    assert_true(components['mock']['ui_controller'].ask_for_user_input.called)
    assert_equal(components['real']['storage_cache'].get_all_records(), [])
    assert_false(components['real']['input_queue'].empty(['operation']))
    operation, _ = components['real']['input_queue'].get(['operation'])
    assert_equal(operation.pathname, 'File.txt')
    assert_equal(operation.verb, 'DOWNLOAD')