Skip to content

Instantly share code, notes, and snippets.

@jonathansick
Created August 15, 2019 20:34
Show Gist options
  • Save jonathansick/55da98366712cd77b897b498e565f154 to your computer and use it in GitHub Desktop.
Save jonathansick/55da98366712cd77b897b498e565f154 to your computer and use it in GitHub Desktop.
Using the MockRegistryApi
# In unit tests =====================================
from kafkit.registry.sansio import MockRegistryApi
# The Avro schema that you'll be testing with
schema = {}
# The MockRegistryApi works just like the RegistryApi, but doesn't
# do any network requests.
registryclient = MockRegistryApi()
# Insert the schema you know you're using into the client's
# cache. The `1` is just the unique ID that the Confluent Schema
# Registry server would have assigned to it.
registryclient.schemas.insert(schema, 1)
# In the application code =============================
# Now you can pass this registryclient into the code being
# tested and it will work without any network I/O.
# The serializer can now use this registry. When it does
serializer = await Serializer.register(
registry=client,
schema=schema)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment