david / django-modelviews

Backup of an old repository with useful ideas. Initial goal: integrating REST to django admin (class-based views).

Clone this repository (size: 85.8 KB): HTTPS / SSH
$ hg clone http://code.welldev.org/django-modelviews
commit 38: 7a46edcc917a
parent 37: e34bbc96c11f
branch: default
Cleaned up line spacing in tests.py
Will Larson
2 years ago

Changed (Δ3 bytes):

raw changeset »

tests/test_modelview/tests.py (17 lines added, 2 lines removed)

Up to file-list tests/test_modelview/tests.py:

@@ -3,6 +3,7 @@ from models import Article
3
3
from django.utils import simplejson
4
4
from xml.dom.minidom import parseString
5
5
        
6
6
7
class ArticleTest(TestCase):
7
8
    def test_model(self):
8
9
        a = Article.objects.create(name="An article",
@@ -12,12 +13,14 @@ class ArticleTest(TestCase):
12
13
        self.assertEqual(a.slug, "an-article")
13
14
        self.assertEqual(a.body, "some text")
14
15
16
15
17
class ModelViewTest(TestCase):
16
18
    def setUp(self):
17
19
        Article.objects.create(name="My Story",
18
20
                               slug="my-story",
19
21
                               body="My thrilling story!")
20
22
23
21
24
    def test_restricting_exposed_methods(self):
22
25
        """
23
26
        The service exposed at /article/ should only
@@ -38,11 +41,13 @@ class ModelViewTest(TestCase):
38
41
                                   REQUEST_METHOD='PUT')
39
42
        self.assertEqual(response.status_code, 405)
40
43
44
41
45
    def test_default_responder(self):
42
46
        a = Article.objects.all()[0]
43
47
        response = self.client.get('/articles/%s/' % a.slug)
44
48
        self.assertEqual(response.status_code, 200)
45
49
50
46
51
    def test_html_responder_read_detail(self):
47
52
        a = Article.objects.all()[0]
48
53
        response = self.client.get('/articles/%s/html/' % a.slug)
@@ -50,6 +55,7 @@ class ModelViewTest(TestCase):
50
55
        self.assertTemplateUsed(response, 'test_modelview/article_detail.html')
51
56
        self.assertNotEqual(response.content.find(a.name), -1)
52
57
58
53
59
    def test_html_responder_read_list(self):
54
60
        response = self.client.get('/articles/')
55
61
        self.assertEqual(response.status_code, 200)
@@ -57,6 +63,7 @@ class ModelViewTest(TestCase):
57
63
        for article in Article.objects.all():
58
64
            self.assertNotEqual(response.content.find(article.name),-1)
59
65
66
60
67
    def test_html_responder_create(self):
61
68
        response = self.client.post('/rw-articles/', {'name': "Another article",
62
69
                                                      'slug': "another-article",
@@ -64,6 +71,7 @@ class ModelViewTest(TestCase):
64
71
        self.assertEqual(response.status_code, 302)
65
72
        self.assertEqual(Article.objects.count(), 2)
66
73
74
67
75
    def test_html_responder_update(self):
68
76
        a = Article.objects.all()[0]
69
77
        response = self.client.post('/rw-articles/%s/' % a.slug,
@@ -75,6 +83,7 @@ class ModelViewTest(TestCase):
75
83
        self.assertEqual(Article.objects.count(), 1)
76
84
        self.assertEqual(Article.objects.all()[0].name, u'An updated article')
77
85
86
78
87
    def test_html_responder_delete(self):
79
88
        a = Article.objects.all()[0]
80
89
        response = self.client.post('/rw-articles/%s/' % a.slug,
@@ -82,6 +91,7 @@ class ModelViewTest(TestCase):
82
91
        self.assertEqual(response.status_code, 302)
83
92
        self.assertEqual(Article.objects.count(), 0)
84
93
94
85
95
    def test_atom_responder_read_detail(self):
86
96
        a = Article.objects.all()[0]
87
97
        response = self.client.get('/articles/%s/atom/' % a.slug)
@@ -89,6 +99,7 @@ class ModelViewTest(TestCase):
89
99
        feed_content = '</updated><entry><title>%s</title>' % a.name
90
100
        self.assertEqual(response.content.find(feed_content), -1)
91
101
102
92
103
    def test_atom_responder_read_list(self):
93
104
        a = Article.objects.all()[0]
94
105
        response = self.client.get('/articles/atom/')
@@ -96,6 +107,7 @@ class ModelViewTest(TestCase):
96
107
        feed_content = '</updated><entry><title>%s</title>' % a.name
97
108
        self.assertEqual(response.content.find(feed_content), -1)
98
109
110
99
111
    def test_rss_responder_read_detail(self):
100
112
        a = Article.objects.all()[0]
101
113
        response = self.client.get('/articles/%s/rss/' % a.slug)
@@ -103,6 +115,7 @@ class ModelViewTest(TestCase):
103
115
        feed_content = '</updated><entry><title>%s</title>' % a.name
104
116
        self.assertEqual(response.content.find(feed_content), -1)
105
117
118
106
119
    def test_rss_responder_read_list(self):
107
120
        a = Article.objects.all()[0]
108
121
        response = self.client.get('/articles/rss/')
@@ -110,6 +123,7 @@ class ModelViewTest(TestCase):
110
123
        feed_content = '</updated><entry><title>%s</title>' % a.name
111
124
        self.assertEqual(response.content.find(feed_content), -1)
112
125
126
113
127
    def test_json_responder_detail(self):
114
128
        a = Article.objects.all()[0]
115
129
        response = self.client.get('/articles/%s/json/' % a.slug)
@@ -119,6 +133,7 @@ class ModelViewTest(TestCase):
119
133
        self.assertEqual(data[0]['pk'], a.pk)
120
134
        self.assertEqual(data[0]['fields']['body'], a.body)
121
135
136
122
137
    def test_json_responder_list(self):
123
138
        response = self.client.get('/articles/json/')
124
139
        self.assertEqual(response.status_code, 200)
@@ -151,6 +166,7 @@ class ModelViewTest(TestCase):
151
166
        dom = parseString(response.content)
152
167
        self.assertEqual(Article.objects.count(), len(dom.childNodes[0].childNodes))
153
168
169
154
170
    def test_yaml_responder_detail(self):
155
171
        try:
156
172
            import yaml
@@ -160,11 +176,10 @@ class ModelViewTest(TestCase):
160
176
            data = yaml.load(response.content)[0]
161
177
            self.assertEqual(a.slug, data['fields']['slug'])
162
178
            self.assertEqual(a.body, data['fields']['body'])
163
            
164
165
179
        except ImportError:
166
180
            pass
167
181
182
168
183
    def test_yaml_responder_list(self):
169
184
        try:
170
185
            import yaml