Skip to content

Commit

Permalink
[draft] Test scenario for #439
Browse files Browse the repository at this point in the history
  • Loading branch information
amureki committed Aug 21, 2023
1 parent 4c22653 commit d38dea5
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tests/generic/baker_recipes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
10 changes: 10 additions & 0 deletions tests/generic/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
17 changes: 17 additions & 0 deletions tests/test_recipes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit d38dea5

Please sign in to comment.