Skip to content

Commit

Permalink
Merge pull request #33 from GonzaloEBaez/refactor/D101
Browse files Browse the repository at this point in the history
Refactor/D101-Arreglar migración
  • Loading branch information
CandelAbregu authored Jun 5, 2024
2 parents b573e24 + 30e5bce commit 48c6f6c
Show file tree
Hide file tree
Showing 10 changed files with 166 additions and 13 deletions.
10 changes: 7 additions & 3 deletions .ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ exclude = [
"node_modules",
"site-packages",
"venv",
"migrations"
"migrations",

]

# Same as Black.
#Same as Black.
line-length = 88
indent-width = 4

Expand All @@ -38,7 +39,10 @@ target-version = "py38"

[lint]
# Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default.
select = ["E4", "E7", "E9", "F", "COM812", "D102", "D103","I001"]


select = ["E4", "E7", "E9", "F", "COM812", "D102", "D103","I001","D101"]

ignore = []

# Allow fix for all enabled rules (when `--fix`) is provided.
Expand Down
5 changes: 5 additions & 0 deletions app/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,10 @@


class AppConfig(AppConfig):
"""
Configuración de la aplicación MyApp.
Esta clase se encarga de configurar la aplicación MyApp.
"""
default_auto_field = "django.db.models.BigAutoField"
name = "app"
14 changes: 14 additions & 0 deletions app/migrations/0015_merge_20240604_1813.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Generated by Django 5.0.4 on 2024-06-04 21:13

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('app', '0012_alter_product_price'),
('app', '0014_merge_20240603_0914'),
]

operations = [
]
14 changes: 14 additions & 0 deletions app/migrations/0015_merge_20240604_1908.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Generated by Django 5.0.4 on 2024-06-04 22:08

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('app', '0012_alter_product_price'),
('app', '0014_merge_20240603_0914'),
]

operations = [
]
6 changes: 5 additions & 1 deletion app/migrations/0016_delete_veterinario.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@

# Generated by Django 5.0.4 on 2024-06-04 22:08

# Generated by Django 5.0.4 on 2024-06-03 23:34


from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('app', '0015_merge_20240603_1806'),
('app', '0015_merge_20240604_1908'),
]

operations = [
Expand Down
15 changes: 15 additions & 0 deletions app/migrations/0020_merge_20240605_1221.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Generated by Django 5.0.4 on 2024-06-05 15:21

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('app', '0015_merge_20240603_1806'),
('app', '0015_merge_20240604_1813'),
('app', '0019_merge_20240605_0942'),
]

operations = [
]
45 changes: 43 additions & 2 deletions app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@


class CityEnum(models.TextChoices):
LA_PLATA = 'La Plata',
"""
Enumeracion de la Ciudad
"""
LA_PLATA = 'La Plata',
BERISSO = 'Berisso',
ENSENADA = 'Ensenada',

Expand Down Expand Up @@ -47,6 +50,9 @@ def validate_client(data):
return errors

class Client(models.Model):
"""
Modelo que representa a un cliente en el sistema.
"""
name = models.CharField(max_length=100)
phone = models.CharField(max_length=15)
email = models.EmailField()
Expand Down Expand Up @@ -147,6 +153,9 @@ def validate_provider(data):
return errors

class Provider(models.Model):
"""
Modelo que representa a un cliente en el sistema.
"""
name = models.CharField(max_length=100)
email = models.EmailField()
address = models.CharField(max_length=100)
Expand Down Expand Up @@ -201,9 +210,20 @@ def update_provider(self, provider_data):
self.name = provider_data.get("name", "") or self.name
self.email = provider_data.get("email", "") or self.email
self.address = provider_data.get("address", "") or self.address


try:
self.save()
return True, None
except Exception as e:
return False, e



self.save()
return True, None


def validate_product(data):
"""
Valida los datos del producto.
Expand Down Expand Up @@ -240,6 +260,9 @@ def validate_product(data):
return errors

class Product(models.Model):
"""
Modelo que representa a un producto en el sistema.
"""
name = models.CharField(max_length=100)
product_type = models.CharField(max_length=15)
price = models.DecimalField(max_digits=10, decimal_places=2)
Expand Down Expand Up @@ -344,6 +367,9 @@ def validate_pet(data):
return errors

class Pet(models.Model):
"""
Modelo que representa a una mascota en el sistema.
"""
name = models.CharField(max_length=40)
breed = models.CharField(max_length=40)
birthday = models.DateField()
Expand Down Expand Up @@ -440,6 +466,9 @@ def validate_veterinary(data):
return errors

class Veterinary(models.Model):
"""
Modelo que representa a un veterinario en el sistema.
"""
name = models.CharField(max_length=100)
email = models.EmailField()
phone = models.CharField(max_length=15)
Expand Down Expand Up @@ -530,6 +559,9 @@ def validate_medicine(data):
return errors

class Medicine(models.Model):
"""
Modelo que representa una medicina en el sistema.
"""
name = models.CharField(max_length=100)
description = models.CharField(max_length=255)
dose = models.IntegerField()
Expand Down Expand Up @@ -585,5 +617,14 @@ def update_medicine(self, medicine_data):
self.name = medicine_data.get("name", "") or self.name
self.description = medicine_data.get("description", "") or self.description
self.dose = medicine_data.get("dose", "") or self.dose


try:
self.save()
return True, None
except Exception as e:
return False, {"errors": str(e)}

self.save()
return True, None
return True, None

18 changes: 17 additions & 1 deletion app/tests_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@


class HomePageTest(TestCase):
"""
Pruebas para la página de inicio.
"""
def test_use_home_template(self):
"""
Esta funcion testea que el template del home funcione.
Expand All @@ -19,6 +22,9 @@ def test_use_home_template(self):
"""

class ClientsTest(TestCase):
"""
Pruebas para el repositorio de clientes.
"""
def test_repo_use_repo_template(self):
"""
Esta función testea que el template del repo funcione.
Expand Down Expand Up @@ -247,6 +253,7 @@ def test_user_cant_edit_client_with_incorrect_name(self):


class MedicineIntegrationTest(TestCase):
"""Pruebas de integración para el modelo de Medicina. """
def test_can_create_medicine(self):
"""
Esta función testea si pudo crear una medicina.
Expand Down Expand Up @@ -323,6 +330,9 @@ def test_validation_invalid_dose_is_less_than_1(self):
)
self.assertContains(response, "La dosis debe estar en un rango de 1 a 10")
class ProviderTest(TestCase):
"""
Pruebas para el repositorio de proveedores.
"""
def test_repo_use_repo_template(self):
"""
Esta función verifica que un repositorio está utilizando una plantilla de repositorio específica.
Expand Down Expand Up @@ -387,6 +397,9 @@ def test_validation_address_null(self): #Agrego una función especifica del issu


class PetsTest(TestCase):
"""
Pruebas para el modelo de mascotas.
"""
def test_create_pet_with_valid_weight(self):
"""
Esta función verifica que un sistema permita la creación de una mascota con un peso válido.
Expand Down Expand Up @@ -489,8 +502,10 @@ def test_create_pet_with_invalid_birthday(self):
# Verificar que se muestra un mensaje de error en la respuesta
self.assertContains(response, "La fecha de nacimiento debe ser menor a la fecha actual")


class ProductsTest(TestCase):
"""
Pruebas para el modelo de productos.
"""
def test_create_product_with_valid_price(self):
# Crear un producto con precio válido
"""
Expand All @@ -500,6 +515,7 @@ def test_create_product_with_valid_price(self):
reverse("product_form"),
data={
"name": "Producto Test",

"product_type": "Tipo Test",
"price": "10.00", # Precio válido
},
Expand Down
16 changes: 16 additions & 0 deletions app/tests_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@


class ClientModelTest(TestCase):
"""
Pruebas para el modelo Cliente.
"""
def test_can_create_and_get_client(self):
"""
Prueba la creación y recuperación de un cliente.
Expand Down Expand Up @@ -187,6 +190,9 @@ def test_update_client_with_incorrect_name(self):
self.assertEqual(client_updated.name, "Juan Sebastian Veron")

class MedicineModelTest(TestCase):
"""
Pruebas para el modelo Medicina.
"""

def test_can_create_medicine_with_valid_dose(self):
"""
Expand Down Expand Up @@ -248,6 +254,10 @@ def test_update_medicine_with_invalid_dose(self):
self.assertEqual(medicine_updated.dose, 5)

class ProviderModelTest(TestCase):
"""
Pruebas para el modelo Provedor.
"""

def test_can_create_and_get_provider(self):
"""
Prueba la creación y recuperación de un proveedor.
Expand Down Expand Up @@ -286,6 +296,9 @@ def test_provider_address(self):
self.assertEqual(provider.address, addres) #verifica que la direccion recuperada coincida con la especifica

class PetModelTest(TestCase):
"""
Pruebas para el modelo Pet.
"""
def test_validate_pet_birthday(self):
"""
Prueba la validación de la fecha de nacimiento de una mascota.
Expand Down Expand Up @@ -347,6 +360,9 @@ def test_create_pet_with_invalid_weight_negative(self):
self.assertEqual(message_or_errors["weight"], "El peso debe ser mayor a cero")

class ProductModelTest(TestCase):
"""
Pruebas para el modelo Producto.
"""
def test_create_product_with_valid_price(self):
"""
Prueba la creación de un producto con un precio válido.
Expand Down
Loading

0 comments on commit 48c6f6c

Please sign in to comment.