#18586 - GenericRelationsTests separated into several tests #2693

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
2 participants
Contributor

jose-lpa commented May 20, 2014

This intends to fix the first test case reported in Trac ticket 18586 as a "too long" unit test to be separated into several, more specific ones.

In particular, this PR splits the old modeltests.generic_relations.GenericRelationsTests.test_generic_relations unit test into several different unit tests, each one related to a single feature of Django generic relations. It also adds a setUp method to the TestCase to define the common attributes.

)
- TaggedItem.objects.filter(tag='fatty').delete()
@timgraham

timgraham May 28, 2014

Owner

It seems like some lines were deleted like this stuff... was it intentional?

@jose-lpa

jose-lpa May 28, 2014

Contributor

Yeah, some delete() lines were removed because of the new layout, which creates the objects in the setUp method. I can make a further review of my fixes later today, but roughly I think it should be okay.

tests/generic_relations/tests.py
@@ -14,154 +14,178 @@
class GenericRelationsTests(TestCase):
- def test_generic_relations(self):
+ def setUp(self):
# Create the world in 7 lines of code...
@timgraham

timgraham May 28, 2014

Owner

I think this comment can go

@jose-lpa

jose-lpa May 28, 2014

Contributor

It was there before, so I left it, but feel free to remove it anyway.

tests/generic_relations/tests.py
)
+
mpk = ManualPK.objects.create(id=1)
mpk.tags.create(tag='mpk')
from django.db.models import Q
@timgraham

timgraham May 28, 2014

Owner

move import to top of file

@jose-lpa

jose-lpa May 28, 2014

Contributor

Agree. Sorry for missing that...

Owner

timgraham commented May 28, 2014

Thanks. After you give it another review, please go ahead and squash the commits and follow our commit message guidelines (e.g. "Split GenericRelationsTests.test_generic_relations into several tests; refs #18586."). Thanks!

Contributor

jose-lpa commented May 30, 2014

Done. Reviewed the issue and applied the changes you suggested (remove old comment and move import from the method to the global imports in the top of the file).

Also squashed the 4 commits into only one and edited the commit message accordingly.

)
- TaggedItem.objects.filter(tag='fatty').delete()
- ctype = ContentType.objects.get_for_model(lion)
- self.assertQuerysetEqual(Animal.objects.filter(tags__content_type=ctype), [
@timgraham

timgraham May 30, 2014

Owner

still seems like we're missing this type of query: filter(tags__content_type=ctype)

Split GenericRelationsTests.test_generic_relations into several tests…
…; refs #18586.

Refactored the first big unit test of GenericRelationsTests test case
into several, more granular unit tests checking just one feature.
+ def test_access_via_content_type(self):
+ """
+ Test lookups through content type.
+ """
@jose-lpa

jose-lpa May 31, 2014

Contributor

This is the missing test case that @timgraham noticed I've forgot to add.

Contributor

jose-lpa commented May 31, 2014

Added that missing test. Thanks!

Owner

timgraham commented Jun 1, 2014

merged in 7b064e5.

@timgraham timgraham closed this Jun 1, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment