Ejemplo n.º 1
0
    def test_create(self):
        body = JSONAPIErrorBody.create(KeyError("message"))
        error = JSONAPIError.create([body, body])

        assert isinstance(error, JSONAPIError)

        assert error.raw == {"errors": [body.raw, body.raw]}
Ejemplo n.º 2
0
    def test_subclassing(self):
        body = JSONAPIErrorBody.create(KeyError("test"))

        class TestError(JSONAPIError):
            def _error_bodies(self):
                yield body

        error = TestError("Name")

        assert error.as_dict() == {"errors": [body.raw]}
Ejemplo n.º 3
0
 def _format_error(self, error):
     return JSONAPIErrorBody.create(
         self,
         detail=error.message,
         pointer=self._path_to_string(error.path),
         meta={
             "schema": {
                 "pointer": self._path_to_string(error.schema_path)
             },
             "context": [context.message for context in error.context],
         },
         status=self.http_status,
     )
Ejemplo n.º 4
0
    def test_create(self):
        meta = {"metadata": 1}
        body = JSONAPIErrorBody.create(
            KeyError("message"),
            title="title",
            detail="detail",
            pointer="_pointer",
            status=200,
            meta=meta,
        )

        assert isinstance(body, JSONAPIErrorBody)
        assert body.raw == {
            "code": "KeyError",
            "title": "title",
            "detail": "detail",
            "meta": meta,
            "source": {
                "pointer": "_pointer"
            },
            "status": "200",
        }

        assert body.detail == "detail"
Ejemplo n.º 5
0
    def test_degenerate_create(self):
        body = JSONAPIErrorBody.create(KeyError("message"))

        assert body.raw == {"code": "KeyError", "title": "message"}

        assert body.detail is None
Ejemplo n.º 6
0
 def _error_bodies(self):
     yield JSONAPIErrorBody.create(self, status=self.http_status)