Skip to content
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
47 changes: 47 additions & 0 deletions essenza/product/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,53 @@ def test_admin_can_access_detail(self):
self.assertEqual(resp.status_code, 200)
self.assertContains(resp, self.product.name)

def test_admin_can_create_product(self):
"""Prueba que un admin puede crear un nuevo producto (POST)."""
self.client.force_login(self.admin)

initial_count = Product.objects.count()

data = {
"name": "Nuevo Producto Creado",
"description": "Creado por el test de admin",
"category": "perfume",
"brand": "NewBrand",
"price": "99.99",
"stock": 100,
"is_active": True,
}
resp = self.client.post(self.create_url, data)
self.assertEqual(resp.status_code, 302)
self.assertEqual(Product.objects.count(), initial_count + 1)
self.assertTrue(Product.objects.filter(name="Nuevo Producto Creado").exists())

def test_admin_can_update_product(self):
"""Prueba que un admin puede actualizar un producto existente (POST)."""
self.client.force_login(self.admin)

updated_name = "Nombre Actualizado Admin"
updated_price = "15.50"

data = {
"name": updated_name,
"description": "Descripción actualizada",
"category": "tratamiento",
"brand": self.product.brand,
"price": updated_price,
"stock": 50,
"is_active": False,
}
resp = self.client.post(self.update_url, data)
self.assertEqual(resp.status_code, 302)

self.assertRedirects(resp, reverse("product_list"))

self.product.refresh_from_db()
self.assertEqual(self.product.name, updated_name)
self.assertEqual(self.product.price, Decimal(updated_price))
self.assertFalse(self.product.is_active)
self.assertEqual(self.product.stock, 50)

def test_admin_can_delete_product(self):
self.client.force_login(self.admin)
url = reverse("product_delete", args=[self.product.pk])
Expand Down
1 change: 0 additions & 1 deletion essenza/product/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ def get_top_selling_products(since):
filtered_query = query_with_totals.filter(total_quantity__gt=0)
# Paso 4: Ordenar (descendente).
ordered_query = filtered_query.order_by("-total_quantity")
# Paso 5: Limitar.
top_products = ordered_query[:10]
return top_products

Expand Down
2 changes: 1 addition & 1 deletion essenza/templates/product/confirm_delete.html
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
{% csrf_token %}
<div class="actions">
<button type="submit" class="btn-delete">Sí, borrar producto</button>
<a href="{% url 'product_detail' product.pk %}" class="btn-cancel">← No, cancelar</a>
<a href="{% url 'product_list' %}" class="btn-cancel">← No, cancelar</a>
</div>
</form>

Expand Down
8 changes: 2 additions & 6 deletions essenza/templates/product/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -165,20 +165,16 @@

/* CLAVE: Aplica FLEX al header para separar los grupos */
display: flex;
justify-content: space-between; /* Separa left-group del profile-dropdown */
justify-content: space-between;
align-items: center;

/* CLAVE: Añade padding a los lados para crear el margen visible */
padding: 14px 20px;
}

/* ELIMINAMOS .header-inner (ya no es necesario) */

/* NUEVO: Contenedor para agrupar (i + ESSENZA + Buscar) */
.left-group {
display: flex;
align-items: center;
gap: 15px; /* Espacio entre los elementos i, ESSENZA y Buscar... */
gap: 15px;
}

.info-button {
Expand Down