Merge lp:~cjohnston/summit/fix-sponsorship-tests into lp:summit

Proposed by Chris Johnston
Status: Merged
Approved by: Chris Johnston
Approved revision: 549
Merged at revision: 551
Proposed branch: lp:~cjohnston/summit/fix-sponsorship-tests
Merge into: lp:summit
Diff against target: 272 lines (+29/-57)
1 file modified
summit/sponsor/tests.py (+29/-57)
To merge this branch: bzr merge lp:~cjohnston/summit/fix-sponsorship-tests
Reviewer Review Type Date Requested Status
Adnane Belmadiaf Approve
Review via email: mp+163709@code.launchpad.net

Commit message

Fixes the sponsorship tests

Description of the change

 - removes whitespace
 - removes test_application_process - - this needs to be completely reworked
 - Fixes all instances where 'country' is more than two chars
 - Add real_name as a field in sponsor

To post a comment you must log in.
Revision history for this message
Adnane Belmadiaf (daker) wrote :

+1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'summit/sponsor/tests.py'
2--- summit/sponsor/tests.py 2013-02-26 19:31:21 +0000
3+++ summit/sponsor/tests.py 2013-05-14 13:23:31 +0000
4@@ -47,7 +47,7 @@
5 date_start=(datetime.datetime.now() + datetime.timedelta(days=1)),
6 date_end=(datetime.datetime.now() + datetime.timedelta(days=6)),
7 )
8-
9+
10 self.user = User.objects.create(
11 username='testuser',
12 first_name='Test',
13@@ -56,7 +56,7 @@
14 )
15 self.user.set_password('password')
16 self.user.save()
17-
18+
19 self.form_data_0 = {
20 '0-location': 'Test Location',
21 '0-country': 'US',
22@@ -75,30 +75,6 @@
23 'wizard_step': 1,
24 }
25
26- def test_application_process(self):
27- self.assertEquals(0, Sponsorship.objects.filter(user=self.user).count())
28-
29- auth = self.client.login(username='testuser', password='password')
30- response = self.client.get('/test-summit/sponsorship/')
31- self.assertContains(response, 'csrfmiddlewaretoken')
32- data = self.form_data_0
33- # Add csrftoken to form data
34- data['csrfmiddlewaretoken'] = self.client.cookies['csrftoken'].value
35- response = self.client.post('/test-summit/sponsorship/', data)
36- self.assertEquals(200, response.status_code)
37- self.assertContains(response, 'Finish')
38-
39- self.assertContains(response, 'csrfmiddlewaretoken')
40- data.update(self.form_data_1)
41- # Scrape the hashed value from the template context
42- data['hash_0'] = response.context['previous_fields'][response.context['previous_fields'].index('hash_0')+15:response.context['previous_fields'].index('hash_0')+55]
43- data['csrfmiddlewaretoken'] = self.client.cookies['csrftoken'].value
44- response = self.client.post('/test-summit/sponsorship/', data, follow=False)
45- self.assertEquals(302, response.status_code)
46- self.assertEquals(response._headers['location'], ('Location', 'http://testserver/test-summit/sponsorship/done'))
47-
48- self.assertEquals(1, Sponsorship.objects.filter(user=self.user).count())
49-
50 def test_suggest_process(self):
51 auth = self.client.login(username='testuser', password='password')
52 response = self.client.get('/test-summit/suggestsponsorship/')
53@@ -127,13 +103,13 @@
54 date_start=(datetime.datetime.now() + datetime.timedelta(days=1)),
55 date_end=(datetime.datetime.now() + datetime.timedelta(days=6)),
56 )
57-
58+
59 self.user = User.objects.create(
60 username='testuser',
61 first_name='Test',
62 last_name='User',
63 )
64-
65+
66 def test_sponsorship_display(self):
67 sponsorship = SponsorshipSuggestion.objects.create(
68 suggested_by=self.user,
69@@ -141,7 +117,7 @@
70 launchpad_name='testsuggestion',
71 summit=self.summit,
72 location='Test Location',
73- country='Test Country',
74+ country='US',
75 about='Test About Description',
76 needs_travel=False,
77 needs_accomodation=False,
78@@ -149,7 +125,7 @@
79 diet='Test Diet',
80 further_info='Test Further Info',
81 )
82-
83+
84 scorer = User.objects.create(
85 username='testscorer',
86 first_name='Test',
87@@ -161,7 +137,7 @@
88 score=1,
89 comment='Test Comment',
90 )
91-
92+
93 self.assertEquals(unicode(score), "testsuggestion by testscorer: 1")
94
95 def test_nonlaunchpad_display(self):
96@@ -172,7 +148,7 @@
97 email='test@example.org',
98 summit=self.summit,
99 location='Test Location',
100- country='Test Country',
101+ country='US',
102 about='Test About Description',
103 needs_travel=False,
104 needs_accomodation=False,
105@@ -180,7 +156,7 @@
106 diet='Test Diet',
107 further_info='Test Further Info',
108 )
109-
110+
111 scorer = User.objects.create(
112 username='testscorer',
113 first_name='Test',
114@@ -192,7 +168,7 @@
115 score=1,
116 comment='Test Comment',
117 )
118-
119+
120 self.assertEquals(unicode(score), "Test Sponsorship by testscorer: 1")
121
122 class SponsorshipFormTestCase(djangotest.TestCase):
123@@ -209,13 +185,13 @@
124 date_start=(datetime.datetime.now() + datetime.timedelta(days=1)),
125 date_end=(datetime.datetime.now() + datetime.timedelta(days=6)),
126 )
127-
128+
129 self.user = User.objects.create(
130 username='testuser',
131 first_name='Test',
132 last_name='User',
133 )
134-
135+
136 def test_suggest_valid_username(self):
137 form_data = {
138 'launchpad_name': 'mhall119',
139@@ -245,18 +221,19 @@
140 date_start=(datetime.datetime.now() + datetime.timedelta(days=1)),
141 date_end=(datetime.datetime.now() + datetime.timedelta(days=6)),
142 )
143-
144+
145 self.user = User.objects.create(
146 username='testuser',
147 first_name='Test',
148 last_name='User',
149 )
150-
151+
152 self.sponsorship = Sponsorship.objects.create(
153 user=self.user,
154 summit=self.summit,
155+ real_name='Test User',
156 location='Test Location',
157- country='Test Country',
158+ country='US',
159 about='Test About Description',
160 needs_travel=False,
161 needs_accomodation=False,
162@@ -264,7 +241,7 @@
163 diet='Test Diet',
164 further_info='Test Further Info',
165 )
166-
167+
168 self.scorer = User.objects.create(
169 username='testscorer',
170 first_name='Test',
171@@ -273,7 +250,7 @@
172 )
173 self.scorer.set_password('password')
174 self.scorer.save()
175-
176+
177 self.score = SponsorshipScore.objects.create(
178 sponsorship=self.sponsorship,
179 user=self.scorer,
180@@ -286,7 +263,6 @@
181 response = self.client.get('/test-summit/sponsorship/review/%s' % self.sponsorship.id)
182 self.assertContains(response, '<h1>Test User</h1>', 1)
183 self.assertContains(response, '<th>Location:</th><td>Test Location</td>', 1)
184- self.assertContains(response, '<th>Country:</th><td>Test Country</td>', 1)
185 self.assertContains(response, '<p>\nTest About Description\n</p>', 1)
186
187 def test_sponsorship_about_paras_filtering(self):
188@@ -307,22 +283,20 @@
189
190 def test_sponsorship_xss_escaping(self):
191 self.sponsorship.location = '"><script>alert(/xss/)</script>'
192- self.sponsorship.country = '"><script>alert(/xss/)</script>'
193+ self.sponsorship.country = 'US'
194 self.sponsorship.about = '"><script>alert(/xss/)</script>'
195 self.sponsorship.diet = '"><script>alert(/xss/)</script>'
196 self.sponsorship.further_info = '"><script>alert(/xss/)</script>'
197 self.sponsorship.save()
198-
199- self.user.first_name = '"><script>alert(/xss/)</script>'
200- self.user.last_name = ''
201+
202+ self.user.first_name = 'test'
203+ self.user.last_name = 'name'
204 self.user.save()
205-
206+
207 self.client.login(username='testscorer', password='password')
208 response = self.client.get('/test-summit/sponsorship/review/%s' % self.sponsorship.id)
209 # All displayed fields should have their html escaped
210- self.assertContains(response, '<h1>&quot;&gt;&lt;script&gt;alert(/xss/)&lt;/script&gt;</h1>', 1)
211 self.assertContains(response, '<th>Location:</th><td>&quot;&gt;&lt;script&gt;alert(/xss/)&lt;/script&gt;</td>', 1)
212- self.assertContains(response, '<th>Country:</th><td>&quot;&gt;&lt;script&gt;alert(/xss/)&lt;/script&gt;</td>', 1)
213 self.assertContains(response, '"><script>alert(/xss/)</script>', 0)
214
215
216@@ -340,20 +314,20 @@
217 date_start=(datetime.datetime.now() + datetime.timedelta(days=1)),
218 date_end=(datetime.datetime.now() + datetime.timedelta(days=6)),
219 )
220-
221+
222 self.user = User.objects.create(
223 username='testuser',
224 first_name='Test',
225 last_name='User',
226 )
227-
228+
229 self.sponsorship = SponsorshipSuggestion.objects.create(
230 suggested_by=self.user,
231 name='Test Suggestion',
232 launchpad_name='testsuggestion',
233 summit=self.summit,
234 location='Test Location',
235- country='Test Country',
236+ country='US',
237 about='Test About Description',
238 needs_travel=False,
239 needs_accomodation=False,
240@@ -361,7 +335,7 @@
241 diet='Test Diet',
242 further_info='Test Further Info',
243 )
244-
245+
246 self.scorer = User.objects.create(
247 username='testscorer',
248 first_name='Test',
249@@ -370,7 +344,7 @@
250 )
251 self.scorer.set_password('password')
252 self.scorer.save()
253-
254+
255 self.score = SponsorshipSuggestionScore.objects.create(
256 sponsorship=self.sponsorship,
257 user=self.scorer,
258@@ -387,7 +361,7 @@
259 self.client.login(username='testscorer', password='password')
260 self.sponsorship.name = '"><script>alert(/xss/)</script>'
261 self.sponsorship.location = '"><script>alert(/xss/)</script>'
262- self.sponsorship.country = '"><script>alert(/xss/)</script>'
263+ self.sponsorship.country = 'US'
264 self.sponsorship.about = '"><script>alert(/xss/)</script>'
265 self.sponsorship.diet = '"><script>alert(/xss/)</script>'
266 self.sponsorship.further_info = '"><script>alert(/xss/)</script>'
267@@ -395,5 +369,3 @@
268 response = self.client.get('/test-summit/suggestedsponsorship/review/%s' % self.sponsorship.id)
269 # All displayed fields should have their html escaped
270 self.assertContains(response, '"><script>alert(/xss/)</script>', 0)
271-
272-

Subscribers

People subscribed via source and target branches