1
0
mirror of https://github.com/django/django.git synced 2025-10-24 14:16:09 +00:00

Convert all modeltests to use absolute imports, rather than relative ones.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16975 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Alex Gaynor
2011-10-13 18:04:12 +00:00
parent 99512d3544
commit d5a45d79fe
119 changed files with 380 additions and 187 deletions

View File

@@ -1,22 +1,24 @@
from __future__ import absolute_import
from operator import attrgetter
from django.test import TestCase
from models import Post, Question, Answer
from .models import Post, Question, Answer
class OrderWithRespectToTests(TestCase):
def test_basic(self):
q1 = Question.objects.create(text="Which Beatle starts with the letter 'R'?")
q2 = Question.objects.create(text="What is your name?")
Answer.objects.create(text="John", question=q1)
Answer.objects.create(text="Jonno", question=q2)
Answer.objects.create(text="Paul", question=q1)
Answer.objects.create(text="Paulo", question=q2)
Answer.objects.create(text="George", question=q1)
Answer.objects.create(text="Ringo", question=q1)
# The answers will always be ordered in the order they were inserted.
self.assertQuerysetEqual(
q1.answer_set.all(), [
@@ -24,7 +26,7 @@ class OrderWithRespectToTests(TestCase):
],
attrgetter("text"),
)
# We can retrieve the answers related to a particular object, in the
# order they were created, once we have a particular object.
a1 = Answer.objects.filter(question=q1)[0]
@@ -34,20 +36,20 @@ class OrderWithRespectToTests(TestCase):
a4 = list(Answer.objects.filter(question=q1))[-1]
self.assertEqual(a4.text, "Ringo")
self.assertEqual(a4.get_previous_in_order().text, "George")
# Determining (and setting) the ordering for a particular item is also
# possible.
id_list = [o.pk for o in q1.answer_set.all()]
self.assertEqual(a2.question.get_answer_order(), id_list)
a5 = Answer.objects.create(text="Number five", question=q1)
# It doesn't matter which answer we use to check the order, it will
# always be the same.
self.assertEqual(
a2.question.get_answer_order(), a5.question.get_answer_order()
)
# The ordering can be altered:
id_list = [o.pk for o in q1.answer_set.all()]
x = id_list.pop()