Пример #1
0
 def test_incorrect_urlencoded_path(self):
     'Incorrect url encoded path'
     t = UrlTemplate('/<name>')
     value = quote(u'/имя'.encode('utf-8')) + '%r1'
     self.assertEqual(t.match(value), (True, {
         'name': u'\u0438\u043c\u044f%r1'
     }))
Пример #2
0
 def test_incorrect_value(self):
     'Incorrect url encoded value'
     t = UrlTemplate('/<name>')
     value = quote(u'/имя'.encode('utf-8'))[:-1]
     self.assertEqual(t.match(value), (True, {
         'name': u'\u0438\u043c\ufffd%8'
     }))
Пример #3
0
 def test_match_from_begining_without_params(self):
     'UrlTemplate match method without params (from begining of str)'
     ut = UrlTemplate('simple', match_whole_str=False)
     self.assertEqual(ut.match('simple'), (True, {}))
     self.assertEqual(ut.match('simple/sdffds'), (True, {}))
     self.assertEqual(ut.match('/simple'), (False, {}))
     self.assertEqual(ut.match('/simple/'), (False, {}))
Пример #4
0
 def test_multiple_converters(self):
     'Multiple converters'
     t = UrlTemplate('/<name>/text/<action>')
     self.assertEqual(t.match(quote('/this/text/edit')), (True, {
         'name': 'this',
         'action': 'edit'
     }))
Пример #5
0
 def test_unicode(self):
     'Unicode values of converters'
     t = UrlTemplate('/<name>/text/<action>')
     self.assertEqual(t.match(quote(u'/имя/text/действие'.encode('utf-8'))),
                      (True, {
                          'name': u'имя',
                          'action': u'действие'
                      }))
Пример #6
0
 def test_multiple_converters_postfix(self):
     'Multiple converters with postfix data'
     t = UrlTemplate('/<name>/text/<action>/post')
     self.assertEqual(t.match(quote(u'/this/text/edit/post')),
                      (True, {
                          'name': 'this',
                          'action': 'edit'
                      }))
     self.assertEqual(t.match(quote(u'/this/text/edit')), (False, {}))
Пример #7
0
 def test_converter_with_args(self):
     'Converter with args'
     class Conv(Converter):
         def __init__(self, *items):
             self.items = items
         def to_python(self, value, **kw):
             if value not in self.items:
                 raise ConvertError(self.name, value)
             return value
     t = UrlTemplate('/<conv(u"text", u"test"):name>', converters=[Conv])
     value = quote(u'/имя'.encode('utf-8'))
     self.assertEqual(t.match(value), (False, {}))
     value = quote(u'/text'.encode('utf-8'))
     self.assertEqual(t.match(value), (True, {'name': u'text'}))
     value = quote(u'/test'.encode('utf-8'))
     self.assertEqual(t.match(value), (True, {'name': u'test'}))
Пример #8
0
    def test_converter_with_args(self):
        'Converter with args'

        class Conv(Converter):
            def __init__(self, *items):
                self.items = items

            def to_python(self, value, **kw):
                if value not in self.items:
                    raise ConvertError(self.name, value)
                return value

        t = UrlTemplate('/<conv(u"text", u"test"):name>', converters=[Conv])
        value = quote(u'/имя'.encode('utf-8'))
        self.assertEqual(t.match(value), (False, {}))
        value = quote(u'/text'.encode('utf-8'))
        self.assertEqual(t.match(value), (True, {'name': u'text'}))
        value = quote(u'/test'.encode('utf-8'))
        self.assertEqual(t.match(value), (True, {'name': u'test'}))
Пример #9
0
 def test_match_from_begining_with_params(self):
     'UrlTemplate match method with params (from begining of str)'
     ut = UrlTemplate('/simple/<int:id>', match_whole_str=False)
     self.assertEqual(ut.match('/simple/2'), (True, {'id':2}))
     self.assertEqual(ut.match('/simple/2/sdfsf'), (True, {'id':2}))
     self.assertEqual(ut.match('/simple'), (False, {}))
     self.assertEqual(ut.match('/simple/d'), (False, {}))
     self.assertEqual(ut.match('/simple/d/sdfsdf'), (False, {}))
Пример #10
0
 def test_match_with_params(self):
     'UrlTemplate match method with params'
     ut = UrlTemplate('/simple/<int:id>')
     self.assertEqual(ut.match('/simple/2'), (True, {'id':2}))
     self.assertEqual(ut.match('/simple'), (False, {}))
     self.assertEqual(ut.match('/simple/d'), (False, {}))
Пример #11
0
 def test_incorrect_value(self):
     'Incorrect url encoded value'
     t = UrlTemplate('/<name>')
     value = quote(u'/имя'.encode('utf-8'))[:-1]
     self.assertEqual(t.match(value), (True, {'name': u'\u0438\u043c\ufffd%8'}))
Пример #12
0
 def test_multiple_converters_postfix(self):
     'Multiple converters with postfix data'
     t = UrlTemplate('/<name>/text/<action>/post')
     self.assertEqual(t.match(quote(u'/this/text/edit/post')), (True, {'name': 'this', 'action': 'edit'}))
     self.assertEqual(t.match(quote(u'/this/text/edit')), (False, {}))
Пример #13
0
 def test_default_converter(self):
     'Default converter test'
     t = UrlTemplate('/<name>')
     self.assertEqual(t.match('/somevalue'), (True, {'name': 'somevalue'}))
Пример #14
0
 def test_static_text(self):
     'Simple text match'
     t = UrlTemplate('/test/url')
     self.assertEqual(t.match('/test/url'), (True, {}))
Пример #15
0
 def test_unknown_converter(self):
     'Unknown converter'
     self.assertRaises(KeyError, lambda: UrlTemplate('/<baba:name>/'))
     self.assertRaises(KeyError, lambda: UrlTemplate('/<baba:name></'))
Пример #16
0
 def test_incorrect_url_template1(self):
     'Incorrect url template 1'
     self.assertRaises(ValueError, lambda: UrlTemplate('/<:name>/'))
Пример #17
0
 def test_match(self):
     'Simple match'
     t = UrlTemplate('/')
     self.assertEqual(t.match('/'), (True, {}))
Пример #18
0
 def test_match(self):
     'Simple match'
     t = UrlTemplate('/')
     self.assertEqual(t.match('/'), (True, {}))
Пример #19
0
 def test_converter(self):
     'Simple text match'
     t = UrlTemplate('/<string:name>')
     self.assertEqual(t.match('/somevalue'), (True, {'name': 'somevalue'}))
Пример #20
0
 def test_static_text(self):
     'Simple text match'
     t = UrlTemplate('/test/url')
     self.assertEqual(t.match('/test/url'), (True, {}))
Пример #21
0
 def test_multiple_converters(self):
     'Multiple converters'
     t = UrlTemplate('/<name>/text/<action>')
     self.assertEqual(t.match(quote('/this/text/edit')), (True, {'name': 'this', 'action': 'edit'}))
Пример #22
0
 def test_converter(self):
     'Simple text match'
     t = UrlTemplate('/<string:name>')
     self.assertEqual(t.match('/somevalue'), (True, {'name': 'somevalue'}))
Пример #23
0
 def test_unicode(self):
     'Unicode values of converters'
     t = UrlTemplate('/<name>/text/<action>')
     self.assertEqual(t.match(quote(u'/имя/text/действие'.encode('utf-8'))), (True, {'name': u'имя', 'action': u'действие'}))
Пример #24
0
 def test_default_converter(self):
     'Default converter test'
     t = UrlTemplate('/<name>')
     self.assertEqual(t.match('/somevalue'), (True, {'name': 'somevalue'}))
Пример #25
0
 def test_incorrect_urlencoded_path(self):
     'Incorrect url encoded path'
     t = UrlTemplate('/<name>')
     value = quote(u'/имя'.encode('utf-8'))+'%r1'
     self.assertEqual(t.match(value), (True, {'name': u'\u0438\u043c\u044f%r1'}))
Пример #26
0
 def test_match_without_params(self):
     'UrlTemplate match method without params'
     ut = UrlTemplate('simple')
     self.assertEqual(ut.match('simple'), (True, {}))
     self.assertEqual(ut.match('/simple'), (False, {}))