diff options
author | Jason Myers <jason@jasonamyers.com> | 2013-11-02 23:36:09 -0500 |
---|---|---|
committer | Jason Myers <jason@jasonamyers.com> | 2013-11-02 23:50:49 -0500 |
commit | 7a61c68c50d3837c50e35c252fd76220f08b5290 (patch) | |
tree | 586f16a3f02c2b45ffb3dd2af834c0ef604e099c /tests/basic | |
parent | 0fdb692c6c94d912f17a3e2ad12413fb072d38ec (diff) | |
download | django-7a61c68c50d3837c50e35c252fd76220f08b5290.tar.gz |
PEP8 cleanup
Signed-off-by: Jason Myers <jason@jasonamyers.com>
Diffstat (limited to 'tests/basic')
-rw-r--r-- | tests/basic/models.py | 2 | ||||
-rw-r--r-- | tests/basic/tests.py | 48 |
2 files changed, 34 insertions, 16 deletions
diff --git a/tests/basic/models.py b/tests/basic/models.py index 38cb813d42..5e67b0dca9 100644 --- a/tests/basic/models.py +++ b/tests/basic/models.py @@ -19,11 +19,13 @@ class Article(models.Model): def __str__(self): return self.headline + class ArticleSelectOnSave(Article): class Meta: proxy = True select_on_save = True + @python_2_unicode_compatible class SelfRef(models.Model): selfref = models.ForeignKey('self', null=True, blank=True, diff --git a/tests/basic/tests.py b/tests/basic/tests.py index e4559dc7d7..976fb1124d 100644 --- a/tests/basic/tests.py +++ b/tests/basic/tests.py @@ -87,7 +87,8 @@ class ModelTest(TestCase): # Django raises an Article.DoesNotExist exception for get() if the # parameters don't match any object. - six.assertRaisesRegex(self, + six.assertRaisesRegex( + self, ObjectDoesNotExist, "Article matching query does not exist.", Article.objects.get, @@ -102,7 +103,8 @@ class ModelTest(TestCase): pub_date__month=8, ) - six.assertRaisesRegex(self, + six.assertRaisesRegex( + self, ObjectDoesNotExist, "Article matching query does not exist.", Article.objects.get, @@ -135,21 +137,24 @@ class ModelTest(TestCase): # Django raises an Article.MultipleObjectsReturned exception if the # lookup matches more than one object - six.assertRaisesRegex(self, + six.assertRaisesRegex( + self, MultipleObjectsReturned, "get\(\) returned more than one Article -- it returned 2!", Article.objects.get, headline__startswith='Area', ) - six.assertRaisesRegex(self, + six.assertRaisesRegex( + self, MultipleObjectsReturned, "get\(\) returned more than one Article -- it returned 2!", Article.objects.get, pub_date__year=2005, ) - six.assertRaisesRegex(self, + six.assertRaisesRegex( + self, MultipleObjectsReturned, "get\(\) returned more than one Article -- it returned 2!", Article.objects.get, @@ -165,14 +170,16 @@ class ModelTest(TestCase): Article(headline='Area %s' % i, pub_date=datetime(2005, 7, 28)) for i in range(MAX_GET_RESULTS) ) - six.assertRaisesRegex(self, + six.assertRaisesRegex( + self, MultipleObjectsReturned, "get\(\) returned more than one Article -- it returned %d!" % MAX_GET_RESULTS, Article.objects.get, headline__startswith='Area', ) Article.objects.create(headline='Area %s' % MAX_GET_RESULTS, pub_date=datetime(2005, 7, 28)) - six.assertRaisesRegex(self, + six.assertRaisesRegex( + self, MultipleObjectsReturned, "get\(\) returned more than one Article -- it returned more than %d!" % MAX_GET_RESULTS, Article.objects.get, @@ -219,7 +226,8 @@ class ModelTest(TestCase): self.assertEqual(a4.headline, 'Fourth article') # Don't use invalid keyword arguments. - six.assertRaisesRegex(self, + six.assertRaisesRegex( + self, TypeError, "'foo' is an invalid keyword argument for this function", Article, @@ -315,7 +323,8 @@ class ModelTest(TestCase): Article.objects.dates, ) - six.assertRaisesRegex(self, + six.assertRaisesRegex( + self, FieldDoesNotExist, "Article has no field named 'invalid_field'", Article.objects.dates, @@ -323,7 +332,8 @@ class ModelTest(TestCase): "year", ) - six.assertRaisesRegex(self, + six.assertRaisesRegex( + self, AssertionError, "'kind' must be one of 'year', 'month' or 'day'.", Article.objects.dates, @@ -331,7 +341,8 @@ class ModelTest(TestCase): "bad_kind", ) - six.assertRaisesRegex(self, + six.assertRaisesRegex( + self, AssertionError, "'order' must be either 'ASC' or 'DESC'.", Article.objects.dates, @@ -419,14 +430,16 @@ class ModelTest(TestCase): "<Article: Updated article 8>"]) # Also, once you have sliced you can't filter, re-order or combine - six.assertRaisesRegex(self, + six.assertRaisesRegex( + self, AssertionError, "Cannot filter a query once a slice has been taken.", Article.objects.all()[0:5].filter, id=a.id, ) - six.assertRaisesRegex(self, + six.assertRaisesRegex( + self, AssertionError, "Cannot reorder a query once a slice has been taken.", Article.objects.all()[0:5].order_by, @@ -461,7 +474,8 @@ class ModelTest(TestCase): # An Article instance doesn't have access to the "objects" attribute. # That's only available on the class. - six.assertRaisesRegex(self, + six.assertRaisesRegex( + self, AttributeError, "Manager isn't accessible via Article instances", getattr, @@ -605,8 +619,8 @@ class ModelTest(TestCase): ) dicts = Article.objects.filter( - pub_date__year=2008).extra(select={'dashed-value': '1'} - ).values('headline', 'dashed-value') + pub_date__year=2008).extra( + select={'dashed-value': '1'}).values('headline', 'dashed-value') self.assertEqual([sorted(d.items()) for d in dicts], [[('dashed-value', 1), ('headline', 'Article 11')], [('dashed-value', 1), ('headline', 'Article 12')]]) @@ -723,6 +737,7 @@ class ModelTest(TestCase): # hash) hash(Article()) + class ConcurrentSaveTests(TransactionTestCase): available_apps = ['basic'] @@ -808,6 +823,7 @@ class ManagerTest(TestCase): sorted(self.QUERYSET_PROXY_METHODS), ) + class SelectOnSaveTests(TestCase): def test_select_on_save(self): a1 = Article.objects.create(pub_date=datetime.now()) |