示例#1
0
    def test_get_provider(self):
        provider = ProviderModel.get(1)
        assert provider.name == 'Fornecedor 01'

        provider = ProviderModel.get_by_cnpj('04790618000153')
        assert provider.name == 'Fornecedor 01'

        providers = ProviderModel.list()
        assert len(providers) == 1
        assert type(providers) == type([])
示例#2
0
    def put(self):
        try:
            data = request.get_json()
            item = ProviderModel.get(data['id'])

            for parameter in data:
                setattr(item, parameter, data[parameter])
            item.update()

            return "success", 201
        except:
            return "error", 401
示例#3
0
 def get(self):
     if 'id' in request.args:
         item = ProviderModel.get(request.args['id'])
         item = serialize_model(item)
         return item
     elif 'email' in request.args:
         item = ProviderModel.get_by_email(request.args['email'])
         item = serialize_model(item)
         return item
     elif 'cnpj' in request.args:
         item = ProviderModel.get_by_cnpj(request.args['cnpj'])
         item = serialize_model(item)
         return item
     list = ProviderModel.list()
     return serialize_model_list(list)