def on_post(self, req, resp): pedido_gateway = PedidoGateway(self.db.session) body = req.bounded_stream.read().decode() if not body: resp.status = falcon.HTTP_PRECONDITION_FAILED resp.body = json.dumps({"erro": "POST precisa conter um body."}) return resp raw_json = json.loads(body) data = raw_json["data"] cliente_id = raw_json["cliente_id"] valor = raw_json["valor"] pedido_gateway.create(data, cliente_id, valor) resp.status = falcon.HTTP_201
class TestPedidoGatewayTestCase(object): def setup(self): configurations = load_config_file() db_manager = DBManager(configurations.db_test.connection) db_manager.setup() self.pedido_gateway = PedidoGateway(db_manager.session) def teardown(self): self.pedido_gateway.delete_all() def _cria_um_pedido(self): return self.pedido_gateway.create(data=datetime.now(), cliente_id=1, valor=1.0)