test: move to tests folder.
This commit is contained in:
		
							
								
								
									
										88
									
								
								tienda_ilusion/don_confiao/tests/test_billing.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										88
									
								
								tienda_ilusion/don_confiao/tests/test_billing.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,88 @@ | ||||
| from django.test import TestCase | ||||
| from django.core.exceptions import ValidationError | ||||
| from ..models import Payment, ReconciliationJar | ||||
|  | ||||
|  | ||||
| class TestBilling(TestCase): | ||||
|  | ||||
|     def test_reconciliation_jar_summary(self): | ||||
|         cash_payment1, cash_payment2 = self._create_two_cash_payments() | ||||
|         jar_summary = Payment.get_reconciliation_jar_summary() | ||||
|         self.assertEqual(164000, jar_summary.total) | ||||
|         self.assertSetEqual( | ||||
|             {cash_payment1, cash_payment2}, | ||||
|             set(jar_summary.payments) | ||||
|         ) | ||||
|  | ||||
|     def test_reconciliation_jar_summary_use_only_cash(self): | ||||
|         cash_payment1, cash_payment2 = self._create_two_cash_payments() | ||||
|  | ||||
|         confiar_payment = Payment() | ||||
|         confiar_payment.date_time = '2024-07-07 16:00:00' | ||||
|         confiar_payment.type_payment = 'CONFIAR' | ||||
|         confiar_payment.amount = 85000 | ||||
|         confiar_payment.save() | ||||
|  | ||||
|         bancolombia_payment = Payment() | ||||
|         bancolombia_payment.date_time = '2024-07-07 12:30:00' | ||||
|         bancolombia_payment.type_payment = 'BANCOLOMBIA' | ||||
|         bancolombia_payment.amount = 12000 | ||||
|         bancolombia_payment.save() | ||||
|  | ||||
|         jar_summary = Payment.get_reconciliation_jar_summary() | ||||
|         self.assertEqual(164000, jar_summary.total) | ||||
|         self.assertSetEqual( | ||||
|             {cash_payment1, cash_payment2}, | ||||
|             set(jar_summary.payments) | ||||
|         ) | ||||
|  | ||||
|     def test_fail_validate_reconciliation_jar_with_discrepancy_values(self): | ||||
|         cash_payment1, cash_payment2 = self._create_two_cash_payments() | ||||
|  | ||||
|         jar_summary = Payment.get_reconciliation_jar_summary() | ||||
|  | ||||
|         reconciliation_jar = ReconciliationJar() | ||||
|         reconciliation_jar.date_time = '2024-07-13 13:02:00' | ||||
|         reconciliation_jar.description = "test reconcialiation jar" | ||||
|         reconciliation_jar.reconcilier = 'Jorge' | ||||
|         reconciliation_jar.cash_float = 0 | ||||
|         reconciliation_jar.cash_taken = 0 | ||||
|         reconciliation_jar.cash_discrepancy = 0 | ||||
|         reconciliation_jar.save() | ||||
|  | ||||
|         reconciliation_jar.add_payments(jar_summary.payments) | ||||
|         with self.assertRaises(ValidationError): | ||||
|             reconciliation_jar.clean() | ||||
|  | ||||
|     def test_validate_reconciliation_jar_with_cash_float(self): | ||||
|         cash_payment1, cash_payment2 = self._create_two_cash_payments() | ||||
|         jar_summary = Payment.get_reconciliation_jar_summary() | ||||
|  | ||||
|         reconciliation_jar = ReconciliationJar() | ||||
|         reconciliation_jar.date_time = '2024-07-13 13:02:00' | ||||
|         reconciliation_jar.description = "test reconcialiation jar" | ||||
|         reconciliation_jar.reconcilier = 'Jorge' | ||||
|         reconciliation_jar.cash_taken = jar_summary.total | ||||
|         reconciliation_jar.cash_discrepancy = 0 | ||||
|         reconciliation_jar.save() | ||||
|  | ||||
|         reconciliation_jar.add_payments(jar_summary.payments) | ||||
|         reconciliation_jar.clean() | ||||
|         reconciliation_jar.save() | ||||
|         self.assertTrue(reconciliation_jar.is_valid) | ||||
|  | ||||
|     def _create_two_cash_payments(self): | ||||
|         cash_payment1 = Payment() | ||||
|         cash_payment1.date_time = '2024-07-07 12:00:00' | ||||
|         cash_payment1.type_payment = 'CASH' | ||||
|         cash_payment1.amount = 132000 | ||||
|         cash_payment1.description = 'Saldo en compra' | ||||
|         cash_payment1.save() | ||||
|  | ||||
|         cash_payment2 = Payment() | ||||
|         cash_payment2.date_time = '2024-07-07 13:05:00' | ||||
|         cash_payment2.type_payment = 'CASH' | ||||
|         cash_payment2.amount = 32000 | ||||
|         cash_payment2.save() | ||||
|  | ||||
|         return [cash_payment1, cash_payment2] | ||||
| @@ -0,0 +1,45 @@ | ||||
| from django.test import Client, TestCase | ||||
| from django.contrib.auth.models import AnonymousUser, User | ||||
|  | ||||
| from ..models import Payment | ||||
|  | ||||
|  | ||||
| class TestReconciliationJarClient(TestCase): | ||||
|     def setUp(self): | ||||
|         self.client = Client() | ||||
|  | ||||
|     def test_get_summary_info_on_view(self): | ||||
|         self._generate_two_cash_payments() | ||||
|         response = self.client.get("/don_confiao/cuadrar_tarro") | ||||
|         self.assertEqual(response.status_code, 200) | ||||
|         self.assertEqual(response.context["summary"].total, 160000) | ||||
|         self.assertIn('160000', response.content.decode('utf-8')) | ||||
|  | ||||
|     def test_create_reconciliation_jar(self): | ||||
|         self._generate_two_cash_payments() | ||||
|         response = self.client.post( | ||||
|             "/don_confiao/cuadrar_tarro", | ||||
|             { | ||||
|                 "date_time": "2024-07-20T00:00", | ||||
|                 "description": "Cuadre de prueba", | ||||
|                 "reconcilier": "Jorge", | ||||
|                 "cash_taken": "100000", | ||||
|                 "cash_discrepancy": "60000", | ||||
|             } | ||||
|         ) | ||||
|         self.assertRedirects(response, '/don_confiao/cuadres') | ||||
|  | ||||
|  | ||||
|     def _generate_two_cash_payments(self): | ||||
|         cash_payment1 = Payment() | ||||
|         cash_payment1.date_time = '2024-07-07 12:00:00' | ||||
|         cash_payment1.type_payment = 'CASH' | ||||
|         cash_payment1.amount = 130000 | ||||
|         cash_payment1.description = 'Saldo en compra' | ||||
|         cash_payment1.save() | ||||
|  | ||||
|         cash_payment2 = Payment() | ||||
|         cash_payment2.date_time = '2024-07-07 13:05:00' | ||||
|         cash_payment2.type_payment = 'CASH' | ||||
|         cash_payment2.amount = 30000 | ||||
|         cash_payment2.save() | ||||
		Reference in New Issue
	
	Block a user