@@ -34,83 +34,83 @@ def test_contains(self):
34
34
try :
35
35
self .assertContains (response , 'text' , status_code = 999 )
36
36
except AssertionError , e :
37
- self .assertEquals ( str ( e ), "Couldn't retrieve page: Response code was 200 (expected 999)" )
37
+ self .assertTrue ( "Couldn't retrieve page: Response code was 200 (expected 999)" in str ( e ) )
38
38
try :
39
39
self .assertContains (response , 'text' , status_code = 999 , msg_prefix = 'abc' )
40
40
except AssertionError , e :
41
- self .assertEquals ( str ( e ), "abc: Couldn't retrieve page: Response code was 200 (expected 999)" )
41
+ self .assertTrue ( "abc: Couldn't retrieve page: Response code was 200 (expected 999)" in str ( e ) )
42
42
43
43
try :
44
44
self .assertNotContains (response , 'text' , status_code = 999 )
45
45
except AssertionError , e :
46
- self .assertEquals ( str ( e ), "Couldn't retrieve page: Response code was 200 (expected 999)" )
46
+ self .assertTrue ( "Couldn't retrieve page: Response code was 200 (expected 999)" in str ( e ) )
47
47
try :
48
48
self .assertNotContains (response , 'text' , status_code = 999 , msg_prefix = 'abc' )
49
49
except AssertionError , e :
50
- self .assertEquals ( str ( e ), "abc: Couldn't retrieve page: Response code was 200 (expected 999)" )
50
+ self .assertTrue ( "abc: Couldn't retrieve page: Response code was 200 (expected 999)" in str ( e ) )
51
51
52
52
try :
53
53
self .assertNotContains (response , 'once' )
54
54
except AssertionError , e :
55
- self .assertEquals ( str ( e ), "Response should not contain 'once'" )
55
+ self .assertTrue ( "Response should not contain 'once'" in str ( e ) )
56
56
try :
57
57
self .assertNotContains (response , 'once' , msg_prefix = 'abc' )
58
58
except AssertionError , e :
59
- self .assertEquals ( str ( e ), "abc: Response should not contain 'once'" )
59
+ self .assertTrue ( "abc: Response should not contain 'once'" in str ( e ) )
60
60
61
61
try :
62
62
self .assertContains (response , 'never' , 1 )
63
63
except AssertionError , e :
64
- self .assertEquals ( str ( e ), "Found 0 instances of 'never' in response (expected 1)" )
64
+ self .assertTrue ( "Found 0 instances of 'never' in response (expected 1)" in str ( e ) )
65
65
try :
66
66
self .assertContains (response , 'never' , 1 , msg_prefix = 'abc' )
67
67
except AssertionError , e :
68
- self .assertEquals ( str ( e ), "abc: Found 0 instances of 'never' in response (expected 1)" )
68
+ self .assertTrue ( "abc: Found 0 instances of 'never' in response (expected 1)" in str ( e ) )
69
69
70
70
try :
71
71
self .assertContains (response , 'once' , 0 )
72
72
except AssertionError , e :
73
- self .assertEquals ( str ( e ), "Found 1 instances of 'once' in response (expected 0)" )
73
+ self .assertTrue ( "Found 1 instances of 'once' in response (expected 0)" in str ( e ) )
74
74
try :
75
75
self .assertContains (response , 'once' , 0 , msg_prefix = 'abc' )
76
76
except AssertionError , e :
77
- self .assertEquals ( str ( e ), "abc: Found 1 instances of 'once' in response (expected 0)" )
77
+ self .assertTrue ( "abc: Found 1 instances of 'once' in response (expected 0)" in str ( e ) )
78
78
79
79
try :
80
80
self .assertContains (response , 'once' , 2 )
81
81
except AssertionError , e :
82
- self .assertEquals ( str ( e ), "Found 1 instances of 'once' in response (expected 2)" )
82
+ self .assertTrue ( "Found 1 instances of 'once' in response (expected 2)" in str ( e ) )
83
83
try :
84
84
self .assertContains (response , 'once' , 2 , msg_prefix = 'abc' )
85
85
except AssertionError , e :
86
- self .assertEquals ( str ( e ), "abc: Found 1 instances of 'once' in response (expected 2)" )
86
+ self .assertTrue ( "abc: Found 1 instances of 'once' in response (expected 2)" in str ( e ) )
87
87
88
88
try :
89
89
self .assertContains (response , 'twice' , 1 )
90
90
except AssertionError , e :
91
- self .assertEquals ( str ( e ), "Found 2 instances of 'twice' in response (expected 1)" )
91
+ self .assertTrue ( "Found 2 instances of 'twice' in response (expected 1)" in str ( e ) )
92
92
try :
93
93
self .assertContains (response , 'twice' , 1 , msg_prefix = 'abc' )
94
94
except AssertionError , e :
95
- self .assertEquals ( str ( e ), "abc: Found 2 instances of 'twice' in response (expected 1)" )
95
+ self .assertTrue ( "abc: Found 2 instances of 'twice' in response (expected 1)" in str ( e ) )
96
96
97
97
try :
98
98
self .assertContains (response , 'thrice' )
99
99
except AssertionError , e :
100
- self .assertEquals ( str ( e ), "Couldn't find 'thrice' in response" )
100
+ self .assertTrue ( "Couldn't find 'thrice' in response" in str ( e ) )
101
101
try :
102
102
self .assertContains (response , 'thrice' , msg_prefix = 'abc' )
103
103
except AssertionError , e :
104
- self .assertEquals ( str ( e ), "abc: Couldn't find 'thrice' in response" )
104
+ self .assertTrue ( "abc: Couldn't find 'thrice' in response" in str ( e ) )
105
105
106
106
try :
107
107
self .assertContains (response , 'thrice' , 3 )
108
108
except AssertionError , e :
109
- self .assertEquals ( str ( e ), "Found 0 instances of 'thrice' in response (expected 3)" )
109
+ self .assertTrue ( "Found 0 instances of 'thrice' in response (expected 3)" in str ( e ) )
110
110
try :
111
111
self .assertContains (response , 'thrice' , 3 , msg_prefix = 'abc' )
112
112
except AssertionError , e :
113
- self .assertEquals ( str ( e ), "abc: Found 0 instances of 'thrice' in response (expected 3)" )
113
+ self .assertTrue ( "abc: Found 0 instances of 'thrice' in response (expected 3)" in str ( e ) )
114
114
115
115
def test_unicode_contains (self ):
116
116
"Unicode characters can be found in template context"
@@ -140,12 +140,12 @@ def test_no_context(self):
140
140
try :
141
141
self .assertTemplateUsed (response , 'GET Template' )
142
142
except AssertionError , e :
143
- self .assertEquals ( str ( e ), "No templates used to render the response" )
143
+ self .assertTrue ( "No templates used to render the response" in str ( e ) )
144
144
145
145
try :
146
146
self .assertTemplateUsed (response , 'GET Template' , msg_prefix = 'abc' )
147
147
except AssertionError , e :
148
- self .assertEquals ( str ( e ), "abc: No templates used to render the response" )
148
+ self .assertTrue ( "abc: No templates used to render the response" in str ( e ) )
149
149
150
150
def test_single_context (self ):
151
151
"Template assertions work when there is a single context"
@@ -154,22 +154,22 @@ def test_single_context(self):
154
154
try :
155
155
self .assertTemplateNotUsed (response , 'Empty GET Template' )
156
156
except AssertionError , e :
157
- self .assertEquals ( str ( e ), "Template 'Empty GET Template' was used unexpectedly in rendering the response" )
157
+ self .assertTrue ( "Template 'Empty GET Template' was used unexpectedly in rendering the response" in str ( e ) )
158
158
159
159
try :
160
160
self .assertTemplateNotUsed (response , 'Empty GET Template' , msg_prefix = 'abc' )
161
161
except AssertionError , e :
162
- self .assertEquals ( str ( e ), "abc: Template 'Empty GET Template' was used unexpectedly in rendering the response" )
162
+ self .assertTrue ( "abc: Template 'Empty GET Template' was used unexpectedly in rendering the response" in str ( e ) )
163
163
164
164
try :
165
165
self .assertTemplateUsed (response , 'Empty POST Template' )
166
166
except AssertionError , e :
167
- self .assertEquals ( str ( e ), "Template 'Empty POST Template' was not a template used to render the response. Actual template(s) used: Empty GET Template" )
167
+ self .assertTrue ( "Template 'Empty POST Template' was not a template used to render the response. Actual template(s) used: Empty GET Template" in str ( e ) )
168
168
169
169
try :
170
170
self .assertTemplateUsed (response , 'Empty POST Template' , msg_prefix = 'abc' )
171
171
except AssertionError , e :
172
- self .assertEquals ( str ( e ), "abc: Template 'Empty POST Template' was not a template used to render the response. Actual template(s) used: Empty GET Template" )
172
+ self .assertTrue ( "abc: Template 'Empty POST Template' was not a template used to render the response. Actual template(s) used: Empty GET Template" in str ( e ) )
173
173
174
174
def test_multiple_context (self ):
175
175
"Template assertions work when there are multiple contexts"
@@ -185,17 +185,17 @@ def test_multiple_context(self):
185
185
try :
186
186
self .assertTemplateNotUsed (response , "form_view.html" )
187
187
except AssertionError , e :
188
- self .assertEquals ( str ( e ), "Template 'form_view.html' was used unexpectedly in rendering the response" )
188
+ self .assertTrue ( "Template 'form_view.html' was used unexpectedly in rendering the response" in str ( e ) )
189
189
190
190
try :
191
191
self .assertTemplateNotUsed (response , 'base.html' )
192
192
except AssertionError , e :
193
- self .assertEquals ( str ( e ), "Template 'base.html' was used unexpectedly in rendering the response" )
193
+ self .assertTrue ( "Template 'base.html' was used unexpectedly in rendering the response" in str ( e ) )
194
194
195
195
try :
196
196
self .assertTemplateUsed (response , "Valid POST Template" )
197
197
except AssertionError , e :
198
- self .assertEquals ( str ( e ), "Template 'Valid POST Template' was not a template used to render the response. Actual template(s) used: form_view.html, base.html" )
198
+ self .assertTrue ( "Template 'Valid POST Template' was not a template used to render the response. Actual template(s) used: form_view.html, base.html" in str ( e ) )
199
199
200
200
class AssertRedirectsTests (TestCase ):
201
201
def test_redirect_page (self ):
@@ -205,25 +205,25 @@ def test_redirect_page(self):
205
205
try :
206
206
self .assertRedirects (response , '/test_client/get_view/' )
207
207
except AssertionError , e :
208
- self .assertEquals ( str ( e ), "Response didn't redirect as expected: Response code was 301 (expected 302)" )
208
+ self .assertTrue ( "Response didn't redirect as expected: Response code was 301 (expected 302)" in str ( e ) )
209
209
210
210
try :
211
211
self .assertRedirects (response , '/test_client/get_view/' , msg_prefix = 'abc' )
212
212
except AssertionError , e :
213
- self .assertEquals ( str ( e ), "abc: Response didn't redirect as expected: Response code was 301 (expected 302)" )
213
+ self .assertTrue ( "abc: Response didn't redirect as expected: Response code was 301 (expected 302)" in str ( e ) )
214
214
215
215
def test_lost_query (self ):
216
216
"An assertion is raised if the redirect location doesn't preserve GET parameters"
217
217
response = self .client .get ('/test_client/redirect_view/' , {'var' : 'value' })
218
218
try :
219
219
self .assertRedirects (response , '/test_client/get_view/' )
220
220
except AssertionError , e :
221
- self .assertEquals ( str ( e ), "Response redirected to 'http://testserver/test_client/get_view/?var=value', expected 'http://testserver/test_client/get_view/'" )
221
+ self .assertTrue ( "Response redirected to 'http://testserver/test_client/get_view/?var=value', expected 'http://testserver/test_client/get_view/'" in str ( e ) )
222
222
223
223
try :
224
224
self .assertRedirects (response , '/test_client/get_view/' , msg_prefix = 'abc' )
225
225
except AssertionError , e :
226
- self .assertEquals ( str ( e ), "abc: Response redirected to 'http://testserver/test_client/get_view/?var=value', expected 'http://testserver/test_client/get_view/'" )
226
+ self .assertTrue ( "abc: Response redirected to 'http://testserver/test_client/get_view/?var=value', expected 'http://testserver/test_client/get_view/'" in str ( e ) )
227
227
228
228
def test_incorrect_target (self ):
229
229
"An assertion is raised if the response redirects to another target"
@@ -232,7 +232,7 @@ def test_incorrect_target(self):
232
232
# Should redirect to get_view
233
233
self .assertRedirects (response , '/test_client/some_view/' )
234
234
except AssertionError , e :
235
- self .assertEquals ( str ( e ), "Response didn't redirect as expected: Response code was 301 (expected 302)" )
235
+ self .assertTrue ( "Response didn't redirect as expected: Response code was 301 (expected 302)" in str ( e ) )
236
236
237
237
def test_target_page (self ):
238
238
"An assertion is raised if the response redirect target cannot be retrieved as expected"
@@ -241,13 +241,13 @@ def test_target_page(self):
241
241
# The redirect target responds with a 301 code, not 200
242
242
self .assertRedirects (response , 'http://testserver/test_client/permanent_redirect_view/' )
243
243
except AssertionError , e :
244
- self .assertEquals ( str ( e ), "Couldn't retrieve redirection page '/test_client/permanent_redirect_view/': response code was 301 (expected 200)" )
244
+ self .assertTrue ( "Couldn't retrieve redirection page '/test_client/permanent_redirect_view/': response code was 301 (expected 200)" in str ( e ) )
245
245
246
246
try :
247
247
# The redirect target responds with a 301 code, not 200
248
248
self .assertRedirects (response , 'http://testserver/test_client/permanent_redirect_view/' , msg_prefix = 'abc' )
249
249
except AssertionError , e :
250
- self .assertEquals ( str ( e ), "abc: Couldn't retrieve redirection page '/test_client/permanent_redirect_view/': response code was 301 (expected 200)" )
250
+ self .assertTrue ( "abc: Couldn't retrieve redirection page '/test_client/permanent_redirect_view/': response code was 301 (expected 200)" in str ( e ) )
251
251
252
252
def test_redirect_chain (self ):
253
253
"You can follow a redirect chain of multiple redirects"
@@ -338,12 +338,12 @@ def test_redirect_chain_on_non_redirect_page(self):
338
338
try :
339
339
self .assertRedirects (response , '/test_client/get_view/' )
340
340
except AssertionError , e :
341
- self .assertEquals ( str ( e ), "Response didn't redirect as expected: Response code was 200 (expected 302)" )
341
+ self .assertTrue ( "Response didn't redirect as expected: Response code was 200 (expected 302)" in str ( e ) )
342
342
343
343
try :
344
344
self .assertRedirects (response , '/test_client/get_view/' , msg_prefix = 'abc' )
345
345
except AssertionError , e :
346
- self .assertEquals ( str ( e ), "abc: Response didn't redirect as expected: Response code was 200 (expected 302)" )
346
+ self .assertTrue ( "abc: Response didn't redirect as expected: Response code was 200 (expected 302)" in str ( e ) )
347
347
348
348
def test_redirect_on_non_redirect_page (self ):
349
349
"An assertion is raised if the original page couldn't be retrieved as expected"
@@ -352,12 +352,12 @@ def test_redirect_on_non_redirect_page(self):
352
352
try :
353
353
self .assertRedirects (response , '/test_client/get_view/' )
354
354
except AssertionError , e :
355
- self .assertEquals ( str ( e ), "Response didn't redirect as expected: Response code was 200 (expected 302)" )
355
+ self .assertTrue ( "Response didn't redirect as expected: Response code was 200 (expected 302)" in str ( e ) )
356
356
357
357
try :
358
358
self .assertRedirects (response , '/test_client/get_view/' , msg_prefix = 'abc' )
359
359
except AssertionError , e :
360
- self .assertEquals ( str ( e ), "abc: Response didn't redirect as expected: Response code was 200 (expected 302)" )
360
+ self .assertTrue ( "abc: Response didn't redirect as expected: Response code was 200 (expected 302)" in str ( e ) )
361
361
362
362
363
363
class AssertFormErrorTests (TestCase ):
@@ -377,11 +377,11 @@ def test_unknown_form(self):
377
377
try :
378
378
self .assertFormError (response , 'wrong_form' , 'some_field' , 'Some error.' )
379
379
except AssertionError , e :
380
- self .assertEqual ( str ( e ), "The form 'wrong_form' was not used to render the response" )
380
+ self .assertTrue ( "The form 'wrong_form' was not used to render the response" in str ( e ) )
381
381
try :
382
382
self .assertFormError (response , 'wrong_form' , 'some_field' , 'Some error.' , msg_prefix = 'abc' )
383
383
except AssertionError , e :
384
- self .assertEqual ( str ( e ), "abc: The form 'wrong_form' was not used to render the response" )
384
+ self .assertTrue ( "abc: The form 'wrong_form' was not used to render the response" in str ( e ) )
385
385
386
386
def test_unknown_field (self ):
387
387
"An assertion is raised if the field name is unknown"
@@ -399,11 +399,11 @@ def test_unknown_field(self):
399
399
try :
400
400
self .assertFormError (response , 'form' , 'some_field' , 'Some error.' )
401
401
except AssertionError , e :
402
- self .assertEqual ( str ( e ), "The form 'form' in context 0 does not contain the field 'some_field'" )
402
+ self .assertTrue ( "The form 'form' in context 0 does not contain the field 'some_field'" in str ( e ) )
403
403
try :
404
404
self .assertFormError (response , 'form' , 'some_field' , 'Some error.' , msg_prefix = 'abc' )
405
405
except AssertionError , e :
406
- self .assertEqual ( str ( e ), "abc: The form 'form' in context 0 does not contain the field 'some_field'" )
406
+ self .assertTrue ( "abc: The form 'form' in context 0 does not contain the field 'some_field'" in str ( e ) )
407
407
408
408
def test_noerror_field (self ):
409
409
"An assertion is raised if the field doesn't have any errors"
@@ -421,11 +421,11 @@ def test_noerror_field(self):
421
421
try :
422
422
self .assertFormError (response , 'form' , 'value' , 'Some error.' )
423
423
except AssertionError , e :
424
- self .assertEqual ( str ( e ), "The field 'value' on form 'form' in context 0 contains no errors" )
424
+ self .assertTrue ( "The field 'value' on form 'form' in context 0 contains no errors" in str ( e ) )
425
425
try :
426
426
self .assertFormError (response , 'form' , 'value' , 'Some error.' , msg_prefix = 'abc' )
427
427
except AssertionError , e :
428
- self .assertEqual ( str ( e ), "abc: The field 'value' on form 'form' in context 0 contains no errors" )
428
+ self .assertTrue ( "abc: The field 'value' on form 'form' in context 0 contains no errors" in str ( e ) )
429
429
430
430
def test_unknown_error (self ):
431
431
"An assertion is raised if the field doesn't contain the provided error"
@@ -443,11 +443,11 @@ def test_unknown_error(self):
443
443
try :
444
444
self .assertFormError (response , 'form' , 'email' , 'Some error.' )
445
445
except AssertionError , e :
446
- self .assertEqual ( str ( e ), "The field 'email' on form 'form' in context 0 does not contain the error 'Some error.' (actual errors: [u'Enter a valid e-mail address.'])" )
446
+ self .assertTrue ( "The field 'email' on form 'form' in context 0 does not contain the error 'Some error.' (actual errors: [u'Enter a valid e-mail address.'])" in str ( e ) )
447
447
try :
448
448
self .assertFormError (response , 'form' , 'email' , 'Some error.' , msg_prefix = 'abc' )
449
449
except AssertionError , e :
450
- self .assertEqual ( str ( e ), "abc: The field 'email' on form 'form' in context 0 does not contain the error 'Some error.' (actual errors: [u'Enter a valid e-mail address.'])" )
450
+ self .assertTrue ( "abc: The field 'email' on form 'form' in context 0 does not contain the error 'Some error.' (actual errors: [u'Enter a valid e-mail address.'])" in str ( e ) )
451
451
452
452
def test_unknown_nonfield_error (self ):
453
453
"""
@@ -468,11 +468,11 @@ def test_unknown_nonfield_error(self):
468
468
try :
469
469
self .assertFormError (response , 'form' , None , 'Some error.' )
470
470
except AssertionError , e :
471
- self .assertEqual ( str ( e ), "The form 'form' in context 0 does not contain the non-field error 'Some error.' (actual errors: )" )
471
+ self .assertTrue ( "The form 'form' in context 0 does not contain the non-field error 'Some error.' (actual errors: )" in str ( e ) )
472
472
try :
473
473
self .assertFormError (response , 'form' , None , 'Some error.' , msg_prefix = 'abc' )
474
474
except AssertionError , e :
475
- self .assertEqual ( str ( e ), "abc: The form 'form' in context 0 does not contain the non-field error 'Some error.' (actual errors: )" )
475
+ self .assertTrue ( "abc: The form 'form' in context 0 does not contain the non-field error 'Some error.' (actual errors: )" in str ( e ) )
476
476
477
477
class LoginTests (TestCase ):
478
478
fixtures = ['testdata' ]
0 commit comments