Skip to content

Commit cd83e5c

Browse files
committed
Added GenericRelations tests
1 parent cfd0941 commit cd83e5c

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

example/factories/__init__.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import factory
44
from faker import Factory as FakerFactory
5-
from example.models import Blog, Author, AuthorBio, Entry, Comment
5+
from example.models import Blog, Author, AuthorBio, Entry, Comment, TaggedItem
66

77
faker = FakerFactory.create()
88
faker.seed(983843)
@@ -58,3 +58,11 @@ class Meta:
5858
body = factory.LazyAttribute(lambda x: faker.text())
5959
author = factory.SubFactory(AuthorFactory)
6060

61+
62+
class EntryTaggedItemFactory(factory.django.DjangoModelFactory):
63+
64+
class Meta:
65+
model = TaggedItem
66+
67+
content_object = factory.SubFactory(EntryFactory)
68+
tag = factory.LazyAttribute(lambda x: faker.word())

example/tests/conftest.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
import pytest
22
from pytest_factoryboy import register
33

4-
from example.factories import BlogFactory, AuthorFactory, AuthorBioFactory, EntryFactory, CommentFactory
4+
from example.factories import BlogFactory, AuthorFactory, AuthorBioFactory, EntryFactory, CommentFactory, \
5+
EntryTaggedItemFactory
56

67
register(BlogFactory)
78
register(AuthorFactory)
89
register(AuthorBioFactory)
910
register(EntryFactory)
1011
register(CommentFactory)
12+
register(EntryTaggedItemFactory)
1113

1214

1315
@pytest.fixture
14-
def single_entry(blog, author, entry_factory, comment_factory):
16+
def single_entry(blog, author, entry_factory, comment_factory, entry_tagged_item_factory):
1517

1618
entry = entry_factory(blog=blog, authors=(author,))
1719
comment_factory(entry=entry)
20+
entry_tagged_item_factory(content_object=entry)
1821
return entry
1922

2023

example/tests/integration/test_pagination.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,12 @@ def test_pagination_with_single_entry(single_entry, client):
4444
}
4545
},
4646
"tags": {
47-
"data": []
47+
"data": [
48+
{
49+
"id": "1",
50+
"type": "taggedItems"
51+
}
52+
]
4853
}
4954
}
5055
}],

0 commit comments

Comments
 (0)