Пример #1
0
    def test_match_multiple_stars(self):
        self.dispatcher.map('/foo/bar/1', 1)
        self.dispatcher.map('/foo/bar/2', 2)

        self.sortAndAssertSequenceEqual(
            [Handler(1, []), Handler(2, [])],
            self.dispatcher.handlers_for_address("/*/*/*"))
Пример #2
0
 def test_call_correct_dispatcher_on_star(self):
     self.dispatcher.map('/a+b', 1)
     self.dispatcher.map('/aaab', 2)
     self.sortAndAssertSequenceEqual(
         [Handler(2, [])], self.dispatcher.handlers_for_address('/aaab'))
     self.sortAndAssertSequenceEqual(
         [Handler(1, [])], self.dispatcher.handlers_for_address('/a+b'))
Пример #3
0
    def test_match_address_contains_plus_as_character(self):
        self.dispatcher.map('/footest/bar+tender/1', 1)

        self.sortAndAssertSequenceEqual(
            [Handler(1, [])], self.dispatcher.handlers_for_address("/foo*/bar+*/*"))
        self.sortAndAssertSequenceEqual(
            [Handler(1, [])], self.dispatcher.handlers_for_address("/foo*/bar*/*"))
Пример #4
0
 def test_simple_map_and_match(self):
     handler = object()
     self.dispatcher.map('/test', handler, 1, 2, 3)
     self.dispatcher.map('/test2', handler)
     self.sortAndAssertSequenceEqual(
         [Handler(handler, [1, 2, 3])], self.dispatcher.handlers_for_address('/test'))
     self.sortAndAssertSequenceEqual(
         [Handler(handler, [])], self.dispatcher.handlers_for_address('/test2'))
Пример #5
0
    def test_use_default_handler_when_set_and_no_match(self):
        handler = object()
        self.dispatcher.set_default_handler(handler)

        self.sortAndAssertSequenceEqual(
            [Handler(handler, [])],
            self.dispatcher.handlers_for_address('/test'))
Пример #6
0
 def test_map_double_stars(self):
     self.dispatcher.map('/foo/*/bar/*', 1)
     self.sortAndAssertSequenceEqual(
         [Handler(1, [])],
         self.dispatcher.handlers_for_address("/foo/wild/bar/wild"))
     self.sortAndAssertSequenceEqual(
         [], self.dispatcher.handlers_for_address("/foo/wild/nomatch/wild"))
Пример #7
0
    def test_unmap(self):
        def dummyhandler():
            pass

        # Test with handler returned by map
        returnedhandler = self.dispatcher.map("/map/me", dummyhandler)
        self.sortAndAssertSequenceEqual([Handler(dummyhandler, [])], self.dispatcher.handlers_for_address("/map/me"))
        self.dispatcher.unmap("/map/me", returnedhandler)
        self.sortAndAssertSequenceEqual([], self.dispatcher.handlers_for_address("/map/me"))

        # Test with reconstructing handler
        self.dispatcher.map("/map/me/too", dummyhandler)
        self.sortAndAssertSequenceEqual([Handler(dummyhandler, [])],
                                        self.dispatcher.handlers_for_address("/map/me/too"))
        self.dispatcher.unmap("/map/me/too", dummyhandler)
        self.sortAndAssertSequenceEqual([], self.dispatcher.handlers_for_address("/map/me/too"))
Пример #8
0
    def test_example_from_spec(self):
        addresses = [
            "/first/this/one",
            "/second/1",
            "/second/2",
            "/third/a",
            "/third/b",
            "/third/c",
        ]
        for index, address in enumerate(addresses):
            self.dispatcher.map(address, index)

        for index, address in enumerate(addresses):
            self.sortAndAssertSequenceEqual(
                [Handler(index, [])], self.dispatcher.handlers_for_address(address))

        self.sortAndAssertSequenceEqual(
            [Handler(1, []), Handler(2, [])], self.dispatcher.handlers_for_address("/second/?"))

        self.sortAndAssertSequenceEqual(
            [Handler(3, []), Handler(4, []), Handler(5, [])],
            self.dispatcher.handlers_for_address("/third/*"))
Пример #9
0
 def test_multiple_handlers_with_wildcard_map(self):
     self.dispatcher.map('/foo/bar', 1)
     self.dispatcher.map('/*', 2)
     self.sortAndAssertSequenceEqual(
         [Handler(1, []), Handler(2, [])],
         self.dispatcher.handlers_for_address("/foo/bar"))
Пример #10
0
 def test_map_root_star(self):
     self.dispatcher.map('/*', 1)
     self.sortAndAssertSequenceEqual(
         [Handler(1, [])],
         self.dispatcher.handlers_for_address("/anything/matches"))
Пример #11
0
 def test_map_star(self):
     self.dispatcher.map('/starbase/*', 1)
     self.sortAndAssertSequenceEqual(
         [Handler(1, [])],
         self.dispatcher.handlers_for_address("/starbase/bar"))