示例#1
0
def first_product():
    if ProviderModel.get_by_cnpj("04790618000153") == None:
        first_provider()
        return
    new_product = ProductModel()
    new_product.name = "Produto 01"
    new_product.provider = ProviderModel.get_by_cnpj("04790618000153")
    new_product.quantity = 100
    new_product.price = 10.0
    new_product.available = True
    new_product.save()
    return
示例#2
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([])
    def test_save_product(self):
        products = len(ProductModel.list())

        new_product = ProductModel()
        new_product.name = "Produto 02"
        new_product.provider = ProviderModel.get_by_cnpj("04790618000153")
        new_product.quantity = 100
        new_product.price = 10.0
        new_product.available = True
        new_product.save()

        assert products + 1 == len(ProductModel.list())
示例#4
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)
示例#5
0
def first_provider():
    if ProviderModel.get_by_cnpj("04790618000153") != None:
        return
    new_provider = ProviderModel()
    new_provider.name = "Fornecedor 01"
    new_provider.cnpj = "04790618000153"
    new_provider.address = "Endereço 01"
    new_provider.city = "Cidade 01"
    new_provider.country = "País 01"
    new_provider.cep_code = "000000-000"
    new_provider.responsible_name = "Matheus D'Adamo Milani"
    new_provider.responsible_email = "*****@*****.**"
    new_provider.responsible_phone = "+55(11)97717-9999"
    new_provider.active = True
    new_provider.save()
    return
示例#6
0
    def test_update_provider(self):
        provider = ProviderModel.get_by_cnpj('98617744000154')
        provider.name = "Fornecedor 02 editado"
        provider.update()

        assert provider.name == "Fornecedor 02 editado"