# HG changeset patch -- Bitbucket.org # Project django-modelviews # URL http://bitbucket.org/david/django-modelviews/overview # User Will Larson # Date 1213867018 -32400 # Node ID 7a46edcc917aa4937d949991024d1904d3301de0 # Parent e34bbc96c11fd69ed6b535995dd4fe69fedf88ef Cleaned up line spacing in tests.py --- a/tests/test_modelview/tests.py +++ b/tests/test_modelview/tests.py @@ -3,6 +3,7 @@ from models import Article from django.utils import simplejson from xml.dom.minidom import parseString + class ArticleTest(TestCase): def test_model(self): a = Article.objects.create(name="An article", @@ -12,12 +13,14 @@ class ArticleTest(TestCase): self.assertEqual(a.slug, "an-article") self.assertEqual(a.body, "some text") + class ModelViewTest(TestCase): def setUp(self): Article.objects.create(name="My Story", slug="my-story", body="My thrilling story!") + def test_restricting_exposed_methods(self): """ The service exposed at /article/ should only @@ -38,11 +41,13 @@ class ModelViewTest(TestCase): REQUEST_METHOD='PUT') self.assertEqual(response.status_code, 405) + def test_default_responder(self): a = Article.objects.all()[0] response = self.client.get('/articles/%s/' % a.slug) self.assertEqual(response.status_code, 200) + def test_html_responder_read_detail(self): a = Article.objects.all()[0] response = self.client.get('/articles/%s/html/' % a.slug) @@ -50,6 +55,7 @@ class ModelViewTest(TestCase): self.assertTemplateUsed(response, 'test_modelview/article_detail.html') self.assertNotEqual(response.content.find(a.name), -1) + def test_html_responder_read_list(self): response = self.client.get('/articles/') self.assertEqual(response.status_code, 200) @@ -57,6 +63,7 @@ class ModelViewTest(TestCase): for article in Article.objects.all(): self.assertNotEqual(response.content.find(article.name),-1) + def test_html_responder_create(self): response = self.client.post('/rw-articles/', {'name': "Another article", 'slug': "another-article", @@ -64,6 +71,7 @@ class ModelViewTest(TestCase): self.assertEqual(response.status_code, 302) self.assertEqual(Article.objects.count(), 2) + def test_html_responder_update(self): a = Article.objects.all()[0] response = self.client.post('/rw-articles/%s/' % a.slug, @@ -75,6 +83,7 @@ class ModelViewTest(TestCase): self.assertEqual(Article.objects.count(), 1) self.assertEqual(Article.objects.all()[0].name, u'An updated article') + def test_html_responder_delete(self): a = Article.objects.all()[0] response = self.client.post('/rw-articles/%s/' % a.slug, @@ -82,6 +91,7 @@ class ModelViewTest(TestCase): self.assertEqual(response.status_code, 302) self.assertEqual(Article.objects.count(), 0) + def test_atom_responder_read_detail(self): a = Article.objects.all()[0] response = self.client.get('/articles/%s/atom/' % a.slug) @@ -89,6 +99,7 @@ class ModelViewTest(TestCase): feed_content = '%s' % a.name self.assertEqual(response.content.find(feed_content), -1) + def test_atom_responder_read_list(self): a = Article.objects.all()[0] response = self.client.get('/articles/atom/') @@ -96,6 +107,7 @@ class ModelViewTest(TestCase): feed_content = '%s' % a.name self.assertEqual(response.content.find(feed_content), -1) + def test_rss_responder_read_detail(self): a = Article.objects.all()[0] response = self.client.get('/articles/%s/rss/' % a.slug) @@ -103,6 +115,7 @@ class ModelViewTest(TestCase): feed_content = '%s' % a.name self.assertEqual(response.content.find(feed_content), -1) + def test_rss_responder_read_list(self): a = Article.objects.all()[0] response = self.client.get('/articles/rss/') @@ -110,6 +123,7 @@ class ModelViewTest(TestCase): feed_content = '%s' % a.name self.assertEqual(response.content.find(feed_content), -1) + def test_json_responder_detail(self): a = Article.objects.all()[0] response = self.client.get('/articles/%s/json/' % a.slug) @@ -119,6 +133,7 @@ class ModelViewTest(TestCase): self.assertEqual(data[0]['pk'], a.pk) self.assertEqual(data[0]['fields']['body'], a.body) + def test_json_responder_list(self): response = self.client.get('/articles/json/') self.assertEqual(response.status_code, 200) @@ -151,6 +166,7 @@ class ModelViewTest(TestCase): dom = parseString(response.content) self.assertEqual(Article.objects.count(), len(dom.childNodes[0].childNodes)) + def test_yaml_responder_detail(self): try: import yaml @@ -160,11 +176,10 @@ class ModelViewTest(TestCase): data = yaml.load(response.content)[0] self.assertEqual(a.slug, data['fields']['slug']) self.assertEqual(a.body, data['fields']['body']) - - except ImportError: pass + def test_yaml_responder_list(self): try: import yaml