Used more specific test assertions.

This commit is contained in:
Aymeric Augustin 2014-04-09 22:20:22 +02:00
parent 11e7254c3d
commit 2791fbf59d
11 changed files with 19 additions and 20 deletions

View File

@ -475,8 +475,7 @@ class LoginTest(AuthViewsTestCase):
self.assertEqual(response.context['site_name'], site.name) self.assertEqual(response.context['site_name'], site.name)
else: else:
self.assertIsInstance(response.context['site'], RequestSite) self.assertIsInstance(response.context['site'], RequestSite)
self.assertTrue(isinstance(response.context['form'], AuthenticationForm), self.assertIsInstance(response.context['form'], AuthenticationForm)
'Login form is not an AuthenticationForm')
def test_security_check(self, password='password'): def test_security_check(self, password='password'):
login_url = reverse('login') login_url = reverse('login')

View File

@ -246,11 +246,11 @@ class SessionFormTests(TestCase):
def test_init(self): def test_init(self):
request = get_request() request = get_request()
testform = SessionWizardView.as_view([('start', Step1)]) testform = SessionWizardView.as_view([('start', Step1)])
self.assertTrue(isinstance(testform(request), TemplateResponse)) self.assertIsInstance(testform(request), TemplateResponse)
class CookieFormTests(TestCase): class CookieFormTests(TestCase):
def test_init(self): def test_init(self):
request = get_request() request = get_request()
testform = CookieWizardView.as_view([('start', Step1)]) testform = CookieWizardView.as_view([('start', Step1)])
self.assertTrue(isinstance(testform(request), TemplateResponse)) self.assertIsInstance(testform(request), TemplateResponse)

View File

@ -106,7 +106,7 @@ class GeoIPTest(unittest.TestCase):
self.assertEqual('TX', d['region']) self.assertEqual('TX', d['region'])
self.assertEqual(713, d['area_code']) self.assertEqual(713, d['area_code'])
geom = g.geos(query) geom = g.geos(query)
self.assertTrue(isinstance(geom, GEOSGeometry)) self.assertIsInstance(geom, GEOSGeometry)
lon, lat = (-95.4010, 29.7079) lon, lat = (-95.4010, 29.7079)
lat_lon = g.lat_lon(query) lat_lon = g.lat_lon(query)
lat_lon = (lat_lon[1], lat_lon[0]) lat_lon = (lat_lon[1], lat_lon[0])

View File

@ -201,7 +201,7 @@ class GeoModelTest(TestCase):
as_text = 'ST_AsText' if postgis else 'asText' as_text = 'ST_AsText' if postgis else 'asText'
cities2 = City.objects.raw('select id, name, %s(point) from geoapp_city' % as_text) cities2 = City.objects.raw('select id, name, %s(point) from geoapp_city' % as_text)
self.assertEqual(len(cities1), len(list(cities2))) self.assertEqual(len(cities1), len(list(cities2)))
self.assertTrue(isinstance(cities2[0].point, Point)) self.assertIsInstance(cities2[0].point, Point)
@skipUnless(HAS_GEOS and HAS_SPATIAL_DB, "Geos and spatial db are required.") @skipUnless(HAS_GEOS and HAS_SPATIAL_DB, "Geos and spatial db are required.")

View File

@ -179,8 +179,8 @@ class RelatedGeoModelTest(TestCase):
for m, d, t in zip(gqs, gvqs, gvlqs): for m, d, t in zip(gqs, gvqs, gvlqs):
# The values should be Geometry objects and not raw strings returned # The values should be Geometry objects and not raw strings returned
# by the spatial database. # by the spatial database.
self.assertTrue(isinstance(d['point'], Geometry)) self.assertIsInstance(d['point'], Geometry)
self.assertTrue(isinstance(t[1], Geometry)) self.assertIsInstance(t[1], Geometry)
self.assertEqual(m.point, d['point']) self.assertEqual(m.point, d['point'])
self.assertEqual(m.point, t[1]) self.assertEqual(m.point, t[1])
@ -255,7 +255,7 @@ class RelatedGeoModelTest(TestCase):
qs = Location.objects.filter(id=5).annotate(num_cities=Count('city')).values('id', 'point', 'num_cities') qs = Location.objects.filter(id=5).annotate(num_cities=Count('city')).values('id', 'point', 'num_cities')
self.assertEqual(1, len(qs)) self.assertEqual(1, len(qs))
self.assertEqual(2, qs[0]['num_cities']) self.assertEqual(2, qs[0]['num_cities'])
self.assertTrue(isinstance(qs[0]['point'], GEOSGeometry)) self.assertIsInstance(qs[0]['point'], GEOSGeometry)
# TODO: The phantom model does appear on Oracle. # TODO: The phantom model does appear on Oracle.
@no_oracle @no_oracle

View File

@ -93,7 +93,7 @@ class DistanceTest(unittest.TestCase):
self.assertEqual(d5, 50) self.assertEqual(d5, 50)
a5 = d1 * D(m=10) a5 = d1 * D(m=10)
self.assertTrue(isinstance(a5, Area)) self.assertIsInstance(a5, Area)
self.assertEqual(a5.sq_m, 100 * 10) self.assertEqual(a5.sq_m, 100 * 10)
with self.assertRaises(TypeError): with self.assertRaises(TypeError):

View File

@ -26,7 +26,7 @@ class SitesFrameworkTests(TestCase):
def test_site_manager(self): def test_site_manager(self):
# Make sure that get_current() does not return a deleted Site object. # Make sure that get_current() does not return a deleted Site object.
s = Site.objects.get_current() s = Site.objects.get_current()
self.assertTrue(isinstance(s, Site)) self.assertIsInstance(s, Site)
s.delete() s.delete()
self.assertRaises(ObjectDoesNotExist, Site.objects.get_current) self.assertRaises(ObjectDoesNotExist, Site.objects.get_current)
@ -57,7 +57,7 @@ class SitesFrameworkTests(TestCase):
"SERVER_PORT": "80", "SERVER_PORT": "80",
} }
site = get_current_site(request) site = get_current_site(request)
self.assertTrue(isinstance(site, Site)) self.assertIsInstance(site, Site)
self.assertEqual(site.id, settings.SITE_ID) self.assertEqual(site.id, settings.SITE_ID)
# Test that an exception is raised if the sites framework is installed # Test that an exception is raised if the sites framework is installed
@ -68,7 +68,7 @@ class SitesFrameworkTests(TestCase):
# A RequestSite is returned if the sites framework is not installed # A RequestSite is returned if the sites framework is not installed
with self.modify_settings(INSTALLED_APPS={'remove': 'django.contrib.sites'}): with self.modify_settings(INSTALLED_APPS={'remove': 'django.contrib.sites'}):
site = get_current_site(request) site = get_current_site(request)
self.assertTrue(isinstance(site, RequestSite)) self.assertIsInstance(site, RequestSite)
self.assertEqual(site.name, "example.com") self.assertEqual(site.name, "example.com")
def test_domain_name_with_whitespaces(self): def test_domain_name_with_whitespaces(self):

View File

@ -620,8 +620,8 @@ class SimpleTestCase(unittest.TestCase):
# test that max_length and min_length are always accepted # test that max_length and min_length are always accepted
if issubclass(fieldclass, CharField): if issubclass(fieldclass, CharField):
field_kwargs.update({'min_length': 2, 'max_length': 20}) field_kwargs.update({'min_length': 2, 'max_length': 20})
self.assertTrue(isinstance(fieldclass(*field_args, **field_kwargs), self.assertIsInstance(fieldclass(*field_args, **field_kwargs),
fieldclass)) fieldclass)
def assertHTMLEqual(self, html1, html2, msg=None): def assertHTMLEqual(self, html1, html2, msg=None):
""" """

View File

@ -646,7 +646,7 @@ class BackendTestCase(TestCase):
Test that cursors can be used as a context manager Test that cursors can be used as a context manager
""" """
with connection.cursor() as cursor: with connection.cursor() as cursor:
self.assertTrue(isinstance(cursor, CursorWrapper)) self.assertIsInstance(cursor, CursorWrapper)
# Both InterfaceError and ProgrammingError seem to be used when # Both InterfaceError and ProgrammingError seem to be used when
# accessing closed cursor (psycopg2 has InterfaceError, rest seem # accessing closed cursor (psycopg2 has InterfaceError, rest seem
# to use ProgrammingError). # to use ProgrammingError).
@ -661,7 +661,7 @@ class BackendTestCase(TestCase):
# psycopg2 offers us a way to check that by closed attribute. # psycopg2 offers us a way to check that by closed attribute.
# So, run only on psycopg2 for that reason. # So, run only on psycopg2 for that reason.
with connection.cursor() as cursor: with connection.cursor() as cursor:
self.assertTrue(isinstance(cursor, CursorWrapper)) self.assertIsInstance(cursor, CursorWrapper)
self.assertTrue(cursor.closed) self.assertTrue(cursor.closed)

View File

@ -1908,7 +1908,7 @@ class FormsTestCase(TestCase):
field = ChoicesField() field = ChoicesField()
field2 = copy.deepcopy(field) field2 = copy.deepcopy(field)
self.assertTrue(isinstance(field2, ChoicesField)) self.assertIsInstance(field2, ChoicesField)
self.assertFalse(id(field2.fields) == id(field.fields)) self.assertFalse(id(field2.fields) == id(field.fields))
self.assertFalse(id(field2.fields[0].choices) == self.assertFalse(id(field2.fields[0].choices) ==
id(field.fields[0].choices)) id(field.fields[0].choices))
@ -2152,7 +2152,7 @@ class FormsTestCase(TestCase):
e.append('Foo') e.append('Foo')
e.append(ValidationError('Foo%(bar)s', code='foobar', params={'bar': 'bar'})) e.append(ValidationError('Foo%(bar)s', code='foobar', params={'bar': 'bar'}))
self.assertTrue(isinstance(e, list)) self.assertIsInstance(e, list)
self.assertIn('Foo', e) self.assertIn('Foo', e)
self.assertIn('Foo', forms.ValidationError(e)) self.assertIn('Foo', forms.ValidationError(e))

View File

@ -298,7 +298,7 @@ class BooleanFieldTests(unittest.TestCase):
# conversions are applied with an offset # conversions are applied with an offset
b5 = BooleanModel.objects.all().extra( b5 = BooleanModel.objects.all().extra(
select={'string_col': 'string'})[0] select={'string_col': 'string'})[0]
self.assertFalse(isinstance(b5.pk, bool)) self.assertNotIsInstance(b5.pk, bool)
def test_select_related(self): def test_select_related(self):
""" """