Example #1
0
def test_state_rename2(mock_provider):
    providers = (mock_provider, mock_provider)
    state = SyncState(providers, shuffle=True)
    state.update(LOCAL, FILE, path="foo", oid="123", hash=b"foo")
    assert state.lookup_path(LOCAL, path="foo")
    assert state.lookup_oid(LOCAL, "123")
    state.update(LOCAL, FILE, path="foo2", oid="456", prior_oid="123")
    assert state.lookup_path(LOCAL, path="foo2")
    assert state.lookup_oid(LOCAL, "456")
    assert not state.lookup_path(LOCAL, path="foo")
    assert state.lookup_oid(LOCAL, oid="456")
    assert not state.lookup_oid(LOCAL, oid="123")
    state.assert_index_is_correct()
Example #2
0
def test_state_alter_oid(mock_provider):
    providers = (mock_provider, mock_provider)
    state = SyncState(providers, shuffle=True)
    state.update(LOCAL, FILE, path="123", oid="123", hash="123")
    ent1 = state.lookup_oid(LOCAL, "123")
    assert ent1 in state.changes
    state.update(LOCAL, FILE, path="456", oid="456", hash="456")
    ent2 = state.lookup_oid(LOCAL, "456")
    assert ent2[LOCAL].changed
    assert ent2 in state.changes
    ent1[LOCAL].oid = "456"
    assert state.lookup_oid(LOCAL, "456") is ent1
    assert state.lookup_oid(LOCAL, "123") is None
    assert ent2 not in state.get_all()
    ent1[LOCAL].oid = "456"
    ent2[LOCAL].oid = "123"
    assert ent2[LOCAL].changed
    assert state.lookup_oid(LOCAL, "123") is ent2
    assert ent2 in state.changes
Example #3
0
def test_state_storage_corrupt_input(mock_provider):
    providers = (mock_provider, mock_provider)
    backend: Dict[Any, Any] = {}
    storage = MockStorage(backend)
    state = SyncState(providers, storage, tag="whatever")
    state.update(LOCAL, FILE, path="123", oid="123", hash=b"123")
    state.update(LOCAL, FILE, path="456", oid="456", hash=b"456")
    state.storage_commit()

    tag = state._tag
    eid = state.lookup_oid(LOCAL, "123").storage_id
    state._storage.update(tag, b"crappy bad stuff", eid)

    state2 = SyncState(providers, storage, tag="whatever")

    # 123 record was corrupt, but 456 is still cool
    assert not state2.lookup_oid(LOCAL, "123")
    assert state2.lookup_oid(LOCAL, "456")
Example #4
0
def test_state_split(mock_provider):
    # annoyingly, the state manager now interacts with the provider
    # this means that the state manager needs to know how to get an oid

    # TODO: make a layer that knows about providers and state, and ANOTHER layer that just knows about state
    # that way we can go back to have a pure state/storage manager

    providers = (mock_provider, mock_provider)
    state = SyncState(providers, shuffle=True)

    state.update(LOCAL, DIRECTORY, path="/dir", oid="123")

    ent = state.lookup_oid(LOCAL, "123")

    # oid/path updated
    ent[REMOTE].oid = "999"
    ent[REMOTE].path = "/rem"

    assert state.lookup_oid(LOCAL, "123")
    assert state.lookup_path(LOCAL, "/dir")

    assert state.lookup_path(REMOTE, "/rem")
    assert state.lookup_oid(REMOTE, "999")

    (defer, _ds, repl, _rs) = state.split(ent)

    assert state.lookup_oid(LOCAL, "123") is repl
    assert state.lookup_path(LOCAL, "/dir")

    assert state.lookup_path(REMOTE, "/rem")
    assert state.lookup_oid(REMOTE, "999") is defer

    state.assert_index_is_correct()