summaryrefslogtreecommitdiff
path: root/tests/raw_query
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2016-06-28 11:21:26 -0400
committerGitHub <noreply@github.com>2016-06-28 11:21:26 -0400
commitc9ae09addffb839403312131d4251e9d8b454508 (patch)
tree74913fbe2e90d88e094f8594947ebf313ec5f12f /tests/raw_query
parentc1b6f554e405fe733e8d80f7e3d77c277810e707 (diff)
downloaddjango-c9ae09addffb839403312131d4251e9d8b454508.tar.gz
Replaced use of TestCase.fail() with assertRaises().
Also removed try/except/fail antipattern that hides exceptions.
Diffstat (limited to 'tests/raw_query')
-rw-r--r--tests/raw_query/tests.py10
1 files changed, 2 insertions, 8 deletions
diff --git a/tests/raw_query/tests.py b/tests/raw_query/tests.py
index f4fe90aeb6..4c791dd206 100644
--- a/tests/raw_query/tests.py
+++ b/tests/raw_query/tests.py
@@ -221,11 +221,8 @@ class RawQueryTests(TestCase):
def test_missing_fields_without_PK(self):
query = "SELECT first_name, dob FROM raw_query_author"
- try:
+ with self.assertRaisesMessage(InvalidQuery, 'Raw query must include the primary key'):
list(Author.objects.raw(query))
- self.fail('Query without primary key should fail')
- except InvalidQuery:
- pass
def test_annotations(self):
query = (
@@ -290,10 +287,7 @@ class RawQueryTests(TestCase):
self.assertNumQueries(1, list, Author.objects.raw("SELECT * FROM raw_query_author"))
def test_subquery_in_raw_sql(self):
- try:
- list(Book.objects.raw('SELECT id FROM (SELECT * FROM raw_query_book WHERE paperback IS NOT NULL) sq'))
- except InvalidQuery:
- self.fail("Using a subquery in a RawQuerySet raised InvalidQuery")
+ list(Book.objects.raw('SELECT id FROM (SELECT * FROM raw_query_book WHERE paperback IS NOT NULL) sq'))
def test_db_column_name_is_used_in_raw_query(self):
"""