Test code that uses calendaring-sync#

The parts of your application that read records and the change feed don’t need a server in their tests. Ingest what a server would send, and the replica reaches the state your code then reads.

from calendaring_sync import Changed, ChangeSet, MemoryStore, Removed, Replica


def server_sends(replica, since, token, changes, *, full_listing=False):
    """Ingest what a server would have sent for the "work" scope."""
    with replica.session("work", fingerprint_scheme="test", media_type="text/plain") as session:
        session.ingest(ChangeSet("work", since, token, changes, full_listing=full_listing))


replica = Replica(MemoryStore())
server_sends(replica, None, "t1", {"a": Changed("v1", "a1", b"Team meeting")}, full_listing=True)
server_sends(replica, "t1", "t2", {"a": Changed("v2", "a2", b"Team meeting, moved")})
server_sends(replica, "t2", "t3", {"a": Removed()})

Each ChangeSet is the change set an adapter would hand the core, so the replica ends up exactly as a real sync would leave it. A new MemoryStore starts empty, so each test begins from nothing. Your test then checks what your code made of it:

from calendaring_sync import FeedEntryKind

kinds = [entry.kind for entry in replica.read_feed()]
assert kinds == [FeedEntryKind.CHANGED, FeedEntryKind.CHANGED, FeedEntryKind.REMOVED]

To test your application’s edits, and a server’s answers to them, write a small adapter instead, as Write an adapter shows. The examples on these pages run on one.

Last updated on 2026-10-27.