Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Grid view tests.

Added several grid view tests; added JSON test data to confirm 404
on element view.
  • Loading branch information...
commit 9cd90be2025d4e8fd2a4ffe4ca9ae743afdf68de 1 parent 7f5d0d4
@akavlie authored
Showing with 70 additions and 2 deletions.
  1. +53 −2 apps/grid/tests/test_views.py
  2. +17 −0 fixtures/test_initial_data.json
View
55 apps/grid/tests/test_views.py
@@ -1,7 +1,7 @@
from django.test import TestCase
from django.core.urlresolvers import reverse
-from grid.models import Element, Feature, GridPackage
+from grid.models import Grid, Element, Feature, GridPackage
class FunctionalGridTest(TestCase):
fixtures = ['test_initial_data.json']
@@ -31,6 +31,16 @@ def test_add_grid_view(self):
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, 'grid/add_grid.html')
+ # Test form post
+ count = Grid.objects.count()
+ response = self.client.post(url, {
+ 'title': 'TEST TITLE',
+ 'slug': 'test-title',
+ 'description': 'Just a test description'
+ }, follow=True)
+ self.assertEqual(Grid.objects.count(), count + 1)
+ self.assertContains(response, 'TEST TITLE')
+
def test_edit_grid_view(self):
url = reverse('edit_grid', kwargs={'slug': 'testing'})
response = self.client.get(url)
@@ -44,6 +54,16 @@ def test_edit_grid_view(self):
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, 'grid/edit_grid.html')
+ # Test form post
+ count = Grid.objects.count()
+ response = self.client.post(url, {
+ 'title': 'TEST TITLE',
+ 'slug': 'testing',
+ 'description': 'Just a test description'
+ }, follow=True)
+ self.assertEqual(Grid.objects.count(), count)
+ self.assertContains(response, 'TEST TITLE')
+
def test_add_feature_view(self):
url = reverse('add_feature', kwargs={'grid_slug': 'testing'})
response = self.client.get(url)
@@ -57,6 +77,15 @@ def test_add_feature_view(self):
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, 'grid/add_feature.html')
+ # Test form post
+ count = Feature.objects.count()
+ response = self.client.post(url, {
+ 'title': 'TEST TITLE',
+ 'description': 'Just a test description'
+ }, follow=True)
+ self.assertEqual(Feature.objects.count(), count + 1)
+ self.assertContains(response, 'TEST TITLE')
+
def test_edit_feature_view(self):
url = reverse('edit_feature', kwargs={'id': '1'})
response = self.client.get(url)
@@ -70,6 +99,15 @@ def test_edit_feature_view(self):
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, 'grid/edit_feature.html')
+ # Test form post
+ count = Feature.objects.count()
+ response = self.client.post(url, {
+ 'title': 'TEST TITLE',
+ 'description': 'Just a test description'
+ }, follow=True)
+ self.assertEqual(Feature.objects.count(), count)
+ self.assertContains(response, 'TEST TITLE')
+
def test_delete_feature_view(self):
count = Feature.objects.count()
@@ -84,7 +122,7 @@ def test_delete_feature_view(self):
# the given feature, reducing the count by one.
self.assertTrue(self.client.login(username='cleaner', password='cleaner'))
response = self.client.get(url)
- self.assertEqual(count - 1, Feature.objects.count())
+ self.assertEqual(Feature.objects.count(), count - 1)
def test_edit_element_view(self):
url = reverse('edit_element', kwargs={'feature_id': '1', 'package_id': '1'})
@@ -99,6 +137,19 @@ def test_edit_element_view(self):
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, 'grid/edit_element.html')
+ # Test form post
+ count = Element.objects.count()
+ response = self.client.post(url, {
+ 'text': 'Some random text',
+ }, follow=True)
+ self.assertEqual(Element.objects.count(), count)
+ self.assertContains(response, 'Some random text')
+
+ # Confirm 404 if grid IDs differ
+ url = reverse('edit_element', kwargs={'feature_id': '1', 'package_id': '4'})
+ response = self.client.get(url)
+ self.assertEqual(response.status_code, 404)
+
def test_add_gridpackage_view(self):
url = reverse('add_grid_package', kwargs={'grid_slug': 'testing'})
response = self.client.get(url)
View
17 fixtures/test_initial_data.json
@@ -33,6 +33,14 @@
"pk" : 3
},
{ "fields" : { "created" : "2010-01-01 12:00:00",
+ "grid" : 2,
+ "modified" : "2010-01-01 12:00:00",
+ "package" : 3
+ },
+ "model" : "grid.gridpackage",
+ "pk" : 4
+ },
+ { "fields" : { "created" : "2010-01-01 12:00:00",
"description" : "Does this package come with tests?",
"grid" : 1,
"modified" : "2010-01-01 12:00:00",
@@ -42,6 +50,15 @@
"pk" : 1
},
{ "fields" : { "created" : "2010-01-01 12:00:00",
+ "description" : "Is this package cool?",
+ "grid" : 1,
+ "modified" : "2010-01-01 12:00:00",
+ "title" : "Coolness?"
+ },
+ "model" : "grid.feature",
+ "pk" : 2
+ },
+ { "fields" : { "created" : "2010-01-01 12:00:00",
"feature" : 1,
"grid_package" : 1,
"modified" : "2010-01-01 12:00:00",

0 comments on commit 9cd90be

Please sign in to comment.
Something went wrong with that request. Please try again.