summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAnssi Kääriäinen <akaariai@gmail.com>2012-10-03 18:21:39 +0300
committerAnssi Kääriäinen <akaariai@gmail.com>2012-10-10 01:15:29 +0300
commita8b1861fc4d0a48b4879af803bba094eef145017 (patch)
treee4e8e971cc5245c1864a7cab642372cd1027116b /tests
parent7f4dbdc036a4439ed3e4954625fe91596b314a36 (diff)
Revert "Fixed #16211 -- Added comparison and negation ops to F() expressions"
This reverts commit 28abf5f0ebc9d380f25dd278d7ef4642c4504545. Conflicts: docs/releases/1.5.txt
Diffstat (limited to 'tests')
-rw-r--r--tests/modeltests/expressions/models.py2
-rw-r--r--tests/modeltests/expressions/tests.py109
2 files changed, 20 insertions, 91 deletions
diff --git a/tests/modeltests/expressions/models.py b/tests/modeltests/expressions/models.py
index 15f0d24541..f592a0eb13 100644
--- a/tests/modeltests/expressions/models.py
+++ b/tests/modeltests/expressions/models.py
@@ -27,8 +27,6 @@ class Company(models.Model):
Employee,
related_name='company_point_of_contact_set',
null=True)
- is_large = models.BooleanField(
- blank=True)
def __str__(self):
return self.name
diff --git a/tests/modeltests/expressions/tests.py b/tests/modeltests/expressions/tests.py
index 14419ec55b..99eb07e370 100644
--- a/tests/modeltests/expressions/tests.py
+++ b/tests/modeltests/expressions/tests.py
@@ -11,22 +11,22 @@ from .models import Company, Employee
class ExpressionsTests(TestCase):
def test_filter(self):
Company.objects.create(
- name="Example Inc.", num_employees=2300, num_chairs=5, is_large=False,
+ name="Example Inc.", num_employees=2300, num_chairs=5,
ceo=Employee.objects.create(firstname="Joe", lastname="Smith")
)
Company.objects.create(
- name="Foobar Ltd.", num_employees=3, num_chairs=4, is_large=False,
+ name="Foobar Ltd.", num_employees=3, num_chairs=4,
ceo=Employee.objects.create(firstname="Frank", lastname="Meyer")
)
Company.objects.create(
- name="Test GmbH", num_employees=32, num_chairs=1, is_large=False,
+ name="Test GmbH", num_employees=32, num_chairs=1,
ceo=Employee.objects.create(firstname="Max", lastname="Mustermann")
)
company_query = Company.objects.values(
- "name", "num_employees", "num_chairs", "is_large"
+ "name", "num_employees", "num_chairs"
).order_by(
- "name", "num_employees", "num_chairs", "is_large"
+ "name", "num_employees", "num_chairs"
)
# We can filter for companies where the number of employees is greater
@@ -37,13 +37,11 @@ class ExpressionsTests(TestCase):
"num_chairs": 5,
"name": "Example Inc.",
"num_employees": 2300,
- "is_large": False
},
{
"num_chairs": 1,
"name": "Test GmbH",
- "num_employees": 32,
- "is_large": False
+ "num_employees": 32
},
],
lambda o: o
@@ -57,20 +55,17 @@ class ExpressionsTests(TestCase):
{
"num_chairs": 2300,
"name": "Example Inc.",
- "num_employees": 2300,
- "is_large": False
+ "num_employees": 2300
},
{
"num_chairs": 3,
"name": "Foobar Ltd.",
- "num_employees": 3,
- "is_large": False
+ "num_employees": 3
},
{
"num_chairs": 32,
"name": "Test GmbH",
- "num_employees": 32,
- "is_large": False
+ "num_employees": 32
}
],
lambda o: o
@@ -84,20 +79,17 @@ class ExpressionsTests(TestCase):
{
'num_chairs': 2302,
'name': 'Example Inc.',
- 'num_employees': 2300,
- 'is_large': False
+ 'num_employees': 2300
},
{
'num_chairs': 5,
'name': 'Foobar Ltd.',
- 'num_employees': 3,
- 'is_large': False
+ 'num_employees': 3
},
{
'num_chairs': 34,
'name': 'Test GmbH',
- 'num_employees': 32,
- 'is_large': False
+ 'num_employees': 32
}
],
lambda o: o,
@@ -112,20 +104,17 @@ class ExpressionsTests(TestCase):
{
'num_chairs': 6900,
'name': 'Example Inc.',
- 'num_employees': 2300,
- 'is_large': False
+ 'num_employees': 2300
},
{
'num_chairs': 9,
'name': 'Foobar Ltd.',
- 'num_employees': 3,
- 'is_large': False
+ 'num_employees': 3
},
{
'num_chairs': 96,
'name': 'Test GmbH',
- 'num_employees': 32,
- 'is_large': False
+ 'num_employees': 32
}
],
lambda o: o,
@@ -140,80 +129,21 @@ class ExpressionsTests(TestCase):
{
'num_chairs': 5294600,
'name': 'Example Inc.',
- 'num_employees': 2300,
- 'is_large': False
+ 'num_employees': 2300
},
{
'num_chairs': 15,
'name': 'Foobar Ltd.',
- 'num_employees': 3,
- 'is_large': False
+ 'num_employees': 3
},
{
'num_chairs': 1088,
'name': 'Test GmbH',
- 'num_employees': 32,
- 'is_large': False
+ 'num_employees': 32
}
],
lambda o: o,
)
- # The comparison operators and the bitwise unary not can be used
- # to assign to boolean fields
- for expression in (
- # Check boundaries
- ~(F('num_employees') < 33),
- ~(F('num_employees') <= 32),
- (F('num_employees') > 2299),
- (F('num_employees') >= 2300),
- (F('num_employees') == 2300),
- ((F('num_employees') + 1 != 4) & (32 != F('num_employees'))),
- # Inverted argument order works too
- (2299 < F('num_employees')),
- (2300 <= F('num_employees'))
- ):
- # Test update by F-expression
- company_query.update(
- is_large=expression
- )
- # Compare results
- self.assertQuerysetEqual(
- company_query, [
- {
- 'num_chairs': 5294600,
- 'name': 'Example Inc.',
- 'num_employees': 2300,
- 'is_large': True
- },
- {
- 'num_chairs': 15,
- 'name': 'Foobar Ltd.',
- 'num_employees': 3,
- 'is_large': False
- },
- {
- 'num_chairs': 1088,
- 'name': 'Test GmbH',
- 'num_employees': 32,
- 'is_large': False
- }
- ],
- lambda o: o,
- )
- # Reset values
- company_query.update(
- is_large=False
- )
-
- # The python boolean operators should be avoided as they yield
- # unexpected results
- test_gmbh = Company.objects.get(name="Test GmbH")
- with self.assertRaises(TypeError):
- test_gmbh.is_large = not F('is_large')
- with self.assertRaises(TypeError):
- test_gmbh.is_large = F('is_large') and F('is_large')
- with self.assertRaises(TypeError):
- test_gmbh.is_large = F('is_large') or F('is_large')
# The relation of a foreign key can become copied over to an other
# foreign key.
@@ -272,8 +202,9 @@ class ExpressionsTests(TestCase):
test_gmbh.point_of_contact = None
test_gmbh.save()
self.assertTrue(test_gmbh.point_of_contact is None)
- with self.assertRaises(ValueError):
+ def test():
test_gmbh.point_of_contact = F("ceo")
+ self.assertRaises(ValueError, test)
test_gmbh.point_of_contact = test_gmbh.ceo
test_gmbh.save()