From fb3124246c16f87db7726a162079866a56997a13 Mon Sep 17 00:00:00 2001 From: Mono Mono Date: Sat, 13 Dec 2025 17:34:40 -0500 Subject: [PATCH] #29 refactor(Tests): extract to mixin class. --- tienda_ilusion/don_confiao/tests/test_admin_code.py | 10 +++------- tienda_ilusion/don_confiao/tests/test_api.py | 10 +++------- .../don_confiao/tests/test_customers_from_tryton.py | 10 +++------- .../tests/test_exportar_ventas_para_tryton.py | 10 +++------- .../don_confiao/tests/test_jar_reconciliation.py | 10 +++------- .../don_confiao/tests/test_payment_methods.py | 10 +++------- .../don_confiao/tests/test_products_from_tryton.py | 11 ++++------- .../don_confiao/tests/test_summary_view_purchase.py | 10 +++------- 8 files changed, 25 insertions(+), 56 deletions(-) diff --git a/tienda_ilusion/don_confiao/tests/test_admin_code.py b/tienda_ilusion/don_confiao/tests/test_admin_code.py index debab0a..10d1533 100644 --- a/tienda_ilusion/don_confiao/tests/test_admin_code.py +++ b/tienda_ilusion/don_confiao/tests/test_admin_code.py @@ -1,18 +1,14 @@ -from django.contrib.auth.models import User from django.test import TestCase from ..models import AdminCode +from .Mixins import LoginMixin import json -class TestAdminCode(TestCase): +class TestAdminCode(TestCase, LoginMixin): def setUp(self): - username = 'nombre_usuario' - password = 'contraseña' - email = 'correo@example.com' - self.user = User.objects.create_user(username, email, password) - self.client.login(username=username, password=password) + self.login() self.valid_code = 'some valid code' admin_code = AdminCode() diff --git a/tienda_ilusion/don_confiao/tests/test_api.py b/tienda_ilusion/don_confiao/tests/test_api.py index 06072ba..dcc6441 100644 --- a/tienda_ilusion/don_confiao/tests/test_api.py +++ b/tienda_ilusion/don_confiao/tests/test_api.py @@ -2,19 +2,15 @@ import json import csv import io -from django.contrib.auth.models import User from rest_framework import status from rest_framework.test import APITestCase from ..models import Sale, Product, Customer +from .Mixins import LoginMixin -class TestAPI(APITestCase): +class TestAPI(APITestCase, LoginMixin): def setUp(self): - username = 'nombre_usuario' - password = 'contraseña' - email = 'correo@example.com' - self.user = User.objects.create_user(username, email, password) - self.client.login(username=username, password=password) + self.login() self.product = Product.objects.create( name='Panela', diff --git a/tienda_ilusion/don_confiao/tests/test_customers_from_tryton.py b/tienda_ilusion/don_confiao/tests/test_customers_from_tryton.py index 5657467..6af2382 100644 --- a/tienda_ilusion/don_confiao/tests/test_customers_from_tryton.py +++ b/tienda_ilusion/don_confiao/tests/test_customers_from_tryton.py @@ -1,18 +1,14 @@ import json from unittest.mock import patch -from django.contrib.auth.models import User from django.test import TestCase from ..models import Customer +from .Mixins import LoginMixin -class TestCustomersFromTryton(TestCase): +class TestCustomersFromTryton(TestCase, LoginMixin): def setUp(self): - username = 'nombre_usuario' - password = 'contraseña' - email = 'correo@example.com' - self.user = User.objects.create_user(username, email, password) - self.client.login(username=username, password=password) + self.login() self.customer = Customer.objects.create( name='Calos', diff --git a/tienda_ilusion/don_confiao/tests/test_exportar_ventas_para_tryton.py b/tienda_ilusion/don_confiao/tests/test_exportar_ventas_para_tryton.py index eabb4ad..8ef8503 100644 --- a/tienda_ilusion/don_confiao/tests/test_exportar_ventas_para_tryton.py +++ b/tienda_ilusion/don_confiao/tests/test_exportar_ventas_para_tryton.py @@ -2,19 +2,15 @@ import csv import json from unittest.mock import patch -from django.contrib.auth.models import User from django.test import TestCase from ..models import Sale, SaleLine, Product, Customer +from .Mixins import LoginMixin -class TestExportarVentasParaTryton(TestCase): +class TestExportarVentasParaTryton(TestCase, LoginMixin): def setUp(self): - username = 'nombre_usuario' - password = 'contraseña' - email = 'correo@example.com' - self.user = User.objects.create_user(username, email, password) - self.client.login(username=username, password=password) + self.login() self.product = Product.objects.create( name='Panela', diff --git a/tienda_ilusion/don_confiao/tests/test_jar_reconciliation.py b/tienda_ilusion/don_confiao/tests/test_jar_reconciliation.py index e592f0b..7f1386c 100644 --- a/tienda_ilusion/don_confiao/tests/test_jar_reconciliation.py +++ b/tienda_ilusion/don_confiao/tests/test_jar_reconciliation.py @@ -1,18 +1,14 @@ -from django.contrib.auth.models import User from django.test import TestCase from django.core.exceptions import ValidationError from ..models import Sale, Product, SaleLine, Customer, ReconciliationJar +from .Mixins import LoginMixin import json -class TestJarReconcliation(TestCase): +class TestJarReconcliation(TestCase, LoginMixin): def setUp(self): - username = 'nombre_usuario' - password = 'contraseña' - email = 'correo@example.com' - self.user = User.objects.create_user(username, email, password) - self.client.login(username=username, password=password) + self.login() customer = Customer() customer.name = 'Alejo Mono' diff --git a/tienda_ilusion/don_confiao/tests/test_payment_methods.py b/tienda_ilusion/don_confiao/tests/test_payment_methods.py index 58f49cc..6d38a12 100644 --- a/tienda_ilusion/don_confiao/tests/test_payment_methods.py +++ b/tienda_ilusion/don_confiao/tests/test_payment_methods.py @@ -1,14 +1,10 @@ -from django.contrib.auth.models import User from django.test import TestCase +from .Mixins import LoginMixin -class TestPaymentMethods(TestCase): +class TestPaymentMethods(TestCase, LoginMixin): def setUp(self): - username = 'nombre_usuario' - password = 'contraseña' - email = 'correo@example.com' - self.user = User.objects.create_user(username, email, password) - self.client.login(username=username, password=password) + self.login() def test_keys_in_payment_methods_to_select(self): response = self.client.get( diff --git a/tienda_ilusion/don_confiao/tests/test_products_from_tryton.py b/tienda_ilusion/don_confiao/tests/test_products_from_tryton.py index 3b80472..52a80ab 100644 --- a/tienda_ilusion/don_confiao/tests/test_products_from_tryton.py +++ b/tienda_ilusion/don_confiao/tests/test_products_from_tryton.py @@ -2,18 +2,15 @@ import json from decimal import Decimal from unittest.mock import patch -from django.contrib.auth.models import User from django.test import TestCase from ..models import Product +from .Mixins import LoginMixin -class TestProductsFromTryton(TestCase): +class TestProductsFromTryton(TestCase, LoginMixin): def setUp(self): - username = 'nombre_usuario' - password = 'contraseña' - email = 'correo@example.com' - self.user = User.objects.create_user(username, email, password) - self.client.login(username=username, password=password) + self.login() + self.product = Product.objects.create( name='Panela', price=5000, diff --git a/tienda_ilusion/don_confiao/tests/test_summary_view_purchase.py b/tienda_ilusion/don_confiao/tests/test_summary_view_purchase.py index 47156b2..63e3cd6 100644 --- a/tienda_ilusion/don_confiao/tests/test_summary_view_purchase.py +++ b/tienda_ilusion/don_confiao/tests/test_summary_view_purchase.py @@ -1,15 +1,11 @@ -from django.contrib.auth.models import User from django.test import TestCase from ..models import Sale, Product, SaleLine, Customer +from .Mixins import LoginMixin -class TestSummaryViewPurchase(TestCase): +class TestSummaryViewPurchase(TestCase, LoginMixin): def setUp(self): - username = 'nombre_usuario' - password = 'contraseña' - email = 'correo@example.com' - self.user = User.objects.create_user(username, email, password) - self.client.login(username=username, password=password) + self.login() customer = Customer() customer.name = 'Alejo Mono'