From fbe3e74e2c5ca0ec1b55902bc69d23de77389fd8 Mon Sep 17 00:00:00 2001 From: sniedzielski Date: Tue, 10 Dec 2024 14:35:33 +0100 Subject: [PATCH] OP-2219: fixed validation tests --- grievance_social_protection/gql_mutations.py | 1 - .../tests/ticket_service_test.py | 28 +++++++++++-------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/grievance_social_protection/gql_mutations.py b/grievance_social_protection/gql_mutations.py index aaf43a0..fd56cd1 100644 --- a/grievance_social_protection/gql_mutations.py +++ b/grievance_social_protection/gql_mutations.py @@ -107,7 +107,6 @@ def _mutate(cls, user, **data): ticket_id = response['data']['id'] ticket = Ticket.objects.get(id=ticket_id) TicketMutation.object_mutated(user, client_mutation_id=client_mutation_id, ticket=ticket) - print(response) if not response['success']: return response return None diff --git a/grievance_social_protection/tests/ticket_service_test.py b/grievance_social_protection/tests/ticket_service_test.py index 694e226..e7b7def 100644 --- a/grievance_social_protection/tests/ticket_service_test.py +++ b/grievance_social_protection/tests/ticket_service_test.py @@ -1,3 +1,4 @@ +from django.core.exceptions import ValidationError from django.test import TestCase from grievance_social_protection.models import Ticket @@ -36,20 +37,23 @@ def test_add_ticket(self): self.assertEqual(query.count(), 1) def test_add_ticket_validation(self): - result = self.service.create(service_add_ticket_payload_bad_resolution) - self.assertFalse(result.get('success')) - self.assertEqual(result.get('detail'), - f"['{_('validations.CommentValidation.validate_resolution.invalid_format')}']") + with self.assertRaises(ValidationError) as context: + self.service.create(service_add_ticket_payload_bad_resolution) - result = self.service.create(service_add_ticket_payload_bad_resolution_day) - self.assertFalse(result.get('success')) - self.assertEqual(result.get('detail'), - f"['{_('validations.TicketValidation.validate_resolution.invalid_day_value')}']") + exception = context.exception + self.assertIn(_('validations.CommentValidation.validate_resolution.invalid_format'), str(exception)) - result = self.service.create(service_add_ticket_payload_bad_resolution_hour) - self.assertFalse(result.get('success')) - self.assertEqual(result.get('detail'), - f"['{_('validations.TicketValidation.validate_resolution.invalid_hour_value')}']") + with self.assertRaises(ValidationError) as context: + self.service.create(service_add_ticket_payload_bad_resolution_day) + + exception = context.exception + self.assertIn(_('validations.CommentValidation.validate_resolution.invalid_day_value'), str(exception)) + + with self.assertRaises(ValidationError) as context: + self.service.create(service_add_ticket_payload_bad_resolution_hour) + + exception = context.exception + self.assertIn(_('validations.CommentValidation.validate_resolution.invalid_hour_value'), str(exception)) def test_update_ticket(self): update_payload = {