Exemplo n.º 1
0
    def test_named_wildcard(self):
        m = mock.Mock()

        r = ice.WildcardRoute('/<a>', m)
        self.assertEqual(r.match('/foo'), (m, [], {'a': 'foo'}))
        self.assertEqual(r.match('/bar'), (m, [], {'a': 'bar'}))
        self.assertEqual(r.match('/<baz>'), (m, [], {'a': '<baz>'}))
        self.assertIsNone(r.match('/foo/'))
        self.assertIsNone(r.match('/foo/bar'))

        r = ice.WildcardRoute('/<a>/<b>', m)
        self.assertEqual(r.match('/foo/bar'), (m, [], {
            'a': 'foo',
            'b': 'bar'
        }))
        self.assertIsNone(r.match('/foo'), (m, [], {}))
        self.assertIsNone(r.match('/foo/'), (m, [], {}))
        self.assertIsNone(r.match('/foo/'), (m, [], {}))

        r = ice.WildcardRoute('/<a>/bar', m)
        self.assertEqual(r.match('/foo/bar'), (m, [], {'a': 'foo'}))
        self.assertIsNone(r.match('/foo'))
        self.assertIsNone(r.match('/bar'))
        self.assertIsNone(r.match('/foo/bar/'))
        self.assertIsNone(r.match('/foo/bar/baz'))
Exemplo n.º 2
0
    def test_named_path_wildcard(self):
        m = mock.Mock()

        r = ice.WildcardRoute('<a:path>', m)
        self.assertEqual(r.match('/foo'), (m, [], {'a': '/foo'}))
        self.assertEqual(r.match('/bar'), (m, [], {'a': '/bar'}))
        self.assertEqual(r.match('/<baz>'), (m, [], {'a': '/<baz>'}))
        self.assertEqual(r.match('/foo/'), (m, [], {'a': '/foo/'}))
        self.assertEqual(r.match('/foo/bar'), (m, [], {'a': '/foo/bar'}))
        self.assertEqual(r.match('foo'), (m, [], {'a': 'foo'}))
        self.assertEqual(r.match('foo/'), (m, [], {'a': 'foo/'}))
        self.assertEqual(r.match('foo/bar'), (m, [], {'a': 'foo/bar'}))

        r = ice.WildcardRoute('<a:path><b:path>', m)
        self.assertEqual(r.match('/foo/bar'), (m, [], {
            'a': '/foo/ba',
            'b': 'r'
        }))
        self.assertEqual(r.match('/foo/bar/baz'), (m, [], {
            'a': '/foo/bar/ba',
            'b': 'z'
        }))
        self.assertEqual(r.match('/foo'), (m, [], {'a': '/fo', 'b': 'o'}))

        r = ice.WildcardRoute('/<a:path>/bar', m)
        self.assertEqual(r.match('/foo/bar'), (m, [], {'a': 'foo'}))
        self.assertIsNone(r.match('foo'))
        self.assertIsNone(r.match('/bar'))
        self.assertIsNone(r.match('/foo/bar/'))
        self.assertIsNone(r.match('/foo/bar/baz'))

        r = ice.WildcardRoute('/<a:path>', m)
        self.assertEqual(r.match('/foo/bar'), (m, [], {'a': 'foo/bar'}))
        self.assertIsNone(r.match('/'))
Exemplo n.º 3
0
    def test_anonymous_wildcard(self):
        m = mock.Mock()

        r = ice.WildcardRoute('/<>', m)
        self.assertEqual(r.match('/foo'), (m, ['foo'], {}))
        self.assertEqual(r.match('/bar'), (m, ['bar'], {}))
        self.assertEqual(r.match('/<baz>'), (m, ['<baz>'], {}))
        self.assertIsNone(r.match('/'))
        self.assertIsNone(r.match('/foo/'))
        self.assertIsNone(r.match('/foo/bar'))

        r = ice.WildcardRoute('/<>/<>', m)
        self.assertEqual(r.match('/foo/bar'), (m, ['foo', 'bar'], {}))
        self.assertEqual(r.match('/<foo>/bar'), (m, ['<foo>', 'bar'], {}))
        self.assertIsNone(r.match('/foo'))
        self.assertIsNone(r.match('/foo/'))
        self.assertIsNone(r.match('/foo/bar/'))
        self.assertIsNone(r.match('//bar/'))

        r = ice.WildcardRoute('/<>/bar', m)
        self.assertEqual(r.match('/foo/bar'), (m, ['foo'], {}))
        self.assertIsNone(r.match('/foo'))
        self.assertIsNone(r.match('/bar'))
        self.assertIsNone(r.match('/foo/bar/'))
        self.assertIsNone(r.match('/foo/bar/baz'))
Exemplo n.º 4
0
    def test_anonymous_path_wildcard(self):
        m = mock.Mock()

        r = ice.WildcardRoute('<:path>', m)
        self.assertEqual(r.match('/foo'), (m, ['/foo'], {}))
        self.assertEqual(r.match('/bar'), (m, ['/bar'], {}))
        self.assertEqual(r.match('/<baz>'), (m, ['/<baz>'], {}))
        self.assertEqual(r.match('/foo/'), (m, ['/foo/'], {}))
        self.assertEqual(r.match('/foo/bar'), (m, ['/foo/bar'], {}))
        self.assertEqual(r.match('foo'), (m, ['foo'], {}))
        self.assertEqual(r.match('foo/'), (m, ['foo/'], {}))
        self.assertEqual(r.match('foo/bar'), (m, ['foo/bar'], {}))

        r = ice.WildcardRoute('<:path><:path>', m)
        self.assertEqual(r.match('/foo/bar'), (m, ['/foo/ba', 'r'], {}))
        self.assertEqual(r.match('/foo/bar/baz'),
                         (m, ['/foo/bar/ba', 'z'], {}))
        self.assertEqual(r.match('/foo'), (m, ['/fo', 'o'], {}))

        r = ice.WildcardRoute('/<:path>/bar', m)
        self.assertEqual(r.match('/foo/bar'), (m, ['foo'], {}))
        self.assertEqual(r.match('/<foo>/bar'), (m, ['<foo>'], {}))
        self.assertEqual(r.match('/foo/bar/bar'), (m, ['foo/bar'], {}))
        self.assertIsNone(r.match('/foo'))
        self.assertIsNone(r.match('/bar'))
        self.assertIsNone(r.match('/foo/bar/'))
        self.assertIsNone(r.match('/foo/bar/baz'))

        r = ice.WildcardRoute('/<:path>', m)
        self.assertEqual(r.match('/foo/bar'), (m, ['foo/bar'], {}))
        self.assertIsNone(r.match('/'))
Exemplo n.º 5
0
    def test_throwaway_wildcard_with_type(self):
        m = mock.Mock()

        r = ice.WildcardRoute('/<!:str>', m)
        self.assertEqual(r.match('/foo'), (m, [], {}))
        self.assertEqual(r.match('/bar'), (m, [], {}))
        self.assertIsNone(r.match('/foo/'))
        self.assertIsNone(r.match('/foo/bar'))

        r = ice.WildcardRoute('/<!:int>/<!:-int>', m)
        self.assertEqual(r.match('/10/-20'), (m, [], {}))
        self.assertIsNone(r.match('/-10/-20'))
        self.assertIsNone(r.match('/-10'))
        self.assertIsNone(r.match('/foo/bar'))
        self.assertIsNone(r.match('/'))
Exemplo n.º 6
0
 def test_consecutive_int_wildcard(self):
     m = mock.Mock()
     r = ice.WildcardRoute('/<:int><:-int>', m)
     self.assertEqual(r.match('/123'), (m, [12, 3], {}))
     self.assertEqual(r.match('/00'), (m, [0, 0], {}))
     self.assertEqual(r.match('/12-3'), (m, [12, -3], {}))
     self.assertIsNone(r.match('/12+3'))
     self.assertIsNone(r.match('/-12-3'))
     self.assertIsNone(r.match('/12-3-4'))
     self.assertIsNone(r.match('/000'))
     self.assertIsNone(r.match('/0000'))
Exemplo n.º 7
0
    def test_throwaway_wildcard_with_colon(self):
        m = mock.Mock()

        r = ice.WildcardRoute('/<!:>', m)
        self.assertEqual(r.match('/foo'), (m, [], {}))
        self.assertEqual(r.match('/bar'), (m, [], {}))
        self.assertIsNone(r.match('/foo/'))
        self.assertIsNone(r.match('/foo/bar'))

        r = ice.WildcardRoute('/<!:>/<!:>', m)
        self.assertEqual(r.match('/foo/bar'), (m, [], {}))
        self.assertIsNone(r.match('/foo'), (m, [], {}))
        self.assertIsNone(r.match('/foo/'), (m, [], {}))
        self.assertIsNone(r.match('/foo/'), (m, [], {}))

        r = ice.WildcardRoute('/<!:>/bar', m)
        self.assertEqual(r.match('/foo/bar'), (m, [], {}))
        self.assertIsNone(r.match('/foo'))
        self.assertIsNone(r.match('/bar'))
        self.assertIsNone(r.match('/foo/bar/'))
        self.assertIsNone(r.match('/foo/bar/baz'))
Exemplo n.º 8
0
    def test_regex_ineffective_in_wildcard(self):
        # Any regular expression should get escaped by ice.WildcardRoute
        # so that they match literal strings
        m = mock.Mock()

        r = ice.WildcardRoute('/.*', m)
        self.assertEqual(r.match('/.*'), (m, [], {}))
        self.assertIsNone(r.match('/foo'))

        r = ice.WildcardRoute('/(.*)', m)
        self.assertEqual(r.match('/(.*)'), (m, [], {}))
        self.assertIsNone(r.match('/foo'))
        self.assertIsNone(r.match('/(foo)'))

        r = ice.WildcardRoute(r'/\w{3}', m)
        self.assertEqual(r.match('/\w{3}'), (m, [], {}))
        self.assertIsNone(r.match('/foo'))

        r = ice.WildcardRoute('/<>/<a>/(.*)', m)
        self.assertEqual(r.match('/foo/bar/(.*)'), (m, ['foo'], {'a': 'bar'}))
        self.assertIsNone(r.match('/foo/bar/baz'))
        self.assertIsNone(r.match('/foo/bar/(baz)'))
Exemplo n.º 9
0
 def test_anonymous_negative_int_wildcard(self):
     m = mock.Mock()
     r = ice.WildcardRoute('/<:-int>', m)
     self.assertEqual(r.match('/0'), (m, [0], {}))
     self.assertEqual(r.match('/-1'), (m, [-1], {}))
     self.assertEqual(r.match('/1'), (m, [1], {}))
     self.assertEqual(r.match('/-12'), (m, [-12], {}))
     self.assertEqual(r.match('/12'), (m, [12], {}))
     self.assertEqual(r.match('/-123'), (m, [-123], {}))
     self.assertEqual(r.match('/123'), (m, [123], {}))
     self.assertIsNone(r.match('/-0'))
     self.assertIsNone(r.match('/+0'))
     self.assertIsNone(r.match('/+1'))
     self.assertIsNone(r.match('/+12'))
     self.assertIsNone(r.match('/+123'))
     self.assertIsNone(r.match('/-01'))
     self.assertIsNone(r.match('/01'))
     self.assertIsNone(r.match('/+01'))
     self.assertIsNone(r.match('/-012'))
     self.assertIsNone(r.match('/012'))
     self.assertIsNone(r.match('/+012'))
     self.assertIsNone(r.match('/1foo'))
     self.assertIsNone(r.match('/foo'))
     self.assertIsNone(r.match('/1/2'))
Exemplo n.º 10
0
 def test_no_wildcard(self):
     m = mock.Mock()
     r = ice.WildcardRoute('/foo', m)
     self.assertEqual(r.match('/foo'), (m, [], {}))
     self.assertIsNone(r.match('/foo/'))