Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor/D101-Arreglar migración #33

Merged
merged 22 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -5,7 +5,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 @@ -41,6 +44,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 @@ -136,6 +142,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 @@ -190,9 +199,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 @@ -229,6 +249,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 @@ -333,6 +356,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 @@ -429,6 +455,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 @@ -519,6 +548,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 @@ -574,5 +606,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 @@ -162,6 +168,7 @@ def test_edit_user_with_invalid_data_test_city(self):
self.assertEqual(editedClient.city, "La Plata")

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 @@ -238,6 +245,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 @@ -302,6 +312,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 @@ -404,8 +417,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 @@ -415,6 +430,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 @@ -5,6 +5,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 @@ -99,6 +102,9 @@ def test_update_client_with_email_null(self): #nuevo test verificando que no pue

self.assertEqual(client_updated.email, "[email protected]")
class MedicineModelTest(TestCase):
"""
Pruebas para el modelo Medicina.
"""

def test_can_create_medicine_with_valid_dose(self):
"""
Expand Down Expand Up @@ -160,6 +166,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 @@ -198,6 +208,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 @@ -259,6 +272,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
Loading