model-bakery 1.11.0__py3-none-any.whl → 1.13.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of model-bakery might be problematic. Click here for more details.
- model_bakery/__about__.py +1 -1
- model_bakery/baker.py +13 -0
- model_bakery/random_gen.py +27 -16
- model_bakery/utils.py +3 -1
- {model_bakery-1.11.0.dist-info → model_bakery-1.13.0.dist-info}/METADATA +2 -1
- {model_bakery-1.11.0.dist-info → model_bakery-1.13.0.dist-info}/RECORD +8 -8
- {model_bakery-1.11.0.dist-info → model_bakery-1.13.0.dist-info}/WHEEL +1 -1
- {model_bakery-1.11.0.dist-info → model_bakery-1.13.0.dist-info}/licenses/LICENSE +0 -0
model_bakery/__about__.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
__version__ = "1.
|
|
1
|
+
__version__ = "1.13.0"
|
model_bakery/baker.py
CHANGED
|
@@ -59,6 +59,10 @@ def _valid_quantity(quantity: Optional[Union[str, int]]) -> bool:
|
|
|
59
59
|
return quantity is not None and (not isinstance(quantity, int) or quantity < 1)
|
|
60
60
|
|
|
61
61
|
|
|
62
|
+
def seed(seed: Union[int, float, str, bytes, bytearray, None]) -> None:
|
|
63
|
+
Baker.seed(seed)
|
|
64
|
+
|
|
65
|
+
|
|
62
66
|
@overload
|
|
63
67
|
def make(
|
|
64
68
|
_model: Union[str, Type[M]],
|
|
@@ -312,13 +316,22 @@ def _custom_baker_class() -> Optional[Type]:
|
|
|
312
316
|
|
|
313
317
|
|
|
314
318
|
class Baker(Generic[M]):
|
|
319
|
+
SENTINEL = object()
|
|
320
|
+
|
|
315
321
|
attr_mapping: Dict[str, Any] = {}
|
|
316
322
|
type_mapping: Dict = {}
|
|
317
323
|
|
|
324
|
+
_global_seed: Union[object, int, float, str, bytes, bytearray, None] = SENTINEL
|
|
325
|
+
|
|
318
326
|
# Note: we're using one finder for all Baker instances to avoid
|
|
319
327
|
# rebuilding the model cache for every make_* or prepare_* call.
|
|
320
328
|
finder = ModelFinder()
|
|
321
329
|
|
|
330
|
+
@classmethod
|
|
331
|
+
def seed(cls, seed: Union[int, float, str, bytes, bytearray, None]) -> None:
|
|
332
|
+
random_gen.baker_random.seed(seed)
|
|
333
|
+
cls._global_seed = seed
|
|
334
|
+
|
|
322
335
|
@classmethod
|
|
323
336
|
def create(
|
|
324
337
|
cls,
|
model_bakery/random_gen.py
CHANGED
|
@@ -14,7 +14,7 @@ import warnings
|
|
|
14
14
|
from datetime import date, datetime, time, timedelta
|
|
15
15
|
from decimal import Decimal
|
|
16
16
|
from os.path import abspath, dirname, join
|
|
17
|
-
from random import
|
|
17
|
+
from random import Random
|
|
18
18
|
from typing import Any, Callable, List, Optional, Tuple, Union
|
|
19
19
|
from uuid import UUID
|
|
20
20
|
|
|
@@ -27,6 +27,8 @@ MAX_LENGTH = 300
|
|
|
27
27
|
# Postgres database.
|
|
28
28
|
MAX_INT = 100000000000
|
|
29
29
|
|
|
30
|
+
baker_random = Random()
|
|
31
|
+
|
|
30
32
|
|
|
31
33
|
def get_content_file(content: bytes, name: str) -> ContentFile:
|
|
32
34
|
return ContentFile(content, name=name)
|
|
@@ -57,7 +59,7 @@ def gen_from_list(a_list: Union[List[str], range]) -> Callable:
|
|
|
57
59
|
>>> attr_mapping = {'some_field': gen_from_list(['A', 'B', 'C'])}
|
|
58
60
|
|
|
59
61
|
"""
|
|
60
|
-
return lambda: choice(list(a_list))
|
|
62
|
+
return lambda: baker_random.choice(list(a_list))
|
|
61
63
|
|
|
62
64
|
|
|
63
65
|
# -- DEFAULT GENERATORS --
|
|
@@ -75,16 +77,16 @@ def gen_from_choices(choices: List) -> Callable:
|
|
|
75
77
|
|
|
76
78
|
|
|
77
79
|
def gen_integer(min_int: int = -MAX_INT, max_int: int = MAX_INT) -> int:
|
|
78
|
-
return randint(min_int, max_int)
|
|
80
|
+
return baker_random.randint(min_int, max_int)
|
|
79
81
|
|
|
80
82
|
|
|
81
83
|
def gen_float() -> float:
|
|
82
|
-
return random() * gen_integer()
|
|
84
|
+
return baker_random.random() * gen_integer()
|
|
83
85
|
|
|
84
86
|
|
|
85
87
|
def gen_decimal(max_digits: int, decimal_places: int) -> Decimal:
|
|
86
88
|
def num_as_str(x: int) -> str:
|
|
87
|
-
return "".join([str(randint(0, 9)) for _ in range(x)])
|
|
89
|
+
return "".join([str(baker_random.randint(0, 9)) for _ in range(x)])
|
|
88
90
|
|
|
89
91
|
if decimal_places:
|
|
90
92
|
return Decimal(
|
|
@@ -110,15 +112,24 @@ def gen_time() -> time:
|
|
|
110
112
|
|
|
111
113
|
|
|
112
114
|
def gen_string(max_length: int) -> str:
|
|
113
|
-
return str(
|
|
115
|
+
return str(
|
|
116
|
+
"".join(baker_random.choice(string.ascii_letters) for _ in range(max_length))
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def _gen_string_get_max_length(field: Field) -> Tuple[str, int]:
|
|
121
|
+
max_length = getattr(field, "max_length", None)
|
|
122
|
+
if max_length is None:
|
|
123
|
+
max_length = MAX_LENGTH
|
|
124
|
+
return "max_length", max_length
|
|
114
125
|
|
|
115
126
|
|
|
116
|
-
gen_string.required = [
|
|
127
|
+
gen_string.required = [_gen_string_get_max_length] # type: ignore[attr-defined]
|
|
117
128
|
|
|
118
129
|
|
|
119
130
|
def gen_slug(max_length: int) -> str:
|
|
120
131
|
valid_chars = string.ascii_letters + string.digits + "_-"
|
|
121
|
-
return str("".join(choice(valid_chars) for _ in range(max_length)))
|
|
132
|
+
return str("".join(baker_random.choice(valid_chars) for _ in range(max_length)))
|
|
122
133
|
|
|
123
134
|
|
|
124
135
|
gen_slug.required = ["max_length"] # type: ignore[attr-defined]
|
|
@@ -129,11 +140,11 @@ def gen_text() -> str:
|
|
|
129
140
|
|
|
130
141
|
|
|
131
142
|
def gen_boolean() -> bool:
|
|
132
|
-
return choice((True, False))
|
|
143
|
+
return baker_random.choice((True, False))
|
|
133
144
|
|
|
134
145
|
|
|
135
146
|
def gen_null_boolean():
|
|
136
|
-
return choice((True, False, None))
|
|
147
|
+
return baker_random.choice((True, False, None))
|
|
137
148
|
|
|
138
149
|
|
|
139
150
|
def gen_url() -> str:
|
|
@@ -145,15 +156,15 @@ def gen_email() -> str:
|
|
|
145
156
|
|
|
146
157
|
|
|
147
158
|
def gen_ipv6() -> str:
|
|
148
|
-
return ":".join(format(randint(1, 65535), "x") for _ in range(8))
|
|
159
|
+
return ":".join(format(baker_random.randint(1, 65535), "x") for _ in range(8))
|
|
149
160
|
|
|
150
161
|
|
|
151
162
|
def gen_ipv4() -> str:
|
|
152
|
-
return ".".join(str(randint(1, 255)) for _ in range(4))
|
|
163
|
+
return ".".join(str(baker_random.randint(1, 255)) for _ in range(4))
|
|
153
164
|
|
|
154
165
|
|
|
155
166
|
def gen_ipv46() -> str:
|
|
156
|
-
ip_gen = choice([gen_ipv4, gen_ipv6])
|
|
167
|
+
ip_gen = baker_random.choice([gen_ipv4, gen_ipv6])
|
|
157
168
|
return ip_gen()
|
|
158
169
|
|
|
159
170
|
|
|
@@ -190,7 +201,7 @@ gen_ip.required = ["protocol", "default_validators"] # type: ignore[attr-define
|
|
|
190
201
|
|
|
191
202
|
|
|
192
203
|
def gen_byte_string(max_length: int = 16) -> bytes:
|
|
193
|
-
generator = (randint(0, 255) for x in range(max_length))
|
|
204
|
+
generator = (baker_random.randint(0, 255) for x in range(max_length))
|
|
194
205
|
return bytes(generator)
|
|
195
206
|
|
|
196
207
|
|
|
@@ -205,7 +216,7 @@ def gen_content_type():
|
|
|
205
216
|
from django.contrib.contenttypes.models import ContentType
|
|
206
217
|
|
|
207
218
|
try:
|
|
208
|
-
return ContentType.objects.get_for_model(choice(apps.get_models()))
|
|
219
|
+
return ContentType.objects.get_for_model(baker_random.choice(apps.get_models()))
|
|
209
220
|
except (AssertionError, RuntimeError):
|
|
210
221
|
# AssertionError is raised by Django's test framework when db access is not available:
|
|
211
222
|
# https://github.com/django/django/blob/stable/4.0.x/django/test/testcases.py#L150
|
|
@@ -269,7 +280,7 @@ gen_m2m.required = [_fk_model, "_using"] # type: ignore[attr-defined]
|
|
|
269
280
|
|
|
270
281
|
|
|
271
282
|
def gen_coord() -> float:
|
|
272
|
-
return uniform(0, 1)
|
|
283
|
+
return baker_random.uniform(0, 1)
|
|
273
284
|
|
|
274
285
|
|
|
275
286
|
def gen_coords() -> str:
|
model_bakery/utils.py
CHANGED
|
@@ -94,7 +94,9 @@ def seq(value, increment_by=1, start=None, suffix=None):
|
|
|
94
94
|
else:
|
|
95
95
|
yield series_date
|
|
96
96
|
else:
|
|
97
|
-
for n in itertools.count(
|
|
97
|
+
for n in itertools.count(
|
|
98
|
+
increment_by if start is None else start, increment_by
|
|
99
|
+
):
|
|
98
100
|
if suffix:
|
|
99
101
|
yield value + str(n) + suffix
|
|
100
102
|
else:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: model-bakery
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.13.0
|
|
4
4
|
Summary: Smart object creation facility for Django.
|
|
5
5
|
Project-URL: Homepage, https://github.com/model-bakers/model_bakery
|
|
6
6
|
Author-email: berin <bernardoxhc@gmail.com>, amureki <amureki@hey.com>
|
|
@@ -12,6 +12,7 @@ Classifier: Framework :: Django
|
|
|
12
12
|
Classifier: Framework :: Django :: 3.2
|
|
13
13
|
Classifier: Framework :: Django :: 4.0
|
|
14
14
|
Classifier: Framework :: Django :: 4.1
|
|
15
|
+
Classifier: Framework :: Django :: 4.2
|
|
15
16
|
Classifier: Intended Audience :: Developers
|
|
16
17
|
Classifier: License :: OSI Approved :: Apache Software License
|
|
17
18
|
Classifier: Operating System :: OS Independent
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
model_bakery/__about__.py,sha256=
|
|
1
|
+
model_bakery/__about__.py,sha256=qyRV1Az4m5yhA_Nx1r_oZmIwZAZJpLTJdDw9oDJaqr8,23
|
|
2
2
|
model_bakery/__init__.py,sha256=yY0xZUrr_mskBm07iF-MFBEiXzOuKrlMwpKWkXZs8v0,31
|
|
3
3
|
model_bakery/_types.py,sha256=P0iKC5-Cnh3lyzyZs1mlCfOW31zbEZpxqWCuYonucKo,130
|
|
4
|
-
model_bakery/baker.py,sha256=
|
|
4
|
+
model_bakery/baker.py,sha256=uEAudFQYa9o6CjaZGvy0LXMWYzrxthvZ1VKTxzWrses,27132
|
|
5
5
|
model_bakery/exceptions.py,sha256=q1oBZvfxL7HAD-F9aWgiYs4P4rz-hJ5TjeX7gcb3Q0I,333
|
|
6
6
|
model_bakery/generators.py,sha256=IkYFBTwSVwa_wwPnZRiVR1vHqUfjWqmyPGCl10RElB0,6467
|
|
7
7
|
model_bakery/gis.py,sha256=eTNOfT98_ncLAb4KmOYJhE-3ALU2_pQbUpWPTolFZJI,1028
|
|
8
8
|
model_bakery/mock_file.txt,sha256=CO5zPS6Uydk48ZRnGcRKVEYKd2YjaUMa9QOgF5gGMCo,10
|
|
9
9
|
model_bakery/mock_img.jpeg,sha256=iF2ybgAVtDvl48-8VKdv_QFHKfnqeOaeGwR6ZLexJkY,1916
|
|
10
10
|
model_bakery/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
11
|
-
model_bakery/random_gen.py,sha256=
|
|
11
|
+
model_bakery/random_gen.py,sha256=T_SQ7ouKufWFq7QMV1os-3TUgPynycOhYM_zpA1cbME,9619
|
|
12
12
|
model_bakery/recipe.py,sha256=3BU-UgaofBJhYnHjH0yTMK7e7IFI3Jv_pp-XZlvF6KE,8292
|
|
13
13
|
model_bakery/timezone.py,sha256=rd-KGVHqJoHdHKBgENPMBTRqqxgKE91CM9C0f9nS90M,325
|
|
14
|
-
model_bakery/utils.py,sha256=
|
|
15
|
-
model_bakery-1.
|
|
16
|
-
model_bakery-1.
|
|
17
|
-
model_bakery-1.
|
|
18
|
-
model_bakery-1.
|
|
14
|
+
model_bakery/utils.py,sha256=dsbUlzroP_NMtS7SJ5koxfAwO0F4Y_yzt5FlOAfksRA,4550
|
|
15
|
+
model_bakery-1.13.0.dist-info/METADATA,sha256=ksssXGIZ-gVhGu98VSwHc9SICy83oYwPNyb-z1K1erQ,3680
|
|
16
|
+
model_bakery-1.13.0.dist-info/WHEEL,sha256=9QBuHhg6FNW7lppboF2vKVbCGTVzsFykgRQjjlajrhA,87
|
|
17
|
+
model_bakery-1.13.0.dist-info/licenses/LICENSE,sha256=HIJ64rfqx0cBo7VpRa9QZwqpHMyPQRQYhvWVq6enYXc,582
|
|
18
|
+
model_bakery-1.13.0.dist-info/RECORD,,
|
|
File without changes
|