Beispiel #1
0
def test_unicode():
    """url() can handle unicode parameters"""
    with test_context(None, '/'):
        unicodestring =  u_('àèìòù')
        eq_(url('/', params=dict(x=unicodestring)),
            '/?x=%C3%A0%C3%A8%C3%AC%C3%B2%C3%B9'
            )
Beispiel #2
0
def test_unicode():
    """url() can handle unicode parameters"""
    create_request("/")
    unicodestring =  u_('àèìòù')
    eq_(url('/', params=dict(x=unicodestring)),
        '/?x=%C3%A0%C3%A8%C3%AC%C3%B2%C3%B9'
        )
Beispiel #3
0
 def test_custom_failure_message(self):
     message = u_('This is a custom message whose id is: %(id_number)s')
     id_number = 23
     p = EqualsFour(msg=message)
     try:
         p.unmet(message, id_number=id_number)
         self.fail('An exception must have been raised')
     except predicates.NotAuthorizedError as e:
         self.assertEqual(unicode_text(e), message % dict(id_number=id_number))
Beispiel #4
0
    def test_content_type(self):
        r = Response()

        r.content_type = u_('text/html')
        # Verify it's a native string, and not unicode.
        assert type(r.content_type) == str
        assert r.content_type == 'text/html'

        del r.content_type
        assert r.content_type is None
Beispiel #5
0
 def test_unauthorized_with_unicode_message(self):
     # This test is broken on Python 2.4 and 2.5 because the unicode()
     # function doesn't work when converting an exception into an unicode
     # string (this is, to extract its message).
     unicode_msg = u_('请登陆')
     environ = {'test_number': 3}
     p = EqualsFour(msg=unicode_msg)
     try:
         p.check_authorization(environ)
         self.fail('Authorization must have been rejected')
     except predicates.NotAuthorizedError as e:
         self.assertEqual(unicode_text(e), unicode_msg)
Beispiel #6
0
 def test_script_json_encode(self):
     rv = script_json_encode('</script>')
     assert rv == u_('"\\u003c/script\\u003e"')
     rv = script_json_encode("<\0/script>")
     assert rv == '"\\u003c\\u0000/script\\u003e"'
     rv = script_json_encode("<!--<script>")
     assert rv == '"\\u003c!--\\u003cscript\\u003e"'
     rv = script_json_encode("&")
     assert rv == '"\\u0026"'
     rv = script_json_encode("\'")
     assert rv == '"\\u0027"'
     rv = "<a ng-data='%s'></a>" % script_json_encode({'x': ["foo", "bar", "baz'"]})
     assert rv == '<a ng-data=\'{"x": ["foo", "bar", "baz\\u0027"]}\'></a>'
Beispiel #7
0
    def test_form_validation_translation(self):
        if PY3: raise SkipTest()

        """Test translation of form validation error messages"""
        form_values = {'title': 'Razer', 'year': "t007"}
        # check with language set in request header
        resp = self.app.post('/process_form', form_values,
            headers={'Accept-Language': 'de,ru,it'})
        values = loads(resp.body.decode('utf-8'))
        assert "Bitte eine ganze Zahl eingeben" in values['errors']['year'], \
            'No German error message: %r' % values['errors']
        resp = self.app.post('/process_form', form_values,
            headers={'Accept-Language': 'ru,de,it'})
        values = loads(resp.body.decode('utf-8'))
        assert u_("Введите числовое значение") in values['errors']['year'], \
            'No Russian error message: %r' % values['errors']
        # check with language set in session
        self.app.post('/set_lang/de')
        resp = self.app.post('/process_form', form_values,
            headers={'Accept-Language': 'ru,it'})
        values = loads(resp.body.decode('utf-8'))
        assert "Bitte eine ganze Zahl eingeben" in values['errors']['year'], \
            'No German error message: %r' % values['errors']
Beispiel #8
0
    def test_form_validation_translation(self):
        if PY3:
            raise SkipTest()

        """Test translation of form validation error messages"""
        form_values = {"title": "Razer", "year": "t007"}
        # check with language set in request header
        resp = self.app.post("/process_form", form_values, headers={"Accept-Language": "de,ru,it"})
        values = loads(resp.body.decode("utf-8"))
        assert "Bitte eine ganze Zahl eingeben" in values["errors"]["year"], (
            "No German error message: %r" % values["errors"]
        )
        resp = self.app.post("/process_form", form_values, headers={"Accept-Language": "ru,de,it"})
        values = loads(resp.body.decode("utf-8"))
        assert u_("Введите числовое значение") in values["errors"]["year"], (
            "No Russian error message: %r" % values["errors"]
        )
        # check with language set in session
        self.app.post("/set_lang/de")
        resp = self.app.post("/process_form", form_values, headers={"Accept-Language": "ru,it"})
        values = loads(resp.body.decode("utf-8"))
        assert "Bitte eine ganze Zahl eingeben" in values["errors"]["year"], (
            "No German error message: %r" % values["errors"]
        )
Beispiel #9
0
def test_url_unicode_nonascii():
    res = url('.', {'p1':u_('àèìòù')})
    assert res == '.?p1=%C3%A0%C3%A8%C3%AC%C3%B2%C3%B9'
Beispiel #10
0
def test_flash_unicode():
    resp = app.get('/flash_unicode').follow()
    content = resp.body.decode('utf8')
    assert u_('Привет, мир!') in content, content
Beispiel #11
0
def test_list():
    """url() can handle list parameters, with unicode too"""
    create_request("/")
    value = url('/', params=dict(foo=['bar', u_('à')])),
    assert '/?foo=bar&foo=%C3%A0' in value, value
 def test_ticket_2412_with_named_arg(self):
     resp = self.app.get('/ticket2412?arg1=Abip%C3%B3n')
     assert u_("""Abipón""") in resp.body.decode('utf-8'), resp
 def flash_unicode(self):
     tg.flash(u_("Привет, мир!"))
     tg.redirect("/flash_after_redirect")
def test_kajiki_i18n():
    app = setup_noDB()
    resp = app.get('/kajiki_i18n')
    assert u_("Your application is now running") in resp
Beispiel #15
0
 def test_ticket_2412_with_named_arg(self):
     resp = self.app.get('/ticket2412?arg1=Abip%C3%B3n')
     assert u_("""Abipón""") in resp.body.decode('utf-8'), resp
Beispiel #16
0
 def test_unicode_default_dispatch(self):
     r = self.app.get('/sub/%C3%A4%C3%B6')
     assert u_("äö") in r.body.decode('utf-8'), r
Beispiel #17
0
 def flash_unicode(self):
     tg.flash(u_("Привет, мир!"))
     tg.redirect("/flash_after_redirect")
Beispiel #18
0
 def index_unicode(self):
     tg.response.charset = None
     return u_('Hello World')
Beispiel #19
0
 def __str__(self):
     return u_('àèìòù')
Beispiel #20
0
def test_url_unicode_nonascii():
    res = url('.', {'p1': u_('àèìòù')})
    assert res == '.?p1=%C3%A0%C3%A8%C3%AC%C3%B2%C3%B9'
Beispiel #21
0
def test_url_unicode():
    res = url('.', {'p1': u_('v1')})
    assert res == '.?p1=v1'
Beispiel #22
0
def test_list():
    """url() can handle list parameters, with unicode too"""
    with test_context(None, '/'):
        value = url('/', params=dict(foo=['bar', u_('à')])),
        assert '/?foo=bar&foo=%C3%A0' in value, value
 def test_ticket_2412_with_ordered_arg(self):
     resp = self.app.get("/ticket2412/Abip%C3%B3n")
     assert u_("""Abipón""") in resp.body.decode("utf-8"), resp
Beispiel #24
0
def test_flash_unicode():
    resp = app.get('/flash_unicode').follow()
    content = resp.body.decode('utf8')
    assert u_('Привет, мир!') in content, content
 def index_unicode(self):
     tg.response.charset = None
     return u_('Hello World')
Beispiel #26
0
def test_list():
    """url() can handle list parameters, with unicode too"""
    with test_context(None, '/'):
        value = url('/', params=dict(foo=['bar', u_('à')])),
        assert '/?foo=bar&foo=%C3%A0' in value, value
 def test_unicode_default_dispatch(self):
     r =self.app.get('/sub/%C3%A4%C3%B6')
     assert u_("äö") in r.body.decode('utf-8'), r
Beispiel #28
0
def test_kajiki_i18n_de():
    app = setup_noDB()
    resp = app.get('/kajiki_i18n_de')
    assert u_("Ihre Anwendung läuft jetzt einwandfrei") in resp
Beispiel #29
0
def test_kajiki_i18n():
    app = setup_noDB()
    resp = app.get('/kajiki_i18n')
    assert u_("Your application is now running") in resp
Beispiel #30
0
 def test_safe_filename(self):
     assert safe_filename('My cool movie.mov') == 'My_cool_movie.mov'
     assert safe_filename('../../../etc/passwd') == 'etc_passwd'
     assert safe_filename(u_('i contain cool ümläuts.txt')) == 'i_contain_cool_umlauts.txt'
Beispiel #31
0
 def test_url_unicode_nonascii(self):
     with test_context(None, '/'):
         res = url('.', {'p1':u_('àèìòù')})
         assert res == '.?p1=%C3%A0%C3%A8%C3%AC%C3%B2%C3%B9'
Beispiel #32
0
 def test_url_unicode_nonascii(self):
     with test_context(None, '/'):
         res = url('.', {'p1':u_('àèìòù')})
         assert res == '.?p1=%C3%A0%C3%A8%C3%AC%C3%B2%C3%B9'
Beispiel #33
0
def test_jinja_i18n_de():
    app = setup_noDB()
    resp = app.get('/jinja_i18n_de')
    assert u_("Ihre Anwendung läuft jetzt einwandfrei") in resp
Beispiel #34
0
 def test_url_unicode(self):
     with test_context(None, '/'):
         res = url('.', {'p1':u_('v1')})
         assert res == '.?p1=v1'
Beispiel #35
0
def test_url_unicode():
    res = url('.', {'p1':u_('v1')})
    assert res == '.?p1=v1'
 def test_unicode_default_dispatch(self):
     r = self.app.get("/sub/%C3%A4%C3%B6")
     assert u_("äö") in r.body.decode("utf-8"), r
Beispiel #37
0
 def test_unicode_messages(self):
     unicode_msg = u_('请登陆')
     p = EqualsTwo(msg=unicode_msg)
     environ = {'test_number': 3}
     self.eval_unmet_predicate(p, environ, unicode_msg)
Beispiel #38
0
def test_unicode():
    """url() can handle unicode parameters"""
    with test_context(None, '/'):
        unicodestring = u_('àèìòù')
        eq_(url('/', params=dict(x=unicodestring)),
            '/?x=%C3%A0%C3%A8%C3%AC%C3%B2%C3%B9')
Beispiel #39
0
 def test_url_unicode(self):
     with test_context(None, '/'):
         res = url('.', {'p1':u_('v1')})
         assert res == '.?p1=v1'
Beispiel #40
0
 def test_validation_errors_lazy_unicode(self):
     resp = self.app.post('/lazy_unicode_error_pow', {'num': 'NOT_A_NUMBER'}, status=412)
     assert resp.json['errors']['num'] == u_('àèìòù'), resp.json
Beispiel #41
0
 def __str__(self):
     return u_('àèìòù')
Beispiel #42
0
 def test_safe_filename(self):
     assert safe_filename('My cool movie.mov') == 'My_cool_movie.mov'
     assert safe_filename('../../../etc/passwd') == 'etc_passwd'
     assert safe_filename(u_('i contain cool ümläuts.txt')) == 'i_contain_cool_umlauts.txt'