def test_merge_local_user_manifest_no_changes_in_diverged_placeholder( gen_date, alice, alice2, with_ignored_changes): w1 = WorkspaceEntry.new(name="w1") d1, d2, d3, d4 = [gen_date() for _ in range(4)] base = UserManifest( author=alice.device_id, timestamp=d2, id=alice.user_manifest_id, version=1, created=d1, updated=d2, last_processed_message=0, workspaces=(w1, ), ) diverged = LocalUserManifest.from_remote(base) if with_ignored_changes: diverged = diverged.evolve(updated=d4, need_sync=True) target = UserManifest( author=alice2.device_id, timestamp=d2, id=alice2.user_manifest_id, version=2, created=d1, updated=d3, last_processed_message=0, workspaces=(w1, ), ) expected_merged = LocalUserManifest.from_remote(target) merged = merge_local_user_manifests(diverged, target) assert merged == expected_merged
async def test_sync(running_backend, alice2_user_fs, alice2): with freeze_time("2000-01-02"): wid = await alice2_user_fs.workspace_create("w1") with freeze_time("2000-01-03"): await alice2_user_fs.sync() um = alice2_user_fs.get_user_manifest() expected_base_um = UserManifest( author=alice2.device_id, timestamp=datetime(2000, 1, 3), id=alice2.user_manifest_id, version=2, created=datetime(2000, 1, 1), updated=datetime(2000, 1, 2), last_processed_message=0, workspaces=(WorkspaceEntry( name="w1", id=wid, key=ANY, encryption_revision=1, encrypted_on=datetime(2000, 1, 2), role_cached_on=datetime(2000, 1, 2), role=WorkspaceRole.OWNER, ), ), ) expected_um = LocalUserManifest.from_remote(expected_base_um) assert um == expected_um
def _generate_or_retrieve_user_manifest_v1(self, device): try: return self._v1[(device.organization_id, device.user_id)] except KeyError: now = pendulum.now() remote_user_manifest = UserManifest( author=device.device_id, timestamp=now, id=device.user_manifest_id, version=1, created=now, updated=now, last_processed_message=0, workspaces=(), ) local_user_manifest = LocalUserManifest.from_remote( remote_user_manifest) self._v1[(device.organization_id, device.user_id)] = ( remote_user_manifest, local_user_manifest, ) return self._v1[(device.organization_id, device.user_id)]