Exemplo n.º 1
0
    def post(self, *args, **kwargs):
        self.set_header("Content-Type", "application/json")

        try:
            data = json.loads(self.request.body.decode("utf8"))
            conv = Conveyance(data)
            compose = conv.compose()(conv.definitions, conv.resources)
        except (ValidationError, jsonschema.ValidationError) as e:
            # print('this')
            # raise tornado.web.HTTPError(404, reason=e.args[0])
            # compose = {
            #     "validation_error": e
            # }

            self.set_status(401)
            self.set_header('WWW-Authenticate', 'Basic realm="something"')
            data = {
                "error": str(e)
            }
            self.write(json.dumps(data))
            raise tornado.web.Finish()
        except:
            self.set_status(401)
            self.set_header('WWW-Authenticate', 'Basic realm="something"')
            data = {
                "error": sys.exc_info()[0]
            }
            self.write(json.dumps(data))
            raise tornado.web.Finish()


        self.write(json.dumps(compose))
Exemplo n.º 2
0
    def post(self, *args, **kwargs):
        self.set_header("Content-Type", "application/json")

        try:
            data = json.loads(self.request.body.decode("utf8"))
            conv = Conveyance(data)
            compose = conv.compose()(conv.definitions, conv.resources)
        except (ValidationError, jsonschema.ValidationError) as e:
            # print('this')
            # raise tornado.web.HTTPError(404, reason=e.args[0])
            # compose = {
            #     "validation_error": e
            # }

            self.set_status(401)
            self.set_header('WWW-Authenticate', 'Basic realm="something"')
            data = {"error": str(e)}
            self.write(json.dumps(data))
            raise tornado.web.Finish()
        except:
            self.set_status(401)
            self.set_header('WWW-Authenticate', 'Basic realm="something"')
            data = {"error": sys.exc_info()[0]}
            self.write(json.dumps(data))
            raise tornado.web.Finish()

        self.write(json.dumps(compose))
Exemplo n.º 3
0
    def test_payload_processing_example(self):
        # TODO: http_call() should not have been called (use mocks)
        conv = Conveyance(PAYLOAD_1)
        compose = conv.compose()(conv.definitions, conv.resources)

        self.assertEqual(compose, RESPONSE_1)