1
0
mirror of https://github.com/django/django.git synced 2025-10-23 21:59:11 +00:00

Replaced use of TestCase.fail() with assertRaises().

Also removed try/except/fail antipattern that hides exceptions.
This commit is contained in:
Tim Graham
2016-06-28 11:21:26 -04:00
committed by GitHub
parent c1b6f554e4
commit c9ae09addf
30 changed files with 205 additions and 447 deletions

View File

@@ -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):
"""