Beispiel #1
0
 def __init__(self, method, pattern, current_handler):
     method = ensure_str(method)
     pattern = ensure_str(pattern)
     super().__init__(f"Cannot register route pattern `{pattern}` for "
                      f"`{method}` more than once. "
                      f"This pattern is already registered for handler "
                      f"{current_handler.__qualname__}.")
     self.method = method
     self.pattern = pattern
     self.current_handler = current_handler
Beispiel #2
0
async def test_controllers_with_duplicate_routes_throw(first_pattern,
                                                       second_pattern):
    app = FakeApplication()
    app.controllers_router = RoutesRegistry()
    get = app.controllers_router.get

    class A(Controller):
        @get(first_pattern)
        async def index(self, request: Request):
            ...

    class B(Controller):
        @get(second_pattern)
        async def index(self, request: Request):
            ...

    with pytest.raises(RouteDuplicate) as context:
        app.use_controllers()

    error = context.value
    assert "Cannot register route pattern `" + ensure_str(
        first_pattern) + "` for `GET` more than once." in str(error)
    assert ("This pattern is already registered for handler "
            "test_controllers_with_duplicate_routes_throw.<locals>.A.index."
            in str(error))
Beispiel #3
0
def test_ensure_str_throws_for_invalid_value():
    with pytest.raises(ValueError):
        ensure_str(True)
Beispiel #4
0
def test_ensure_str(value, expected_result):
    assert ensure_str(value) == expected_result