API Reference
mongo_bakery.bakery
Baker
Source code in mongo_bakery/bakery.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 | |
cleanup()
Delete all created instances.
This method iterates over all instances stored in the _created_instances
list, calls their delete method to remove them, and then clears the list.
Source code in mongo_bakery/bakery.py
202 203 204 205 206 207 208 209 210 211 | |
make(document_class, _quantity=1, **kwargs)
Creates and saves one or more instances of a MongoEngine document.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
document_class
|
type[Document]
|
The MongoEngine document class to instantiate. |
required |
_quantity
|
int
|
The number of instances to create. Defaults to 1. |
1
|
**kwargs
|
dict[Any, Any]
|
Additional field values to set on the document instances. |
{}
|
Returns:
| Type | Description |
|---|---|
Document | list[Document]
|
Document or list[Document]: A single document instance if _quantity is 1, |
Document | list[Document]
|
otherwise a list of document instances. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the provided document_class is not a subclass of mongoengine.Document or mongoengine.EmbeddedDocument. |
Source code in mongo_bakery/bakery.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | |
mock_dependencies(mock_class)
Mocks the specified dependencies for testing purposes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mock_class
|
list
|
A list of classes or modules to be mocked. |
required |
Source code in mongo_bakery/bakery.py
26 27 28 29 30 31 32 33 | |
seed(value)
Seed Faker's shared random generator, so make produces reproducible mock data.
Faker.seed seeds a random generator shared by every Faker() instance by default,
so this affects mock data generated anywhere in mongo_bakery, not just this module.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
SeedType
|
The seed value, passed through to |
required |
Source code in mongo_bakery/bakery.py
143 144 145 146 147 148 149 150 151 152 153 | |
seq(value, increment_by=1, start=None)
Build a sequence that yields an incrementing value each time make creates an instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str | int | float | date | datetime
|
The base value. Supported types are str, int, float, date and datetime. |
required |
increment_by
|
int | float | timedelta
|
The amount added on every call. Defaults to 1. For date/datetime values, this must be a timedelta. |
1
|
start
|
int | float | timedelta | None
|
The offset applied on the first call. Defaults to |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Sequence |
Sequence
|
A callable object that |
Source code in mongo_bakery/bakery.py
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | |
mongo_bakery.bakery_fields_generators
mongo_bakery.sequences
Sequence
Produces an incrementing value on each call, for use as a baker.make kwarg.
Source code in mongo_bakery/sequences.py
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | |
mongo_bakery.pytest_plugin
baker()
Yield the shared mongo_bakery baker and clean up any instances it created after the test.
Registered as a pytest plugin (see the pytest11 entry point in pyproject.toml), so this
fixture is available in any project that has mongo_bakery installed, with no extra setup.
Yields:
| Name | Type | Description |
|---|---|---|
Baker |
Baker
|
The shared |
Source code in mongo_bakery/pytest_plugin.py
9 10 11 12 13 14 15 16 17 18 19 20 21 | |