summaryrefslogtreecommitdiff
path: root/tests/generic_views
diff options
context:
space:
mode:
authorHasan Ramezani <hasan.r67@gmail.com>2020-10-18 18:29:52 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2020-11-06 09:24:50 +0100
commit3f7b3275627385f8f7531fca01cdda50d4ec6b6e (patch)
treefb082d40e73f6c877911eab92229ac21cdfaa5bc /tests/generic_views
parent13b6fff11703a694e155b84d41d02822bbc0aaa0 (diff)
downloaddjango-3f7b3275627385f8f7531fca01cdda50d4ec6b6e.tar.gz
Fixed #31235 -- Made assertQuerysetEqual() compare querysets directly.
This also replaces assertQuerysetEqual() to assertSequenceEqual()/assertCountEqual() where appropriate. Co-authored-by: Peter Inglesby <peter.inglesby@gmail.com> Co-authored-by: Mariusz Felisiak <felisiak.mariusz@gmail.com>
Diffstat (limited to 'tests/generic_views')
-rw-r--r--tests/generic_views/test_edit.py24
1 files changed, 12 insertions, 12 deletions
diff --git a/tests/generic_views/test_edit.py b/tests/generic_views/test_edit.py
index bdabf1d0d2..ca7c457124 100644
--- a/tests/generic_views/test_edit.py
+++ b/tests/generic_views/test_edit.py
@@ -105,7 +105,7 @@ class CreateViewTests(TestCase):
res = self.client.post('/edit/authors/create/', {'name': 'Randall Munroe', 'slug': 'randall-munroe'})
self.assertEqual(res.status_code, 302)
self.assertRedirects(res, '/list/authors/')
- self.assertQuerysetEqual(Author.objects.all(), ['<Author: Randall Munroe>'])
+ self.assertQuerysetEqual(Author.objects.values_list('name', flat=True), ['Randall Munroe'])
def test_create_invalid(self):
res = self.client.post('/edit/authors/create/', {'name': 'A' * 101, 'slug': 'randall-munroe'})
@@ -119,20 +119,20 @@ class CreateViewTests(TestCase):
self.assertEqual(res.status_code, 302)
artist = Artist.objects.get(name='Rene Magritte')
self.assertRedirects(res, '/detail/artist/%d/' % artist.pk)
- self.assertQuerysetEqual(Artist.objects.all(), ['<Artist: Rene Magritte>'])
+ self.assertQuerysetEqual(Artist.objects.all(), [artist])
def test_create_with_redirect(self):
res = self.client.post('/edit/authors/create/redirect/', {'name': 'Randall Munroe', 'slug': 'randall-munroe'})
self.assertEqual(res.status_code, 302)
self.assertRedirects(res, '/edit/authors/create/')
- self.assertQuerysetEqual(Author.objects.all(), ['<Author: Randall Munroe>'])
+ self.assertQuerysetEqual(Author.objects.values_list('name', flat=True), ['Randall Munroe'])
def test_create_with_interpolated_redirect(self):
res = self.client.post(
'/edit/authors/create/interpolate_redirect/',
{'name': 'Randall Munroe', 'slug': 'randall-munroe'}
)
- self.assertQuerysetEqual(Author.objects.all(), ['<Author: Randall Munroe>'])
+ self.assertQuerysetEqual(Author.objects.values_list('name', flat=True), ['Randall Munroe'])
self.assertEqual(res.status_code, 302)
pk = Author.objects.first().pk
self.assertRedirects(res, '/edit/author/%d/update/' % pk)
@@ -157,7 +157,7 @@ class CreateViewTests(TestCase):
self.assertEqual(res.status_code, 302)
obj = Author.objects.get(slug='randall-munroe')
self.assertRedirects(res, reverse('author_detail', kwargs={'pk': obj.pk}))
- self.assertQuerysetEqual(Author.objects.all(), ['<Author: Randall Munroe>'])
+ self.assertQuerysetEqual(Author.objects.all(), [obj])
def test_create_without_redirect(self):
msg = (
@@ -239,7 +239,7 @@ class UpdateViewTests(TestCase):
)
self.assertEqual(res.status_code, 302)
self.assertRedirects(res, '/list/authors/')
- self.assertQuerysetEqual(Author.objects.all(), ['<Author: Randall Munroe (xkcd)>'])
+ self.assertQuerysetEqual(Author.objects.values_list('name', flat=True), ['Randall Munroe (xkcd)'])
def test_update_invalid(self):
res = self.client.post(
@@ -249,7 +249,7 @@ class UpdateViewTests(TestCase):
self.assertEqual(res.status_code, 200)
self.assertTemplateUsed(res, 'generic_views/author_form.html')
self.assertEqual(len(res.context['form'].errors), 1)
- self.assertQuerysetEqual(Author.objects.all(), ['<Author: Randall Munroe>'])
+ self.assertQuerysetEqual(Author.objects.all(), [self.author])
self.assertEqual(res.context['view'].get_form_called_count, 1)
def test_update_with_object_url(self):
@@ -257,7 +257,7 @@ class UpdateViewTests(TestCase):
res = self.client.post('/edit/artists/%d/update/' % a.pk, {'name': 'Rene Magritte'})
self.assertEqual(res.status_code, 302)
self.assertRedirects(res, '/detail/artist/%d/' % a.pk)
- self.assertQuerysetEqual(Artist.objects.all(), ['<Artist: Rene Magritte>'])
+ self.assertQuerysetEqual(Artist.objects.all(), [a])
def test_update_with_redirect(self):
res = self.client.post(
@@ -266,14 +266,14 @@ class UpdateViewTests(TestCase):
)
self.assertEqual(res.status_code, 302)
self.assertRedirects(res, '/edit/authors/create/')
- self.assertQuerysetEqual(Author.objects.all(), ['<Author: Randall Munroe (author of xkcd)>'])
+ self.assertQuerysetEqual(Author.objects.values_list('name', flat=True), ['Randall Munroe (author of xkcd)'])
def test_update_with_interpolated_redirect(self):
res = self.client.post(
'/edit/author/%d/update/interpolate_redirect/' % self.author.pk,
{'name': 'Randall Munroe (author of xkcd)', 'slug': 'randall-munroe'}
)
- self.assertQuerysetEqual(Author.objects.all(), ['<Author: Randall Munroe (author of xkcd)>'])
+ self.assertQuerysetEqual(Author.objects.values_list('name', flat=True), ['Randall Munroe (author of xkcd)'])
self.assertEqual(res.status_code, 302)
pk = Author.objects.first().pk
self.assertRedirects(res, '/edit/author/%d/update/' % pk)
@@ -301,7 +301,7 @@ class UpdateViewTests(TestCase):
)
self.assertEqual(res.status_code, 302)
self.assertRedirects(res, '/detail/author/%d/' % self.author.pk)
- self.assertQuerysetEqual(Author.objects.all(), ['<Author: Randall Munroe (author of xkcd)>'])
+ self.assertQuerysetEqual(Author.objects.values_list('name', flat=True), ['Randall Munroe (author of xkcd)'])
def test_update_without_redirect(self):
msg = (
@@ -327,7 +327,7 @@ class UpdateViewTests(TestCase):
res = self.client.post('/edit/author/update/', {'name': 'Randall Munroe (xkcd)', 'slug': 'randall-munroe'})
self.assertEqual(res.status_code, 302)
self.assertRedirects(res, '/list/authors/')
- self.assertQuerysetEqual(Author.objects.all(), ['<Author: Randall Munroe (xkcd)>'])
+ self.assertQuerysetEqual(Author.objects.values_list('name', flat=True), ['Randall Munroe (xkcd)'])
@override_settings(ROOT_URLCONF='generic_views.urls')