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([])
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
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)