diff --git a/tests/conftest.py b/tests/conftest.py index ab46503f..25d451f3 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -71,6 +71,7 @@ def pytest_configure(): # Set the version explicitly otherwise Django does extra queries # to get the version via SQL when using POSTGIS POSTGIS_VERSION=postgis_version, + ROOT_URLCONF="tests.generic.urls" ) from model_bakery import baker diff --git a/tests/generic/models.py b/tests/generic/models.py index 0811335d..ae1fce03 100755 --- a/tests/generic/models.py +++ b/tests/generic/models.py @@ -478,3 +478,14 @@ class Issue291Model3(models.Model): Issue291Model2, related_name="bazs", on_delete=models.CASCADE ) name = models.CharField(max_length=32) + + +# Testing out an issue (https://github.com/model-bakers/model_bakery/issues/329). +# Same situation as the above. +class Issue329ModelA(models.Model): + pass + + +class Issue329ModelB(models.Model): + types = models.ManyToManyField(Issue329ModelA) + subtypes = models.ManyToManyField(Issue329ModelA) diff --git a/tests/generic/urls.py b/tests/generic/urls.py new file mode 100644 index 00000000..74d5527f --- /dev/null +++ b/tests/generic/urls.py @@ -0,0 +1,7 @@ +from django.urls import include, path + +from tests.generic.views import issue329_view + +urlpatterns = [ + path('issue-329/', issue329_view, name='issue-329'), +] diff --git a/tests/generic/views.py b/tests/generic/views.py new file mode 100644 index 00000000..b101b3d9 --- /dev/null +++ b/tests/generic/views.py @@ -0,0 +1,6 @@ +from django.views import View +from django.http import HttpResponse + + +def issue329_view(_request): + return HttpResponse(content='Issue 329', status=200) diff --git a/tests/test_issues.py b/tests/test_issues.py new file mode 100644 index 00000000..d7589654 --- /dev/null +++ b/tests/test_issues.py @@ -0,0 +1,31 @@ +import pytest + +from django.urls import reverse +from django.test import Client + +from model_bakery import baker +from tests.generic.models import Issue329ModelA, Issue329ModelB + + +@pytest.fixture() +def site_b(): + return baker.make(Issue329ModelB) + + +@pytest.mark.django_db +def test_issue_329(site_b): + instances = ( + record for record, _created in ( + Issue329ModelA.objects.get_or_create(id=1), + Issue329ModelA.objects.get_or_create(id=2) + ) + ) + + site_b.types.add(*instances) + client = Client() + url = reverse('issue-329') + + resp = client.get(url) + + assert resp.status_code == 200 + assert resp.content == b'Issue 329'