diff options
| author | Russell Keith-Magee <russell@keith-magee.com> | 2010-04-01 16:48:16 +0000 |
|---|---|---|
| committer | Russell Keith-Magee <russell@keith-magee.com> | 2010-04-01 16:48:16 +0000 |
| commit | f7cf58ac0ebf720e5c48f00e99c31cf39c4fca50 (patch) | |
| tree | 048de60757bde88fb24d035508559d78b851884d /tests | |
| parent | c39ec6dccb389fbb4047e44f5247e18bb76ae598 (diff) | |
Fixed #12429 -- Ensure that raw queries call resolve_columns if the backend defines it. This ensures (as much as possible) that the model values returned by a raw query match that in normal queries. Thanks to Ian Kelly for the report.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12904 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/modeltests/raw_query/fixtures/raw_query_books.json (renamed from tests/modeltests/raw_query/fixtures/initial_data.json) | 16 | ||||
| -rw-r--r-- | tests/modeltests/raw_query/models.py | 2 | ||||
| -rw-r--r-- | tests/modeltests/raw_query/tests.py | 15 |
3 files changed, 25 insertions, 8 deletions
diff --git a/tests/modeltests/raw_query/fixtures/initial_data.json b/tests/modeltests/raw_query/fixtures/raw_query_books.json index 3ff9810b45..35879aa5eb 100644 --- a/tests/modeltests/raw_query/fixtures/initial_data.json +++ b/tests/modeltests/raw_query/fixtures/raw_query_books.json @@ -40,7 +40,9 @@ "model": "raw_query.book", "fields": { "author": 1, - "title": "The awesome book" + "title": "The awesome book", + "paperback": false, + "opening_line": "It was a bright cold day in April and the clocks were striking thirteen." } }, { @@ -48,7 +50,9 @@ "model": "raw_query.book", "fields": { "author": 1, - "title": "The horrible book" + "title": "The horrible book", + "paperback": true, + "opening_line": "On an evening in the latter part of May a middle-aged man was walking homeward from Shaston to the village of Marlott, in the adjoining Vale of Blakemore, or Blackmoor." } }, { @@ -56,7 +60,9 @@ "model": "raw_query.book", "fields": { "author": 1, - "title": "Another awesome book" + "title": "Another awesome book", + "paperback": false, + "opening_line": "A squat grey building of only thirty-four stories." } }, { @@ -64,7 +70,9 @@ "model": "raw_query.book", "fields": { "author": 3, - "title": "Some other book" + "title": "Some other book", + "paperback": true, + "opening_line": "It was the day my grandmother exploded." } }, { diff --git a/tests/modeltests/raw_query/models.py b/tests/modeltests/raw_query/models.py index 6188d58cb3..bb42b5be2b 100644 --- a/tests/modeltests/raw_query/models.py +++ b/tests/modeltests/raw_query/models.py @@ -17,6 +17,8 @@ class Author(models.Model): class Book(models.Model): title = models.CharField(max_length=255) author = models.ForeignKey(Author) + paperback = models.BooleanField() + opening_line = models.TextField() class Coffee(models.Model): brand = models.CharField(max_length=255, db_column="name") diff --git a/tests/modeltests/raw_query/tests.py b/tests/modeltests/raw_query/tests.py index 447849abb9..a0325eff97 100644 --- a/tests/modeltests/raw_query/tests.py +++ b/tests/modeltests/raw_query/tests.py @@ -7,6 +7,7 @@ from models import Author, Book, Coffee, Reviewer, FriendlyAuthor class RawQueryTests(TestCase): + fixtures = ['raw_query_books.json'] def assertSuccessfulRawQuery(self, model, query, expected_results, expected_annotations=(), params=[], translations=None): @@ -14,10 +15,10 @@ class RawQueryTests(TestCase): Execute the passed query against the passed model and check the output """ results = list(model.objects.raw(query, params=params, translations=translations)) - self.assertProcessed(results, expected_results, expected_annotations) + self.assertProcessed(model, results, expected_results, expected_annotations) self.assertAnnotations(results, expected_annotations) - def assertProcessed(self, results, orig, expected_annotations=()): + def assertProcessed(self, model, results, orig, expected_annotations=()): """ Compare the results of a raw query against expected results """ @@ -27,7 +28,13 @@ class RawQueryTests(TestCase): for annotation in expected_annotations: setattr(orig_item, *annotation) - self.assertEqual(item.id, orig_item.id) + for field in model._meta.fields: + # Check that all values on the model are equal + self.assertEquals(getattr(item,field.attname), + getattr(orig_item,field.attname)) + # This includes checking that they are the same type + self.assertEquals(type(getattr(item,field.attname)), + type(getattr(orig_item,field.attname))) def assertNoAnnotations(self, results): """ @@ -115,7 +122,7 @@ class RawQueryTests(TestCase): author = Author.objects.all()[2] params = [author.first_name] results = list(Author.objects.raw(query, params=params)) - self.assertProcessed(results, [author]) + self.assertProcessed(Author, results, [author]) self.assertNoAnnotations(results) self.assertEqual(len(results), 1) |
