testing
Application testing support.
ControllerTest ¶
ControllerTest(
client,
base_path,
collection,
raw_collection,
service_type,
monkeypatch,
collection_filters=None,
)
Standard controller testing utility.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
client |
TestClient
|
Test client instance. |
required |
base_path |
str
|
Path for POST and collection GET requests. |
required |
collection |
Sequence[orm.Base]
|
Collection of domain objects. |
required |
raw_collection |
Sequence[dict[str, Any]]
|
Collection of raw representations of domain objects. |
required |
service_type |
type[Service]
|
The domain Service object type. |
required |
monkeypatch |
MonkeyPatch
|
Pytest's monkeypatch. |
required |
collection_filters |
dict[str, Any] | None
|
Collection filters for GET collection request. |
None
|
GenericMockRepository ¶
Bases: AbstractRepository[ModelT]
, Generic[ModelT]
A repository implementation for tests.
Uses a dict
for storage.
__class_getitem__
classmethod
¶
Add collection to _collections
for the type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
item |
type[ModelT]
|
The type that the class has been parametrized with. |
required |
add
async
¶
Add data
to the collection.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
ModelT
|
Instance to be added to the collection. |
required |
allow_id |
bool
|
disable the identified object check. |
False
|
Returns:
Type | Description |
---|---|
ModelT
|
The added instance. |
delete
async
¶
Delete instance identified by id_
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
id_ |
Any
|
Identifier of instance to be deleted. |
required |
Returns:
Type | Description |
---|---|
ModelT
|
The deleted instance. |
Raises:
Type | Description |
---|---|
RepositoryNotFoundException
|
If no instance found identified by |
filter_collection_by_kwargs ¶
Filter the collection by kwargs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**kwargs |
Any
|
key/value pairs such that objects remaining in the collection after filtering
have the property that their attribute named |
{}
|
get
async
¶
Get instance identified by id_
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
id_ |
Any
|
Identifier of the instance to be retrieved. |
required |
Returns:
Type | Description |
---|---|
ModelT
|
The retrieved instance. |
Raises:
Type | Description |
---|---|
RepositoryNotFoundException
|
If no instance found identified by |
list
async
¶
Get a list of instances, optionally filtered.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*filters |
FilterTypes
|
Types for specific filtering operations. |
()
|
**kwargs |
Any
|
Instance attribute value filters. |
{}
|
Returns:
Type | Description |
---|---|
list[ModelT]
|
The list of instances, after filtering applied. |
seed_collection
classmethod
¶
Seed the collection for repository type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
instances |
Iterable[ModelT]
|
the instances to be added to the collection. |
required |
update
async
¶
Update instance with the attribute values present on data
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
ModelT
|
An instance that should have a value for |
required |
Returns:
Type | Description |
---|---|
ModelT
|
The updated instance. |
Raises:
Type | Description |
---|---|
RepositoryNotFoundException
|
If no instance found with same identifier as |
upsert
async
¶
Update or create instance.
Updates instance with the attribute values present on data
, or creates a new instance if
one doesn't exist.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
ModelT
|
Instance to update existing, or be created. Identifier used to determine if an
existing instance exists is the value of an attribute on |
required |
Returns:
Type | Description |
---|---|
ModelT
|
The updated or created instance. |
Raises:
Type | Description |
---|---|
RepositoryNotFoundException
|
If no instance found with same identifier as |