示例#1
0
    def test_handle_fails_on_unknown_path(self) -> None:
        """Test that passing unknown path fails."""
        request = Request("GET", "/foo/bar", {})
        router = Router()

        with self.assertRaises(ServiceNotFoundException):
            router.handle(request)
示例#2
0
    def test_request(self) -> None:
        """Test that Request is working."""
        method = "GET"
        operation = "/api/a/b/x"
        data = self._get_random_dict()
        request = Request(method, operation, data)

        self.assertEqual(method, request.method)
        self.assertEqual(operation, request.operation)
        self.assertEqual(data, request.data)
示例#3
0
    def test_handle_fails_on_unsupported_route_definition_type(self) -> None:
        """Test that not supported route definition type fails."""
        from lpot.ux.components.file_browser.file_browser import get_directory_entries
        from lpot.ux.web.router import RoutingDefinition

        router = Router()
        router.routes = {
            "foo": RoutingDefinition(get_directory_entries),
        }
        request = Request("GET", "foo", {})

        with self.assertRaises(ValueError):
            router.handle(request)
示例#4
0
    def test_executes_expected_realtime_function(
        self,
        mocked_get_directory_entries: MagicMock,
    ) -> None:
        """Test that passing known realtime endpoint succeeds."""
        expected_return = {
            "foo": "bar",
        }
        mocked_get_directory_entries.return_value = expected_return
        request = Request("GET", "filesystem", {"path": ["."]})

        router = Router()
        response = router.handle(request)

        self.assertEqual({}, response.command)
        self.assertEqual(expected_return, response.data)
示例#5
0
    def test_executes_expected_deferred_function(
        self,
        mocked_thread: MagicMock,
        mocked_function: MagicMock,
    ) -> None:
        """Test that passing known deferred endpoint succeeds."""
        params = {
            "foo": "bar",
        }
        request = Request("GET", "get_boundary_nodes", params)

        router = Router()
        response = router.handle(request)

        mocked_thread.assert_called_once_with(target=mocked_function,
                                              args=(params, ))

        self.assertEqual({}, response.command)
        self.assertEqual({
            "exit_code": 102,
            "message": "processing"
        }, response.data)
示例#6
0
def build_parameters(endpoint: str, request: WebRequest) -> Request:
    """Build domain object from flask request."""
    data = request.get_json() if request.is_json else request.args.to_dict(
        flat=False)
    return Request(request.method, endpoint, data)