mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Fixed #12991 -- Added unittest2 support. Thanks to PaulM for the draft patch, and to Luke, Karen, Justin, Alex, Łukasz Rekucki, and Chuck Harmston for their help testing and reviewing the final patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@14139 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
@@ -35,83 +35,83 @@ class AssertContainsTests(TestCase):
|
||||
try:
|
||||
self.assertContains(response, 'text', status_code=999)
|
||||
except AssertionError, e:
|
||||
self.assertEquals(str(e), "Couldn't retrieve content: Response code was 200 (expected 999)")
|
||||
self.assertIn("Couldn't retrieve content: Response code was 200 (expected 999)", str(e))
|
||||
try:
|
||||
self.assertContains(response, 'text', status_code=999, msg_prefix='abc')
|
||||
except AssertionError, e:
|
||||
self.assertEquals(str(e), "abc: Couldn't retrieve content: Response code was 200 (expected 999)")
|
||||
self.assertIn("abc: Couldn't retrieve content: Response code was 200 (expected 999)", str(e))
|
||||
|
||||
try:
|
||||
self.assertNotContains(response, 'text', status_code=999)
|
||||
except AssertionError, e:
|
||||
self.assertEquals(str(e), "Couldn't retrieve content: Response code was 200 (expected 999)")
|
||||
self.assertIn("Couldn't retrieve content: Response code was 200 (expected 999)", str(e))
|
||||
try:
|
||||
self.assertNotContains(response, 'text', status_code=999, msg_prefix='abc')
|
||||
except AssertionError, e:
|
||||
self.assertEquals(str(e), "abc: Couldn't retrieve content: Response code was 200 (expected 999)")
|
||||
self.assertIn("abc: Couldn't retrieve content: Response code was 200 (expected 999)", str(e))
|
||||
|
||||
try:
|
||||
self.assertNotContains(response, 'once')
|
||||
except AssertionError, e:
|
||||
self.assertEquals(str(e), "Response should not contain 'once'")
|
||||
self.assertIn("Response should not contain 'once'", str(e))
|
||||
try:
|
||||
self.assertNotContains(response, 'once', msg_prefix='abc')
|
||||
except AssertionError, e:
|
||||
self.assertEquals(str(e), "abc: Response should not contain 'once'")
|
||||
self.assertIn("abc: Response should not contain 'once'", str(e))
|
||||
|
||||
try:
|
||||
self.assertContains(response, 'never', 1)
|
||||
except AssertionError, e:
|
||||
self.assertEquals(str(e), "Found 0 instances of 'never' in response (expected 1)")
|
||||
self.assertIn("Found 0 instances of 'never' in response (expected 1)", str(e))
|
||||
try:
|
||||
self.assertContains(response, 'never', 1, msg_prefix='abc')
|
||||
except AssertionError, e:
|
||||
self.assertEquals(str(e), "abc: Found 0 instances of 'never' in response (expected 1)")
|
||||
self.assertIn("abc: Found 0 instances of 'never' in response (expected 1)", str(e))
|
||||
|
||||
try:
|
||||
self.assertContains(response, 'once', 0)
|
||||
except AssertionError, e:
|
||||
self.assertEquals(str(e), "Found 1 instances of 'once' in response (expected 0)")
|
||||
self.assertIn("Found 1 instances of 'once' in response (expected 0)", str(e))
|
||||
try:
|
||||
self.assertContains(response, 'once', 0, msg_prefix='abc')
|
||||
except AssertionError, e:
|
||||
self.assertEquals(str(e), "abc: Found 1 instances of 'once' in response (expected 0)")
|
||||
self.assertIn("abc: Found 1 instances of 'once' in response (expected 0)", str(e))
|
||||
|
||||
try:
|
||||
self.assertContains(response, 'once', 2)
|
||||
except AssertionError, e:
|
||||
self.assertEquals(str(e), "Found 1 instances of 'once' in response (expected 2)")
|
||||
self.assertIn("Found 1 instances of 'once' in response (expected 2)", str(e))
|
||||
try:
|
||||
self.assertContains(response, 'once', 2, msg_prefix='abc')
|
||||
except AssertionError, e:
|
||||
self.assertEquals(str(e), "abc: Found 1 instances of 'once' in response (expected 2)")
|
||||
self.assertIn("abc: Found 1 instances of 'once' in response (expected 2)", str(e))
|
||||
|
||||
try:
|
||||
self.assertContains(response, 'twice', 1)
|
||||
except AssertionError, e:
|
||||
self.assertEquals(str(e), "Found 2 instances of 'twice' in response (expected 1)")
|
||||
self.assertIn("Found 2 instances of 'twice' in response (expected 1)", str(e))
|
||||
try:
|
||||
self.assertContains(response, 'twice', 1, msg_prefix='abc')
|
||||
except AssertionError, e:
|
||||
self.assertEquals(str(e), "abc: Found 2 instances of 'twice' in response (expected 1)")
|
||||
self.assertIn("abc: Found 2 instances of 'twice' in response (expected 1)", str(e))
|
||||
|
||||
try:
|
||||
self.assertContains(response, 'thrice')
|
||||
except AssertionError, e:
|
||||
self.assertEquals(str(e), "Couldn't find 'thrice' in response")
|
||||
self.assertIn("Couldn't find 'thrice' in response", str(e))
|
||||
try:
|
||||
self.assertContains(response, 'thrice', msg_prefix='abc')
|
||||
except AssertionError, e:
|
||||
self.assertEquals(str(e), "abc: Couldn't find 'thrice' in response")
|
||||
self.assertIn("abc: Couldn't find 'thrice' in response", str(e))
|
||||
|
||||
try:
|
||||
self.assertContains(response, 'thrice', 3)
|
||||
except AssertionError, e:
|
||||
self.assertEquals(str(e), "Found 0 instances of 'thrice' in response (expected 3)")
|
||||
self.assertIn("Found 0 instances of 'thrice' in response (expected 3)", str(e))
|
||||
try:
|
||||
self.assertContains(response, 'thrice', 3, msg_prefix='abc')
|
||||
except AssertionError, e:
|
||||
self.assertEquals(str(e), "abc: Found 0 instances of 'thrice' in response (expected 3)")
|
||||
self.assertIn("abc: Found 0 instances of 'thrice' in response (expected 3)", str(e))
|
||||
|
||||
def test_unicode_contains(self):
|
||||
"Unicode characters can be found in template context"
|
||||
@@ -141,12 +141,12 @@ class AssertTemplateUsedTests(TestCase):
|
||||
try:
|
||||
self.assertTemplateUsed(response, 'GET Template')
|
||||
except AssertionError, e:
|
||||
self.assertEquals(str(e), "No templates used to render the response")
|
||||
self.assertIn("No templates used to render the response", str(e))
|
||||
|
||||
try:
|
||||
self.assertTemplateUsed(response, 'GET Template', msg_prefix='abc')
|
||||
except AssertionError, e:
|
||||
self.assertEquals(str(e), "abc: No templates used to render the response")
|
||||
self.assertIn("abc: No templates used to render the response", str(e))
|
||||
|
||||
def test_single_context(self):
|
||||
"Template assertions work when there is a single context"
|
||||
@@ -155,22 +155,22 @@ class AssertTemplateUsedTests(TestCase):
|
||||
try:
|
||||
self.assertTemplateNotUsed(response, 'Empty GET Template')
|
||||
except AssertionError, e:
|
||||
self.assertEquals(str(e), "Template 'Empty GET Template' was used unexpectedly in rendering the response")
|
||||
self.assertIn("Template 'Empty GET Template' was used unexpectedly in rendering the response", str(e))
|
||||
|
||||
try:
|
||||
self.assertTemplateNotUsed(response, 'Empty GET Template', msg_prefix='abc')
|
||||
except AssertionError, e:
|
||||
self.assertEquals(str(e), "abc: Template 'Empty GET Template' was used unexpectedly in rendering the response")
|
||||
self.assertIn("abc: Template 'Empty GET Template' was used unexpectedly in rendering the response", str(e))
|
||||
|
||||
try:
|
||||
self.assertTemplateUsed(response, 'Empty POST Template')
|
||||
except AssertionError, e:
|
||||
self.assertEquals(str(e), "Template 'Empty POST Template' was not a template used to render the response. Actual template(s) used: Empty GET Template")
|
||||
self.assertIn("Template 'Empty POST Template' was not a template used to render the response. Actual template(s) used: Empty GET Template", str(e))
|
||||
|
||||
try:
|
||||
self.assertTemplateUsed(response, 'Empty POST Template', msg_prefix='abc')
|
||||
except AssertionError, e:
|
||||
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")
|
||||
self.assertIn("abc: Template 'Empty POST Template' was not a template used to render the response. Actual template(s) used: Empty GET Template", str(e))
|
||||
|
||||
def test_multiple_context(self):
|
||||
"Template assertions work when there are multiple contexts"
|
||||
@@ -186,17 +186,17 @@ class AssertTemplateUsedTests(TestCase):
|
||||
try:
|
||||
self.assertTemplateNotUsed(response, "form_view.html")
|
||||
except AssertionError, e:
|
||||
self.assertEquals(str(e), "Template 'form_view.html' was used unexpectedly in rendering the response")
|
||||
self.assertIn("Template 'form_view.html' was used unexpectedly in rendering the response", str(e))
|
||||
|
||||
try:
|
||||
self.assertTemplateNotUsed(response, 'base.html')
|
||||
except AssertionError, e:
|
||||
self.assertEquals(str(e), "Template 'base.html' was used unexpectedly in rendering the response")
|
||||
self.assertIn("Template 'base.html' was used unexpectedly in rendering the response", str(e))
|
||||
|
||||
try:
|
||||
self.assertTemplateUsed(response, "Valid POST Template")
|
||||
except AssertionError, e:
|
||||
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")
|
||||
self.assertIn("Template 'Valid POST Template' was not a template used to render the response. Actual template(s) used: form_view.html, base.html", str(e))
|
||||
|
||||
class AssertRedirectsTests(TestCase):
|
||||
def test_redirect_page(self):
|
||||
@@ -206,12 +206,12 @@ class AssertRedirectsTests(TestCase):
|
||||
try:
|
||||
self.assertRedirects(response, '/test_client/get_view/')
|
||||
except AssertionError, e:
|
||||
self.assertEquals(str(e), "Response didn't redirect as expected: Response code was 301 (expected 302)")
|
||||
self.assertIn("Response didn't redirect as expected: Response code was 301 (expected 302)", str(e))
|
||||
|
||||
try:
|
||||
self.assertRedirects(response, '/test_client/get_view/', msg_prefix='abc')
|
||||
except AssertionError, e:
|
||||
self.assertEquals(str(e), "abc: Response didn't redirect as expected: Response code was 301 (expected 302)")
|
||||
self.assertIn("abc: Response didn't redirect as expected: Response code was 301 (expected 302)", str(e))
|
||||
|
||||
def test_lost_query(self):
|
||||
"An assertion is raised if the redirect location doesn't preserve GET parameters"
|
||||
@@ -219,12 +219,12 @@ class AssertRedirectsTests(TestCase):
|
||||
try:
|
||||
self.assertRedirects(response, '/test_client/get_view/')
|
||||
except AssertionError, e:
|
||||
self.assertEquals(str(e), "Response redirected to 'http://testserver/test_client/get_view/?var=value', expected 'http://testserver/test_client/get_view/'")
|
||||
self.assertIn("Response redirected to 'http://testserver/test_client/get_view/?var=value', expected 'http://testserver/test_client/get_view/'", str(e))
|
||||
|
||||
try:
|
||||
self.assertRedirects(response, '/test_client/get_view/', msg_prefix='abc')
|
||||
except AssertionError, e:
|
||||
self.assertEquals(str(e), "abc: Response redirected to 'http://testserver/test_client/get_view/?var=value', expected 'http://testserver/test_client/get_view/'")
|
||||
self.assertIn("abc: Response redirected to 'http://testserver/test_client/get_view/?var=value', expected 'http://testserver/test_client/get_view/'", str(e))
|
||||
|
||||
def test_incorrect_target(self):
|
||||
"An assertion is raised if the response redirects to another target"
|
||||
@@ -233,7 +233,7 @@ class AssertRedirectsTests(TestCase):
|
||||
# Should redirect to get_view
|
||||
self.assertRedirects(response, '/test_client/some_view/')
|
||||
except AssertionError, e:
|
||||
self.assertEquals(str(e), "Response didn't redirect as expected: Response code was 301 (expected 302)")
|
||||
self.assertIn("Response didn't redirect as expected: Response code was 301 (expected 302)", str(e))
|
||||
|
||||
def test_target_page(self):
|
||||
"An assertion is raised if the response redirect target cannot be retrieved as expected"
|
||||
@@ -242,13 +242,13 @@ class AssertRedirectsTests(TestCase):
|
||||
# The redirect target responds with a 301 code, not 200
|
||||
self.assertRedirects(response, 'http://testserver/test_client/permanent_redirect_view/')
|
||||
except AssertionError, e:
|
||||
self.assertEquals(str(e), "Couldn't retrieve redirection page '/test_client/permanent_redirect_view/': response code was 301 (expected 200)")
|
||||
self.assertIn("Couldn't retrieve redirection page '/test_client/permanent_redirect_view/': response code was 301 (expected 200)", str(e))
|
||||
|
||||
try:
|
||||
# The redirect target responds with a 301 code, not 200
|
||||
self.assertRedirects(response, 'http://testserver/test_client/permanent_redirect_view/', msg_prefix='abc')
|
||||
except AssertionError, e:
|
||||
self.assertEquals(str(e), "abc: Couldn't retrieve redirection page '/test_client/permanent_redirect_view/': response code was 301 (expected 200)")
|
||||
self.assertIn("abc: Couldn't retrieve redirection page '/test_client/permanent_redirect_view/': response code was 301 (expected 200)", str(e))
|
||||
|
||||
def test_redirect_chain(self):
|
||||
"You can follow a redirect chain of multiple redirects"
|
||||
@@ -339,12 +339,12 @@ class AssertRedirectsTests(TestCase):
|
||||
try:
|
||||
self.assertRedirects(response, '/test_client/get_view/')
|
||||
except AssertionError, e:
|
||||
self.assertEquals(str(e), "Response didn't redirect as expected: Response code was 200 (expected 302)")
|
||||
self.assertIn("Response didn't redirect as expected: Response code was 200 (expected 302)", str(e))
|
||||
|
||||
try:
|
||||
self.assertRedirects(response, '/test_client/get_view/', msg_prefix='abc')
|
||||
except AssertionError, e:
|
||||
self.assertEquals(str(e), "abc: Response didn't redirect as expected: Response code was 200 (expected 302)")
|
||||
self.assertIn("abc: Response didn't redirect as expected: Response code was 200 (expected 302)", str(e))
|
||||
|
||||
def test_redirect_on_non_redirect_page(self):
|
||||
"An assertion is raised if the original page couldn't be retrieved as expected"
|
||||
@@ -353,12 +353,12 @@ class AssertRedirectsTests(TestCase):
|
||||
try:
|
||||
self.assertRedirects(response, '/test_client/get_view/')
|
||||
except AssertionError, e:
|
||||
self.assertEquals(str(e), "Response didn't redirect as expected: Response code was 200 (expected 302)")
|
||||
self.assertIn("Response didn't redirect as expected: Response code was 200 (expected 302)", str(e))
|
||||
|
||||
try:
|
||||
self.assertRedirects(response, '/test_client/get_view/', msg_prefix='abc')
|
||||
except AssertionError, e:
|
||||
self.assertEquals(str(e), "abc: Response didn't redirect as expected: Response code was 200 (expected 302)")
|
||||
self.assertIn("abc: Response didn't redirect as expected: Response code was 200 (expected 302)", str(e))
|
||||
|
||||
|
||||
class AssertFormErrorTests(TestCase):
|
||||
@@ -378,11 +378,11 @@ class AssertFormErrorTests(TestCase):
|
||||
try:
|
||||
self.assertFormError(response, 'wrong_form', 'some_field', 'Some error.')
|
||||
except AssertionError, e:
|
||||
self.assertEqual(str(e), "The form 'wrong_form' was not used to render the response")
|
||||
self.assertIn("The form 'wrong_form' was not used to render the response", str(e))
|
||||
try:
|
||||
self.assertFormError(response, 'wrong_form', 'some_field', 'Some error.', msg_prefix='abc')
|
||||
except AssertionError, e:
|
||||
self.assertEqual(str(e), "abc: The form 'wrong_form' was not used to render the response")
|
||||
self.assertIn("abc: The form 'wrong_form' was not used to render the response", str(e))
|
||||
|
||||
def test_unknown_field(self):
|
||||
"An assertion is raised if the field name is unknown"
|
||||
@@ -400,11 +400,11 @@ class AssertFormErrorTests(TestCase):
|
||||
try:
|
||||
self.assertFormError(response, 'form', 'some_field', 'Some error.')
|
||||
except AssertionError, e:
|
||||
self.assertEqual(str(e), "The form 'form' in context 0 does not contain the field 'some_field'")
|
||||
self.assertIn("The form 'form' in context 0 does not contain the field 'some_field'", str(e))
|
||||
try:
|
||||
self.assertFormError(response, 'form', 'some_field', 'Some error.', msg_prefix='abc')
|
||||
except AssertionError, e:
|
||||
self.assertEqual(str(e), "abc: The form 'form' in context 0 does not contain the field 'some_field'")
|
||||
self.assertIn("abc: The form 'form' in context 0 does not contain the field 'some_field'", str(e))
|
||||
|
||||
def test_noerror_field(self):
|
||||
"An assertion is raised if the field doesn't have any errors"
|
||||
@@ -422,11 +422,11 @@ class AssertFormErrorTests(TestCase):
|
||||
try:
|
||||
self.assertFormError(response, 'form', 'value', 'Some error.')
|
||||
except AssertionError, e:
|
||||
self.assertEqual(str(e), "The field 'value' on form 'form' in context 0 contains no errors")
|
||||
self.assertIn("The field 'value' on form 'form' in context 0 contains no errors", str(e))
|
||||
try:
|
||||
self.assertFormError(response, 'form', 'value', 'Some error.', msg_prefix='abc')
|
||||
except AssertionError, e:
|
||||
self.assertEqual(str(e), "abc: The field 'value' on form 'form' in context 0 contains no errors")
|
||||
self.assertIn("abc: The field 'value' on form 'form' in context 0 contains no errors", str(e))
|
||||
|
||||
def test_unknown_error(self):
|
||||
"An assertion is raised if the field doesn't contain the provided error"
|
||||
@@ -444,11 +444,11 @@ class AssertFormErrorTests(TestCase):
|
||||
try:
|
||||
self.assertFormError(response, 'form', 'email', 'Some error.')
|
||||
except AssertionError, e:
|
||||
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.'])")
|
||||
self.assertIn("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.'])", str(e))
|
||||
try:
|
||||
self.assertFormError(response, 'form', 'email', 'Some error.', msg_prefix='abc')
|
||||
except AssertionError, e:
|
||||
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.'])")
|
||||
self.assertIn("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.'])", str(e))
|
||||
|
||||
def test_unknown_nonfield_error(self):
|
||||
"""
|
||||
@@ -469,11 +469,11 @@ class AssertFormErrorTests(TestCase):
|
||||
try:
|
||||
self.assertFormError(response, 'form', None, 'Some error.')
|
||||
except AssertionError, e:
|
||||
self.assertEqual(str(e), "The form 'form' in context 0 does not contain the non-field error 'Some error.' (actual errors: )")
|
||||
self.assertIn("The form 'form' in context 0 does not contain the non-field error 'Some error.' (actual errors: )", str(e))
|
||||
try:
|
||||
self.assertFormError(response, 'form', None, 'Some error.', msg_prefix='abc')
|
||||
except AssertionError, e:
|
||||
self.assertEqual(str(e), "abc: The form 'form' in context 0 does not contain the non-field error 'Some error.' (actual errors: )")
|
||||
self.assertIn("abc: The form 'form' in context 0 does not contain the non-field error 'Some error.' (actual errors: )", str(e))
|
||||
|
||||
class LoginTests(TestCase):
|
||||
fixtures = ['testdata']
|
||||
|
||||
Reference in New Issue
Block a user