Revert "Splitted expressions tests into smaller methods"

This reverts commit c2532825db.
This commit is contained in:
Anssi Kääriäinen 2012-10-03 18:09:02 +03:00
parent c2150d4d2c
commit 7f4dbdc036
1 changed files with 15 additions and 28 deletions

View File

@ -9,7 +9,7 @@ from .models import Company, Employee
class ExpressionsTests(TestCase): class ExpressionsTests(TestCase):
def setUp(self): def test_filter(self):
Company.objects.create( Company.objects.create(
name="Example Inc.", num_employees=2300, num_chairs=5, is_large=False, name="Example Inc.", num_employees=2300, num_chairs=5, is_large=False,
ceo=Employee.objects.create(firstname="Joe", lastname="Smith") ceo=Employee.objects.create(firstname="Joe", lastname="Smith")
@ -23,8 +23,6 @@ class ExpressionsTests(TestCase):
ceo=Employee.objects.create(firstname="Max", lastname="Mustermann") ceo=Employee.objects.create(firstname="Max", lastname="Mustermann")
) )
def test_filter(self):
company_query = Company.objects.values( company_query = Company.objects.values(
"name", "num_employees", "num_chairs", "is_large" "name", "num_employees", "num_chairs", "is_large"
).order_by( ).order_by(
@ -160,13 +158,6 @@ class ExpressionsTests(TestCase):
], ],
lambda o: o, lambda o: o,
) )
def test_comparisons(self):
company_query = Company.objects.values(
"name", "num_employees", "num_chairs", "is_large"
).order_by(
"name", "num_employees", "num_chairs", "is_large"
)
# The comparison operators and the bitwise unary not can be used # The comparison operators and the bitwise unary not can be used
# to assign to boolean fields # to assign to boolean fields
for expression in ( for expression in (
@ -189,19 +180,19 @@ class ExpressionsTests(TestCase):
self.assertQuerysetEqual( self.assertQuerysetEqual(
company_query, [ company_query, [
{ {
'num_chairs': 5, 'num_chairs': 5294600,
'name': 'Example Inc.', 'name': 'Example Inc.',
'num_employees': 2300, 'num_employees': 2300,
'is_large': True 'is_large': True
}, },
{ {
'num_chairs': 4, 'num_chairs': 15,
'name': 'Foobar Ltd.', 'name': 'Foobar Ltd.',
'num_employees': 3, 'num_employees': 3,
'is_large': False 'is_large': False
}, },
{ {
'num_chairs': 1, 'num_chairs': 1088,
'name': 'Test GmbH', 'name': 'Test GmbH',
'num_employees': 32, 'num_employees': 32,
'is_large': False 'is_large': False
@ -239,31 +230,28 @@ class ExpressionsTests(TestCase):
lambda c: six.text_type(c.point_of_contact), lambda c: six.text_type(c.point_of_contact),
) )
def test_joins(self):
c = Company.objects.all()[0] c = Company.objects.all()[0]
c.point_of_contact = Employee.objects.create( c.point_of_contact = Employee.objects.create(firstname="Guido", lastname="van Rossum")
firstname="Guido", lastname="van Rossum")
old_ceo = c.ceo
c.ceo = c.point_of_contact
c.save() c.save()
# F Expressions can also span joins # F Expressions can also span joins
self.assertQuerysetEqual( self.assertQuerysetEqual(
Company.objects.filter( Company.objects.filter(ceo__firstname=F("point_of_contact__firstname")), [
ceo__firstname=F("point_of_contact__firstname")), "Foobar Ltd.",
[ "Test GmbH",
"Example Inc.",
], ],
lambda c: c.name lambda c: c.name
) )
c.ceo = old_ceo
c.save()
# Guido is point of contanct but not CEO. For the null cases we do
# not generate a match.
Company.objects.exclude( Company.objects.exclude(
ceo__firstname=F("point_of_contact__firstname") ceo__firstname=F("point_of_contact__firstname")
).update(name="foo") ).update(name="foo")
self.assertEqual(Company.objects.filter(name="foo").count(), 1) self.assertEqual(
Company.objects.exclude(
ceo__firstname=F('point_of_contact__firstname')
).get().name,
"foo",
)
self.assertRaises(FieldError, self.assertRaises(FieldError,
lambda: Company.objects.exclude( lambda: Company.objects.exclude(
@ -271,7 +259,6 @@ class ExpressionsTests(TestCase):
).update(name=F('point_of_contact__lastname')) ).update(name=F('point_of_contact__lastname'))
) )
def test_save(self):
# F expressions can be used to update attributes on single objects # F expressions can be used to update attributes on single objects
test_gmbh = Company.objects.get(name="Test GmbH") test_gmbh = Company.objects.get(name="Test GmbH")
self.assertEqual(test_gmbh.num_employees, 32) self.assertEqual(test_gmbh.num_employees, 32)