From d38dea58ac739ef4000e98b59d56a8429f34c627 Mon Sep 17 00:00:00 2001 From: Rust Saiargaliev Date: Mon, 21 Aug 2023 10:10:54 +0200 Subject: [PATCH] [draft] Test scenario for #439 --- tests/generic/baker_recipes.py | 7 +++++++ tests/generic/models.py | 10 ++++++++++ tests/test_recipes.py | 17 +++++++++++++++++ 3 files changed, 34 insertions(+) diff --git a/tests/generic/baker_recipes.py b/tests/generic/baker_recipes.py index f9f82e39..a31db5a5 100644 --- a/tests/generic/baker_recipes.py +++ b/tests/generic/baker_recipes.py @@ -122,3 +122,10 @@ class SmallDogRecipe(Recipe): ipv4_field=seq("127.0.0.", increment_by=2), ipv6_field=seq("2001:12f8:0:28::", start=4, increment_by=2), ) + +issue439_related = Recipe( + "generic.Issue439RelatedModel", name=seq("RelatedModel #"), my_flag=False +) +issue439_model = Recipe( + "generic.Issue439Model", related_model=foreign_key(issue439_related) +) diff --git a/tests/generic/models.py b/tests/generic/models.py index 64eb4256..e07f1fd8 100755 --- a/tests/generic/models.py +++ b/tests/generic/models.py @@ -472,3 +472,13 @@ class Issue291Model3(models.Model): Issue291Model2, related_name="bazs", on_delete=models.CASCADE ) name = models.CharField(max_length=32) + + +class Issue439Model(models.Model): + name = models.CharField(max_length=32) + related_model = models.ForeignKey("Issue439RelatedModel", on_delete=models.CASCADE) + + +class Issue439RelatedModel(models.Model): + name = models.CharField(max_length=32) + my_flag = models.BooleanField(default=False) diff --git a/tests/test_recipes.py b/tests/test_recipes.py index a478c4d3..7bfb85c0 100644 --- a/tests/test_recipes.py +++ b/tests/test_recipes.py @@ -644,3 +644,20 @@ def test_only_iterators_not_iteratables_are_iterated(self): DummyBlankFieldsModel, blank_text_field="not an iterator, so don't iterate!" ) assert r.make().blank_text_field == "not an iterator, so don't iterate!" + + +@pytest.mark.django_db +class TestIssue439: + def test_ok(self): + my_obj = baker.make_recipe("tests.generic.issue439_model") + assert my_obj.related_model.name == "RelatedModel #1" + + assert my_obj.related_model.my_flag is False + + def test_not_ok(self): + my_obj = baker.make_recipe( + "tests.generic.issue439_model", related_model__my_flag=True + ) + assert my_obj.related_model.name == "RelatedModel #1" + + assert my_obj.related_model.my_flag is True