From 403f713257ad738c2ba24a06660049764a9f8223 Mon Sep 17 00:00:00 2001 From: Feliciano Date: Fri, 28 Jun 2024 18:45:58 -0300 Subject: [PATCH 1/2] Agrego el test unitario para validar que el campo telefono sea numerico --- app/tests_unit.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/app/tests_unit.py b/app/tests_unit.py index 9c6e34c1..10249976 100644 --- a/app/tests_unit.py +++ b/app/tests_unit.py @@ -274,6 +274,21 @@ def test_phone_number_without_54(self): self.assertIn("phone", errors) self.assertEqual(errors["phone"], "El telefono debe comenzar con 54") + def test_phone_number_with_a_letter(self): + """ + La funcion verifica que el campo solo tengo caracteres numericos + + """ + client_data = { + "name": "Juan Sebastian Veron", + "phone": "a2245556789", + "city": "La Plata", + "email": "brujita75@vetsoft.com", + } + errors = validate_client(client_data) + self.assertIn("phone", errors) + self.assertEqual(errors["phone"], "El teléfono solo debe contener números") + class MedicineModelTest(TestCase): """ Pruebas para el modelo Medicina. From 5ed6a4a190a77278413e99944895e6f009136ea8 Mon Sep 17 00:00:00 2001 From: Feliciano Date: Fri, 28 Jun 2024 19:10:48 -0300 Subject: [PATCH 2/2] Agrego el test e2e para validar el telefono del cliente --- functional_tests/tests.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/functional_tests/tests.py b/functional_tests/tests.py index 9414bdc9..36a9bddd 100644 --- a/functional_tests/tests.py +++ b/functional_tests/tests.py @@ -390,6 +390,29 @@ def test_should_show_error_for_phone_whitout_54(self): # Verifica si se muestra el mensaje de error esperado expect(self.page.get_by_text("El telefono debe comenzar con 54")).to_be_visible() +def test_should_show_error_for_phone_with_characters(self): + """ + Verifica que se muestre un mensaje de error al intentar crear un cliente con un teléfono no numérico. + """ + url = reverse('clients_form') + data = { + "name": "Guido Carrillo", + "phone": "aa54221232555", # Teléfono con caracteres no numéricos + "email": "goleador@vetsoft.com", + "city": "Berisso", + } + + response = self.client.post(url, data, follow=True) + + # Verificar que se ha mostrado el mensaje de error esperado en la respuesta + self.assertContains(response, "El teléfono solo debe contener números") + + # Verificar que no se ha creado un cliente en la base de datos + clients = Client.objects.filter(name="Guido Carrillo") + self.assertEqual(clients.count(), 0) + + # Verificar que estamos en la página correcta después del envío del formulario + self.assertTemplateUsed(response, 'clients_form.html') class MedicineCreateEditTestCase(PlaywrightTestCase): """