MockRegistryApi¶
-
class
kafkit.registry.sansio.
MockRegistryApi
(url='http://registry:8081', status_code=200, headers=None, body=b'')¶ Bases:
kafkit.registry.sansio.RegistryApi
A mock implementation of the RegistryApi client that doensn’t do network operations and provides attributes for introspection.
Attributes Summary
DEFAULT_HEADERS
schema_cache
The schema cache ( SchemaCache
).subject_cache
The subject cache ( SubjectCache
).Methods Summary
delete
(url[, url_vars, data])Send an HTTP DELETE request. get
(url[, url_vars])Send an HTTP GET request. get_schema_by_id
(schema_id)Get a schema from the registry given its ID. get_schema_by_subject
(subject[, version])Get a schema for a subject in the registry. patch
(url[, url_vars])Send an HTTP PATCH request. post
(url[, url_vars])Send an HTTP POST request. put
(url[, url_vars, data])Send an HTTP PUT request. register_schema
(schema[, subject])Register a schema or get the ID of an existing schema. Attributes Documentation
-
DEFAULT_HEADERS
= {'content-type': 'application/vnd.schemaregistry.v1+json'}¶
-
schema_cache
¶ The schema cache (
SchemaCache
).
-
subject_cache
¶ The subject cache (
SubjectCache
).
Methods Documentation
-
delete
(url, url_vars={}, *, data=b'')¶ Send an HTTP DELETE request.
Parameters: - url :
str
The endpoint path, usually relative to the
RegistryApi.url
attribute (an absolute URL is also okay). The url can be templated (/a{/b}/c
, whereb
is a variable).- url_vars :
dict
, optional A dictionary of variable names and values to expand the templated
url
parameter.- data : object, optional
The body of the request as a JSON-serializable object.
Returns: - data
The response body. If the response is JSON, the data is parsed into a Python object.
Raises: - kafkit.registry.RegistryRedirectionError
Raised if the server returns a 3XX status.
- kafkit.registry.RegistryRadRequestError
Raised if the server returns a 4XX status because the request is incorrect, not authenticated, or not authorized.
- kafkit.registry.RegistryBrokenError
Raised if the server returns a 5XX status because something is wrong with the server itself.
- url :
-
get
(url, url_vars={})¶ Send an HTTP GET request.
Parameters: Returns: - data
The response body. If the response is JSON, the data is parsed into a Python object.
Raises: - kafkit.registry.RegistryRedirectionError
Raised if the server returns a 3XX status.
- kafkit.registry.RegistryRadRequestError
Raised if the server returns a 4XX status because the request is incorrect, not authenticated, or not authorized.
- kafkit.registry.RegistryBrokenError
Raised if the server returns a 5XX status because something is wrong with the server itself.
-
get_schema_by_id
(schema_id)¶ Get a schema from the registry given its ID.
Wraps
GET /schemas/ids/{int: id}
.Parameters: - schema_id :
int
The ID of the schema in the registry.
Returns: - schema :
dict
The Avro schema. The schema is pre-parsed by
fastavro.parse_schema
.
See also
Notes
The schema and ID are cached locally so that repeated calls are fast. This cache is shared by other high-level methods, like
register_schema
.- schema_id :
-
get_schema_by_subject
(subject, version='latest')¶ Get a schema for a subject in the registry.
Wraps
GET /subjects/(string: subject)/versions/(versionId: version)
Parameters: Returns: - schema_info :
dict
A dictionary with the schema and metadata about the schema. The keys are:
"schema"
The schema itself, preparsed by
fastavro.parse_schema
."subject"
The subject this schema is registered under in the registry.
"version"
The version of this schema with respect to the
subject
."id"
The ID of this schema (compatible with
get_schema_by_id
).
See also
Notes
Results from this method are cached locally, so repeated calls are fast. Keep in mind that any call with the
version
parameter set to"latest"
will always miss the cache. The schema is still cached, though, under it’s true subject version. If you app repeatedly calls this method, and you want to make use of caching, replace"latest"
versions with integer versions once they’re known.- schema_info :
-
patch
(url, url_vars={}, *, data)¶ Send an HTTP PATCH request.
Parameters: - url :
str
The endpoint path, usually relative to the
RegistryApi.url
attribute (an absolute URL is also okay). The url can be templated (/a{/b}/c
, whereb
is a variable).- url_vars :
dict
, optional A dictionary of variable names and values to expand the templated
url
parameter.- data : object
The body of the request as a JSON-serializable object.
Returns: - data
The response body. If the response is JSON, the data is parsed into a Python object.
Raises: - kafkit.registry.RegistryRedirectionError
Raised if the server returns a 3XX status.
- kafkit.registry.RegistryRadRequestError
Raised if the server returns a 4XX status because the request is incorrect, not authenticated, or not authorized.
- kafkit.registry.RegistryBrokenError
Raised if the server returns a 5XX status because something is wrong with the server itself.
- url :
-
post
(url, url_vars={}, *, data)¶ Send an HTTP POST request.
Parameters: - url :
str
The endpoint path, usually relative to the
RegistryApi.url
attribute (an absolute URL is also okay). The url can be templated (/a{/b}/c
, whereb
is a variable).- url_vars :
dict
, optional A dictionary of variable names and values to expand the templated
url
parameter.- data : object
The body of the request as a JSON-serializable object.
Returns: - data
The response body. If the response is JSON, the data is parsed into a Python object.
Raises: - kafkit.registry.RegistryRedirectionError
Raised if the server returns a 3XX status.
- kafkit.registry.RegistryRadRequestError
Raised if the server returns a 4XX status because the request is incorrect, not authenticated, or not authorized.
- kafkit.registry.RegistryBrokenError
Raised if the server returns a 5XX status because something is wrong with the server itself.
- url :
-
put
(url, url_vars={}, data=b'')¶ Send an HTTP PUT request.
Parameters: - url :
str
The endpoint path, usually relative to the
RegistryApi.url
attribute (an absolute URL is also okay). The url can be templated (/a{/b}/c
, whereb
is a variable).- url_vars :
dict
, optional A dictionary of variable names and values to expand the templated
url
parameter.- data : object, optional
The body of the request as a JSON-serializable object.
Returns: - data
The response body. If the response is JSON, the data is parsed into a Python object.
Raises: - kafkit.registry.RegistryRedirectionError
Raised if the server returns a 3XX status.
- kafkit.registry.RegistryRadRequestError
Raised if the server returns a 4XX status because the request is incorrect, not authenticated, or not authorized.
- kafkit.registry.RegistryBrokenError
Raised if the server returns a 5XX status because something is wrong with the server itself.
- url :
-
register_schema
(schema, subject=None)¶ Register a schema or get the ID of an existing schema.
Wraps
POST /subjects/(string: subject)/versions
.Parameters: - schema :
dict
An Avro schema as a Python dictionary.
- subject :
str
, optional The subject to register the schema under. If not provided, the fully-qualified name of the schema is adopted as the subject name.
Returns: - schema_id :
int
The ID of the schema in the registry.
Notes
The schema and ID are cached locally so that repeated calls are fast. This cache is shared by other high-level methods, like
get_schema_by_id
.- schema :
-