Exemplo n.º 1
0
    def test_it_doesnt_raises_an_error_if_user_declares_a_metrics_route_with_asyncworker_metrics_disabled(
            self):

        with patch(
                "asyncworker.routes.conf.settings",
                METRICS_ROUTE_ENABLED=False,
                METRICS_ROUTE_PATH=settings.METRICS_ROUTE_PATH,
        ):
            route = HTTPRoute(methods=["GET"],
                              routes=[settings.METRICS_ROUTE_PATH])
            self.assertIsInstance(route, HTTPRoute)
Exemplo n.º 2
0
    def test_it_registers_routes(self):
        handler = CoroutineMock()

        route = HTTPRoute(routes=["/"],
                          methods=["POST"],
                          handler=handler,
                          default_options={})

        self.routes_registry.add_route(route)

        self.assertEqual(route, self.routes_registry.route_for(handler))
Exemplo n.º 3
0
    def test_routes_are_subscriptables(self):
        handler = CoroutineMock()
        route = HTTPRoute(routes=["/"],
                          methods=["POST"],
                          handler=handler,
                          default_options={})

        self.routes_registry.add_route(route)

        self.assertEqual(route["type"], RouteTypes.HTTP)
        with self.assertRaises(KeyError):
            _ = route["Invalid key"]
Exemplo n.º 4
0
 def test_valid_http_methods(self):
     route = HTTPRoute(
         methods=[
             "POST",
             "GET",
             "DELeTE",
             "PUT",
             "head",
             "options",
             "patch",
             "TRACE",
             "connect",
         ],
         handler=CoroutineMock(),
         routes=["/"],
     )
     self.assertIsInstance(route, HTTPRoute)
Exemplo n.º 5
0
 def test_it_raises_an_error_if_user_declares_a_conflicting_metrics_route(
         self):
     with self.assertRaises(ValueError):
         HTTPRoute(methods=["GET"], routes=[settings.METRICS_ROUTE_PATH])