model-bakery 1.15.0__tar.gz → 1.17.0__tar.gz
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-1.15.0 → model_bakery-1.17.0}/.gitignore +2 -0
- {model_bakery-1.15.0 → model_bakery-1.17.0}/PKG-INFO +13 -6
- {model_bakery-1.15.0 → model_bakery-1.17.0}/README.md +8 -5
- model_bakery-1.17.0/model_bakery/__about__.py +1 -0
- {model_bakery-1.15.0 → model_bakery-1.17.0}/model_bakery/baker.py +24 -6
- {model_bakery-1.15.0 → model_bakery-1.17.0}/model_bakery/random_gen.py +2 -4
- {model_bakery-1.15.0 → model_bakery-1.17.0}/pyproject.toml +26 -12
- model_bakery-1.15.0/model_bakery/__about__.py +0 -1
- {model_bakery-1.15.0 → model_bakery-1.17.0}/LICENSE +0 -0
- {model_bakery-1.15.0 → model_bakery-1.17.0}/model_bakery/__init__.py +0 -0
- {model_bakery-1.15.0 → model_bakery-1.17.0}/model_bakery/_types.py +0 -0
- {model_bakery-1.15.0 → model_bakery-1.17.0}/model_bakery/exceptions.py +0 -0
- {model_bakery-1.15.0 → model_bakery-1.17.0}/model_bakery/generators.py +0 -0
- {model_bakery-1.15.0 → model_bakery-1.17.0}/model_bakery/gis.py +0 -0
- {model_bakery-1.15.0 → model_bakery-1.17.0}/model_bakery/mock_file.txt +0 -0
- {model_bakery-1.15.0 → model_bakery-1.17.0}/model_bakery/mock_img.jpeg +0 -0
- {model_bakery-1.15.0 → model_bakery-1.17.0}/model_bakery/py.typed +0 -0
- {model_bakery-1.15.0 → model_bakery-1.17.0}/model_bakery/recipe.py +0 -0
- {model_bakery-1.15.0 → model_bakery-1.17.0}/model_bakery/timezone.py +0 -0
- {model_bakery-1.15.0 → model_bakery-1.17.0}/model_bakery/utils.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: model-bakery
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.17.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>
|
|
@@ -25,8 +25,12 @@ Classifier: Programming Language :: Python :: 3.12
|
|
|
25
25
|
Classifier: Topic :: Software Development
|
|
26
26
|
Requires-Python: >=3.8
|
|
27
27
|
Requires-Dist: django>=3.2
|
|
28
|
+
Provides-Extra: docs
|
|
29
|
+
Requires-Dist: sphinx; extra == 'docs'
|
|
30
|
+
Requires-Dist: sphinx-rtd-theme; extra == 'docs'
|
|
28
31
|
Provides-Extra: test
|
|
29
32
|
Requires-Dist: black; extra == 'test'
|
|
33
|
+
Requires-Dist: coverage; extra == 'test'
|
|
30
34
|
Requires-Dist: mypy; extra == 'test'
|
|
31
35
|
Requires-Dist: pillow; extra == 'test'
|
|
32
36
|
Requires-Dist: pytest; extra == 'test'
|
|
@@ -36,6 +40,11 @@ Description-Content-Type: text/markdown
|
|
|
36
40
|
|
|
37
41
|
# Model Bakery: Smart fixtures for better tests
|
|
38
42
|
|
|
43
|
+
[](https://github.com/model-bakers/model_bakery/actions?workflow=Tests)
|
|
44
|
+
[](https://github.com/model-bakers/model_bakery/actions?workflow=Tests)
|
|
45
|
+
[](https://pypi.python.org/pypi/model_bakery/)
|
|
46
|
+
[](https://model-bakery.readthedocs.io/en/latest/?badge=latest)
|
|
47
|
+
|
|
39
48
|
*Model Bakery* offers you a smart way to create fixtures for testing in
|
|
40
49
|
Django.
|
|
41
50
|
With a simple and powerful API you can create many objects with a single
|
|
@@ -43,14 +52,10 @@ line of code.
|
|
|
43
52
|
|
|
44
53
|
Model Bakery is a rename of the legacy [Model Mommy project](https://pypi.org/project/model_mommy/).
|
|
45
54
|
|
|
46
|
-

|
|
47
|
-
[](https://pypi.python.org/pypi/model_bakery/)
|
|
48
|
-
[](https://model-bakery.readthedocs.io/en/latest/?badge=latest)
|
|
49
|
-
|
|
50
55
|
## Install
|
|
51
56
|
|
|
52
57
|
```bash
|
|
53
|
-
pip install
|
|
58
|
+
pip install model-bakery
|
|
54
59
|
```
|
|
55
60
|
|
|
56
61
|
## Usage and Info
|
|
@@ -61,6 +66,8 @@ pip install model_bakery
|
|
|
61
66
|
|
|
62
67
|
# models.py
|
|
63
68
|
|
|
69
|
+
from django.db import models
|
|
70
|
+
|
|
64
71
|
class Customer(models.Model):
|
|
65
72
|
enjoy_jards_macale = models.BooleanField()
|
|
66
73
|
name = models.CharField(max_length=30)
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# Model Bakery: Smart fixtures for better tests
|
|
2
2
|
|
|
3
|
+
[](https://github.com/model-bakers/model_bakery/actions?workflow=Tests)
|
|
4
|
+
[](https://github.com/model-bakers/model_bakery/actions?workflow=Tests)
|
|
5
|
+
[](https://pypi.python.org/pypi/model_bakery/)
|
|
6
|
+
[](https://model-bakery.readthedocs.io/en/latest/?badge=latest)
|
|
7
|
+
|
|
3
8
|
*Model Bakery* offers you a smart way to create fixtures for testing in
|
|
4
9
|
Django.
|
|
5
10
|
With a simple and powerful API you can create many objects with a single
|
|
@@ -7,14 +12,10 @@ line of code.
|
|
|
7
12
|
|
|
8
13
|
Model Bakery is a rename of the legacy [Model Mommy project](https://pypi.org/project/model_mommy/).
|
|
9
14
|
|
|
10
|
-

|
|
11
|
-
[](https://pypi.python.org/pypi/model_bakery/)
|
|
12
|
-
[](https://model-bakery.readthedocs.io/en/latest/?badge=latest)
|
|
13
|
-
|
|
14
15
|
## Install
|
|
15
16
|
|
|
16
17
|
```bash
|
|
17
|
-
pip install
|
|
18
|
+
pip install model-bakery
|
|
18
19
|
```
|
|
19
20
|
|
|
20
21
|
## Usage and Info
|
|
@@ -25,6 +26,8 @@ pip install model_bakery
|
|
|
25
26
|
|
|
26
27
|
# models.py
|
|
27
28
|
|
|
29
|
+
from django.db import models
|
|
30
|
+
|
|
28
31
|
class Customer(models.Model):
|
|
29
32
|
enjoy_jards_macale = models.BooleanField()
|
|
30
33
|
name = models.CharField(max_length=30)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "1.17.0"
|
|
@@ -8,6 +8,7 @@ from typing import (
|
|
|
8
8
|
Iterator,
|
|
9
9
|
List,
|
|
10
10
|
Optional,
|
|
11
|
+
Set,
|
|
11
12
|
Type,
|
|
12
13
|
Union,
|
|
13
14
|
cast,
|
|
@@ -412,12 +413,10 @@ class Baker(Generic[M]):
|
|
|
412
413
|
params.update(attrs)
|
|
413
414
|
return self._make(**params)
|
|
414
415
|
|
|
415
|
-
def get_fields(self) ->
|
|
416
|
-
return
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
if f not in self.model._meta.related_objects
|
|
420
|
-
]
|
|
416
|
+
def get_fields(self) -> Set[Any]:
|
|
417
|
+
return set(self.model._meta.get_fields()) - set(
|
|
418
|
+
self.model._meta.related_objects
|
|
419
|
+
)
|
|
421
420
|
|
|
422
421
|
def _make( # noqa: C901
|
|
423
422
|
self,
|
|
@@ -499,17 +498,30 @@ class Baker(Generic[M]):
|
|
|
499
498
|
self, attrs: Dict[str, Any], _commit, _save_kwargs, _from_manager
|
|
500
499
|
) -> M:
|
|
501
500
|
one_to_many_keys = {}
|
|
501
|
+
auto_now_keys = {}
|
|
502
|
+
|
|
502
503
|
for k in tuple(attrs.keys()):
|
|
503
504
|
field = getattr(self.model, k, None)
|
|
505
|
+
|
|
506
|
+
if not field:
|
|
507
|
+
continue
|
|
508
|
+
|
|
504
509
|
if isinstance(field, ForeignRelatedObjectsDescriptor):
|
|
505
510
|
one_to_many_keys[k] = attrs.pop(k)
|
|
506
511
|
|
|
512
|
+
if hasattr(field, "field") and (
|
|
513
|
+
getattr(field.field, "auto_now_add", False)
|
|
514
|
+
or getattr(field.field, "auto_now", False)
|
|
515
|
+
):
|
|
516
|
+
auto_now_keys[k] = attrs[k]
|
|
517
|
+
|
|
507
518
|
instance = self.model(**attrs)
|
|
508
519
|
# m2m only works for persisted instances
|
|
509
520
|
if _commit:
|
|
510
521
|
instance.save(**_save_kwargs)
|
|
511
522
|
self._handle_one_to_many(instance, one_to_many_keys)
|
|
512
523
|
self._handle_m2m(instance)
|
|
524
|
+
self._handle_auto_now(instance, auto_now_keys)
|
|
513
525
|
|
|
514
526
|
if _from_manager:
|
|
515
527
|
# Fetch the instance using the given Manager, e.g.
|
|
@@ -610,6 +622,12 @@ class Baker(Generic[M]):
|
|
|
610
622
|
|
|
611
623
|
return False
|
|
612
624
|
|
|
625
|
+
def _handle_auto_now(self, instance: Model, attrs: Dict[str, Any]):
|
|
626
|
+
if not attrs:
|
|
627
|
+
return
|
|
628
|
+
|
|
629
|
+
instance.__class__.objects.filter(pk=instance.pk).update(**attrs)
|
|
630
|
+
|
|
613
631
|
def _handle_one_to_many(self, instance: Model, attrs: Dict[str, Any]):
|
|
614
632
|
for key, values in attrs.items():
|
|
615
633
|
manager = getattr(instance, key)
|
|
@@ -112,9 +112,7 @@ def gen_time() -> time:
|
|
|
112
112
|
|
|
113
113
|
|
|
114
114
|
def gen_string(max_length: int) -> str:
|
|
115
|
-
return
|
|
116
|
-
"".join(baker_random.choice(string.ascii_letters) for _ in range(max_length))
|
|
117
|
-
)
|
|
115
|
+
return "".join(baker_random.choice(string.ascii_letters) for _ in range(max_length))
|
|
118
116
|
|
|
119
117
|
|
|
120
118
|
def _gen_string_get_max_length(field: Field) -> Tuple[str, int]:
|
|
@@ -129,7 +127,7 @@ gen_string.required = [_gen_string_get_max_length] # type: ignore[attr-defined]
|
|
|
129
127
|
|
|
130
128
|
def gen_slug(max_length: int) -> str:
|
|
131
129
|
valid_chars = string.ascii_letters + string.digits + "_-"
|
|
132
|
-
return
|
|
130
|
+
return "".join(baker_random.choice(valid_chars) for _ in range(max_length))
|
|
133
131
|
|
|
134
132
|
|
|
135
133
|
gen_slug.required = ["max_length"] # type: ignore[attr-defined]
|
|
@@ -43,6 +43,7 @@ dependencies = [
|
|
|
43
43
|
|
|
44
44
|
[project.optional-dependencies]
|
|
45
45
|
test = [
|
|
46
|
+
"coverage",
|
|
46
47
|
"pillow",
|
|
47
48
|
"pytest",
|
|
48
49
|
"pytest-django",
|
|
@@ -50,10 +51,34 @@ test = [
|
|
|
50
51
|
"ruff",
|
|
51
52
|
"mypy",
|
|
52
53
|
]
|
|
54
|
+
docs = [
|
|
55
|
+
"Sphinx",
|
|
56
|
+
"sphinx-rtd-theme",
|
|
57
|
+
]
|
|
53
58
|
|
|
54
59
|
[project.urls]
|
|
55
60
|
Homepage = "https://github.com/model-bakers/model_bakery"
|
|
56
61
|
|
|
62
|
+
[tool.coverage.run]
|
|
63
|
+
branch = true
|
|
64
|
+
parallel = true
|
|
65
|
+
source = [
|
|
66
|
+
"model_bakery",
|
|
67
|
+
]
|
|
68
|
+
omit = [
|
|
69
|
+
"model_bakery/__about__.py",
|
|
70
|
+
"model_bakery/_types.py",
|
|
71
|
+
]
|
|
72
|
+
|
|
73
|
+
[tool.coverage.paths]
|
|
74
|
+
source = [
|
|
75
|
+
"model_bakery",
|
|
76
|
+
".tox/**/site-packages/model_bakery",
|
|
77
|
+
]
|
|
78
|
+
|
|
79
|
+
[tool.coverage.report]
|
|
80
|
+
show_missing = true
|
|
81
|
+
|
|
57
82
|
[tool.hatch.version]
|
|
58
83
|
path = "model_bakery/__about__.py"
|
|
59
84
|
|
|
@@ -62,21 +87,10 @@ include = [
|
|
|
62
87
|
"/model_bakery",
|
|
63
88
|
]
|
|
64
89
|
|
|
65
|
-
[tool.isort]
|
|
66
|
-
multi_line_output = 3
|
|
67
|
-
include_trailing_comma = true
|
|
68
|
-
force_grid_wrap = 0
|
|
69
|
-
use_parentheses = true
|
|
70
|
-
line_length = 88
|
|
71
|
-
|
|
72
90
|
[tool.mypy]
|
|
73
91
|
ignore_missing_imports = true
|
|
74
92
|
disallow_untyped_calls = true
|
|
75
93
|
|
|
76
|
-
[tool.pydocstyle]
|
|
77
|
-
add_ignore = "D1"
|
|
78
|
-
match-dir = '(?!test|docs|venv|\.).*'
|
|
79
|
-
|
|
80
94
|
[tool.pytest.ini_options]
|
|
81
95
|
addopts = "--tb=short -rxs --nomigrations"
|
|
82
96
|
|
|
@@ -98,7 +112,7 @@ select = [
|
|
|
98
112
|
ignore = ["B904", "E501", "S101", "D1", "D212"]
|
|
99
113
|
|
|
100
114
|
[tool.ruff.per-file-ignores]
|
|
101
|
-
"
|
|
115
|
+
"tests/test_*.py" = [
|
|
102
116
|
"S",
|
|
103
117
|
]
|
|
104
118
|
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "1.15.0"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|