minos.aggregate.testing.snapshots.repositories.testcases
Classes
- class SnapshotRepositoryTestCase[source]
Bases:
MinosTestCase
,ABC
- snapshot_repository: SnapshotRepository
- class Owner[source]
Bases:
RootEntity
For testing purposes
- __init__(*args, uuid=NULL_UUID, version=0, created_at=NULL_DATETIME, updated_at=NULL_DATETIME, _event_repository, _snapshot_repository, **kwargs)
Class constructor.
- Parameters
kwargs – Named arguments to be set as model attributes.
uuid (UUID) –
version (int) –
created_at (datetime) –
updated_at (datetime) –
_event_repository (EventRepository) –
_snapshot_repository (SnapshotRepository) –
- apply_diff(event)
Apply the differences over the instance.
- Parameters
event (Event) – The
FieldDiffContainer
containing the values to be set.- Returns
This method does not return anything.
- Return type
None
- property avro_bytes: bytes
Generate bytes representation of the current instance.
- Returns
A bytes object.
- property avro_data: dict[str, Any]
Compute the avro data of the model.
- Returns
A dictionary object.
- property avro_str: str
Generate bytes representation of the current instance.
- Returns
A bytes object.
- classname = 'minos.aggregate.testing.snapshots.repositories.testcases.SnapshotRepositoryTestCase.Owner'
- async classmethod create(*args, **kwargs)
Create a new
RootEntity
instance.- Parameters
args – Additional positional arguments.
kwargs – Additional named arguments.
- Returns
A new
RootEntity
instance.- Return type
T
- static decode_data(decoder, target, type_, **kwargs)
Decode data with the given decoder.
- Parameters
decoder (DataDecoder) – The decoder instance.
target (Any) – The data to be decoded.
type – The data type.
kwargs – Additional named arguments.
type_ (ModelType) –
- Returns
A decoded instance.
- Return type
- static decode_schema(decoder, target, **kwargs)
Decode schema with the given encoder.
- Parameters
decoder (SchemaDecoder) – The decoder instance.
target (Any) – The schema to be decoded.
kwargs – Additional named arguments.
- Returns
The decoded schema as a type.
- Return type
- async delete()
Delete the given root entity instance.
- Returns
This method does not return anything.
- Return type
None
- diff(another)
Compute the difference with another instance.
Both
RootEntity
instances (self
andanother
) must share the sameuuid
value.- Parameters
another (RootEntity) – Another
RootEntity
instance.- Returns
An
FieldDiffContainer
instance.- Return type
- static encode_data(encoder, target, **kwargs)
Encode data with the given encoder.
- Parameters
encoder (DataEncoder) – The encoder instance.
target (Any) – An optional pre-encoded data.
kwargs – Additional named arguments.
- Returns
The encoded data of the instance.
- Return type
- static encode_schema(encoder, target, **kwargs)
Encode schema with the given encoder.
- Parameters
encoder (SchemaEncoder) – The encoder instance.
target (Any) – An optional pre-encoded schema.
kwargs – Additional named arguments.
- Returns
The encoded schema of the instance.
- Return type
- property fields: dict[str, minos.common.model.fields.Field]
Fields getter
- classmethod find(condition, ordering=None, limit=None, *, _snapshot_repository, **kwargs)
Find a collection of instances based on a given
Condition
.- Parameters
condition (_Condition) – The
Condition
that must be satisfied by all the instances.ordering (Optional[_Ordering]) – Optional argument to return the instance with specific ordering strategy. The default behaviour is to retrieve them without any order pattern.
limit (Optional[int]) – Optional argument to return only a subset of instances. The default behaviour is to return all the instances that meet the given condition.
_snapshot_repository (SnapshotRepository) – Snapshot to be set to the instances.
- Returns
An asynchronous iterator of
RootEntity
instances.- Return type
- classmethod from_avro(schema, data)
Build a new instance from the
avro
schema and data.
- classmethod from_avro_bytes(raw, batch_mode=False, **kwargs)
Build a single instance or a sequence of instances from bytes.
- Parameters
- Returns
A single instance or a sequence of instances.
- Return type
- classmethod from_avro_str(raw, **kwargs)
Build a single instance or a sequence of instances from bytes
- classmethod from_diff(event, *args, **kwargs)
Build a new instance from an
Event
.- Parameters
event (Event) – The difference that contains the data.
args – Additional positional arguments.
kwargs – Additional named arguments.
- Returns
A new
RootEntity
instance.- Return type
T
- classmethod from_model_type(model_type, *args, **kwargs)
Build a
DeclarativeModel
from aModelType
.- Parameters
model_type (ModelType) –
ModelType
object containing the model structure.args – Positional arguments to be passed to the model constructor.
kwargs – Named arguments to be passed to the model constructor.
- Returns
A new
DeclarativeModel
instance.- Return type
T
- classmethod from_typed_dict(typed_dict, *args, **kwargs)
Build a
Model
from aTypeDict
anddata
.- Parameters
typed_dict (TypedDict) –
TypeDict
object containing the DTO’s structureargs – Positional arguments to be passed to the model constructor.
kwargs – Named arguments to be passed to the model constructor.
- Returns
A new
DataTransferObject
instance.- Return type
T
- async classmethod get(uuid, *, _snapshot_repository, **kwargs)
Get one instance from the database based on its identifier.
- Parameters
uuid (UUID) – The identifier of the instance.
_snapshot_repository (SnapshotRepository) – Snapshot to be set to the root entity.
- Returns
A
RootEntity
instance.- Return type
T
- classmethod get_all(ordering=None, limit=None, *, _snapshot_repository, **kwargs)
Get all instance from the database.
- Parameters
ordering (Optional[_Ordering]) – Optional argument to return the instance with specific ordering strategy. The default behaviour is to retrieve them without any order pattern.
limit (Optional[int]) – Optional argument to return only a subset of instances. The default behaviour is to return all the instances that meet the given condition.
_snapshot_repository (SnapshotRepository) – Snapshot to be set to the root entity.
- Returns
A
RootEntity
instance.- Return type
- items() a set-like object providing a view on D's items
- keys() a set-like object providing a view on D's keys
- async refresh()
Refresh the state of the given instance.
- Returns
This method does not return anything.
- Return type
None
- async save()
Store the current instance on the repository.
If didn’t exist previously creates a new one, otherwise updates the existing one.
- Return type
None
- classmethod to_avro_bytes(models)
Create a
bytes
representation of the given object instances.
- classmethod to_avro_str(models)
Build the avro string representation of the given object instances.
- type_hints_parameters = ()
- async update(**kwargs)
Update an existing
RootEntity
instance.- Parameters
kwargs – Additional named arguments.
self (T) –
- Returns
An updated
RootEntity
instance.- Return type
T
- values() an object providing a view on D's values
- created_at: datetime
- updated_at: datetime
- uuid: UUID
- class Car[source]
Bases:
RootEntity
For testing purposes
- owner: Optional[Ref[SnapshotRepositoryTestCase.Owner]]
- __init__(*args, uuid=NULL_UUID, version=0, created_at=NULL_DATETIME, updated_at=NULL_DATETIME, _event_repository, _snapshot_repository, **kwargs)
Class constructor.
- Parameters
kwargs – Named arguments to be set as model attributes.
uuid (UUID) –
version (int) –
created_at (datetime) –
updated_at (datetime) –
_event_repository (EventRepository) –
_snapshot_repository (SnapshotRepository) –
- apply_diff(event)
Apply the differences over the instance.
- Parameters
event (Event) – The
FieldDiffContainer
containing the values to be set.- Returns
This method does not return anything.
- Return type
None
- property avro_bytes: bytes
Generate bytes representation of the current instance.
- Returns
A bytes object.
- property avro_data: dict[str, Any]
Compute the avro data of the model.
- Returns
A dictionary object.
- property avro_str: str
Generate bytes representation of the current instance.
- Returns
A bytes object.
- classname = 'minos.aggregate.testing.snapshots.repositories.testcases.SnapshotRepositoryTestCase.Car'
- async classmethod create(*args, **kwargs)
Create a new
RootEntity
instance.- Parameters
args – Additional positional arguments.
kwargs – Additional named arguments.
- Returns
A new
RootEntity
instance.- Return type
T
- static decode_data(decoder, target, type_, **kwargs)
Decode data with the given decoder.
- Parameters
decoder (DataDecoder) – The decoder instance.
target (Any) – The data to be decoded.
type – The data type.
kwargs – Additional named arguments.
type_ (ModelType) –
- Returns
A decoded instance.
- Return type
- static decode_schema(decoder, target, **kwargs)
Decode schema with the given encoder.
- Parameters
decoder (SchemaDecoder) – The decoder instance.
target (Any) – The schema to be decoded.
kwargs – Additional named arguments.
- Returns
The decoded schema as a type.
- Return type
- async delete()
Delete the given root entity instance.
- Returns
This method does not return anything.
- Return type
None
- diff(another)
Compute the difference with another instance.
Both
RootEntity
instances (self
andanother
) must share the sameuuid
value.- Parameters
another (RootEntity) – Another
RootEntity
instance.- Returns
An
FieldDiffContainer
instance.- Return type
- static encode_data(encoder, target, **kwargs)
Encode data with the given encoder.
- Parameters
encoder (DataEncoder) – The encoder instance.
target (Any) – An optional pre-encoded data.
kwargs – Additional named arguments.
- Returns
The encoded data of the instance.
- Return type
- static encode_schema(encoder, target, **kwargs)
Encode schema with the given encoder.
- Parameters
encoder (SchemaEncoder) – The encoder instance.
target (Any) – An optional pre-encoded schema.
kwargs – Additional named arguments.
- Returns
The encoded schema of the instance.
- Return type
- property fields: dict[str, minos.common.model.fields.Field]
Fields getter
- classmethod find(condition, ordering=None, limit=None, *, _snapshot_repository, **kwargs)
Find a collection of instances based on a given
Condition
.- Parameters
condition (_Condition) – The
Condition
that must be satisfied by all the instances.ordering (Optional[_Ordering]) – Optional argument to return the instance with specific ordering strategy. The default behaviour is to retrieve them without any order pattern.
limit (Optional[int]) – Optional argument to return only a subset of instances. The default behaviour is to return all the instances that meet the given condition.
_snapshot_repository (SnapshotRepository) – Snapshot to be set to the instances.
- Returns
An asynchronous iterator of
RootEntity
instances.- Return type
- classmethod from_avro(schema, data)
Build a new instance from the
avro
schema and data.
- classmethod from_avro_bytes(raw, batch_mode=False, **kwargs)
Build a single instance or a sequence of instances from bytes.
- Parameters
- Returns
A single instance or a sequence of instances.
- Return type
- classmethod from_avro_str(raw, **kwargs)
Build a single instance or a sequence of instances from bytes
- classmethod from_diff(event, *args, **kwargs)
Build a new instance from an
Event
.- Parameters
event (Event) – The difference that contains the data.
args – Additional positional arguments.
kwargs – Additional named arguments.
- Returns
A new
RootEntity
instance.- Return type
T
- classmethod from_model_type(model_type, *args, **kwargs)
Build a
DeclarativeModel
from aModelType
.- Parameters
model_type (ModelType) –
ModelType
object containing the model structure.args – Positional arguments to be passed to the model constructor.
kwargs – Named arguments to be passed to the model constructor.
- Returns
A new
DeclarativeModel
instance.- Return type
T
- classmethod from_typed_dict(typed_dict, *args, **kwargs)
Build a
Model
from aTypeDict
anddata
.- Parameters
typed_dict (TypedDict) –
TypeDict
object containing the DTO’s structureargs – Positional arguments to be passed to the model constructor.
kwargs – Named arguments to be passed to the model constructor.
- Returns
A new
DataTransferObject
instance.- Return type
T
- async classmethod get(uuid, *, _snapshot_repository, **kwargs)
Get one instance from the database based on its identifier.
- Parameters
uuid (UUID) – The identifier of the instance.
_snapshot_repository (SnapshotRepository) – Snapshot to be set to the root entity.
- Returns
A
RootEntity
instance.- Return type
T
- classmethod get_all(ordering=None, limit=None, *, _snapshot_repository, **kwargs)
Get all instance from the database.
- Parameters
ordering (Optional[_Ordering]) – Optional argument to return the instance with specific ordering strategy. The default behaviour is to retrieve them without any order pattern.
limit (Optional[int]) – Optional argument to return only a subset of instances. The default behaviour is to return all the instances that meet the given condition.
_snapshot_repository (SnapshotRepository) – Snapshot to be set to the root entity.
- Returns
A
RootEntity
instance.- Return type
- items() a set-like object providing a view on D's items
- keys() a set-like object providing a view on D's keys
- async refresh()
Refresh the state of the given instance.
- Returns
This method does not return anything.
- Return type
None
- async save()
Store the current instance on the repository.
If didn’t exist previously creates a new one, otherwise updates the existing one.
- Return type
None
- classmethod to_avro_bytes(models)
Create a
bytes
representation of the given object instances.
- classmethod to_avro_str(models)
Build the avro string representation of the given object instances.
- type_hints_parameters = ()
- async update(**kwargs)
Update an existing
RootEntity
instance.- Parameters
kwargs – Additional named arguments.
self (T) –
- Returns
An updated
RootEntity
instance.- Return type
T
- values() an object providing a view on D's values
- created_at: datetime
- updated_at: datetime
- uuid: UUID
- assert_equal_snapshot_entries(expected, observed)[source]
- Parameters
expected (list[minos.aggregate.snapshots.entries.SnapshotEntry]) –
observed (list[minos.aggregate.snapshots.entries.SnapshotEntry]) –
- get_injections()
- tearDown()
- Return type
None
- CONFIG_FILE_PATH: Path