コード例 #1
0
    def on_put(self, req, resp, cliente_id=None):
        cliente_gateway = ClienteGateway(self.db.session)

        if not cliente_id:
            resp.status = falcon.HTTP_412
            return resp

        resp.status = falcon.HTTP_200
        raw_json = json.loads(req.bounded_stream.read().decode())
        primeiro_nome = raw_json.get("primeiro_nome", None)
        ultimo_nome = raw_json.get("ultimo_nome", None)
        email = raw_json.get("email", None)
        cliente_gateway.update(cliente_id, primeiro_nome, ultimo_nome, email)
コード例 #2
0
    def on_post(self, req, resp):
        cliente_gateway = ClienteGateway(self.db.session)

        resp.status = falcon.HTTP_201
        raw_json = json.loads(req.bounded_stream.read().decode())
        primeiro_nome = raw_json["primeiro_nome"]
        ultimo_nome = raw_json["ultimo_nome"]
        email = raw_json["email"]

        try:
            cliente_gateway.create(primeiro_nome, ultimo_nome, email)
        except DuplicatedEntityException as exc:
            resp.status = falcon.HTTP_412
            resp.body = json.dumps({"erro": str(exc)})
            return resp
コード例 #3
0
    def on_get(self, req, resp, cliente_id=None):
        cliente_gateway = ClienteGateway(self.db.session)

        if cliente_id:
            try:
                clientes = cliente_gateway.get_one(int(cliente_id))
                content = clientes.as_dict
            except ClienteNotFoundException as exc:
                resp.status = falcon.HTTP_404
                resp.body = json.dumps({"erro": str(exc)})
                return resp
        else:
            clientes = cliente_gateway.get_all()
            content = [cliente.as_dict for cliente in clientes]

        resp.status = falcon.HTTP_200
        resp.body = json.dumps(content)
コード例 #4
0
class TestClienteGatewayTestCase(object):
    def setup(self):
        configurations = load_config_file()
        db_manager = DBManager(configurations.db_test.connection)
        db_manager.setup()
        self.cliente_gateway = ClienteGateway(db_manager.session)

    def teardown(self):
        self.cliente_gateway.delete_all()

    def _cria_um_cliente(self,
                         primeiro_nome: str = "",
                         ultimo_nome: str = "",
                         email: str = ""):
        return self.cliente_gateway.create(
            primeiro_nome=primeiro_nome or "João",
            ultimo_nome=ultimo_nome or "Ninguém",
            email=email or "*****@*****.**",
        )
コード例 #5
0
 def setup(self):
     configurations = load_config_file()
     db_manager = DBManager(configurations.db_test.connection)
     db_manager.setup()
     self.cliente_gateway = ClienteGateway(db_manager.session)
コード例 #6
0
 def _gera_um_cliente(self, primeiro_nome, ultimo_nome, email):
     return ClienteGateway(self.session).create(primeiro_nome=primeiro_nome,
                                                ultimo_nome=ultimo_nome,
                                                email=email)
コード例 #7
0
 def teardown(self):
     ClienteGateway(self.session).delete_all()
     PedidoGateway(self.session).delete_all()