Skip to content

Commit

Permalink
OP-2219: fixed validation tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sniedzielski committed Dec 10, 2024
1 parent 85ef666 commit fbe3e74
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
1 change: 0 additions & 1 deletion grievance_social_protection/gql_mutations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 16 additions & 12 deletions grievance_social_protection/tests/ticket_service_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from django.core.exceptions import ValidationError
from django.test import TestCase

from grievance_social_protection.models import Ticket
Expand Down Expand Up @@ -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 = {
Expand Down

0 comments on commit fbe3e74

Please sign in to comment.