Skip to content

Commit

Permalink
[model-bakers#329] (WIP) Initial issue example model and test setup
Browse files Browse the repository at this point in the history
  • Loading branch information
timjklein36 committed Oct 14, 2022
1 parent 370406f commit c79b7a6
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions tests/generic/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
7 changes: 7 additions & 0 deletions tests/generic/urls.py
Original file line number Diff line number Diff line change
@@ -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'),
]
6 changes: 6 additions & 0 deletions tests/generic/views.py
Original file line number Diff line number Diff line change
@@ -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)
31 changes: 31 additions & 0 deletions tests/test_issues.py
Original file line number Diff line number Diff line change
@@ -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'

0 comments on commit c79b7a6

Please sign in to comment.