Ticket #10183: 10183-assertcontains-unicode-testcase.diff

File 10183-assertcontains-unicode-testcase.diff, 2.8 KB (added by trbs, 16 years ago)
  • tests/regressiontests/test_client_regress/models.py

    diff -r ed807b5fa10f tests/regressiontests/test_client_regress/models.py
    a b  
    1111from django.template import TemplateDoesNotExist, TemplateSyntaxError, Context
    1212
    1313class AssertContainsTests(TestCase):
     14    def setUp(self):
     15        self.old_templates = settings.TEMPLATE_DIRS
     16        settings.TEMPLATE_DIRS = ()
     17
     18    def tearDown(self):
     19        settings.TEMPLATE_DIRS = self.old_templates
     20
    1421    def test_contains(self):
    1522        "Responses can be inspected for content, including counting repeated substrings"
    1623        response = self.client.get('/test_client_regress/no_template_view/')
     
    5663            self.assertContains(response, 'thrice', 3)
    5764        except AssertionError, e:
    5865            self.assertEquals(str(e), "Found 0 instances of 'thrice' in response (expected 3)")
     66
     67    def test_unicode_contains(self):
     68        #Regression test for #10183
     69        settings.TEMPLATE_DIRS = (os.path.join(os.path.dirname(__file__), 'templates'),)
     70        r = self.client.get('/test_client_regress/check_unicode/')
     71        self.assertContains(r, '\xe5\xb3\xa0'.decode('utf-8'))
    5972
    6073class AssertTemplateUsedTests(TestCase):
    6174    fixtures = ['testdata.json']
  • new file tests/regressiontests/test_client_regress/templates/unicode.html

    diff -r ed807b5fa10f tests/regressiontests/test_client_regress/templates/unicode.html
    - +  
     1* 峠 (とうげ tōge "mountain pass")
     2* 榊 (さかき sakaki "tree, genus Cleyera")
     3* 畑 (はたけ hatake "field of crops")
     4* 辻 (つじ tsuji "crossroads, street")
     5* 働 (どう dō, はたら hatara(ku) "work")
     6* 腺 (せん sen, "gland")
  • tests/regressiontests/test_client_regress/urls.py

    diff -r ed807b5fa10f tests/regressiontests/test_client_regress/urls.py
    a b  
    2222    (r'^set_session/$', views.set_session_view),
    2323    (r'^check_session/$', views.check_session_view),
    2424    (r'^request_methods/$', views.request_methods_view),
     25    (r'^check_unicode/$', views.return_unicode),
    2526)
  • tests/regressiontests/test_client_regress/views.py

    diff -r ed807b5fa10f tests/regressiontests/test_client_regress/views.py
    a b  
    6060def request_methods_view(request):
    6161    "A view that responds with the request method"
    6262    return HttpResponse('request method: %s' % request.method)
     63
     64def return_unicode(request):
     65    return render_to_response('unicode.html')
Back to Top