forked from openimis/openimis-be-grievance_py
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OP-2219: added tests for gql mutations
- Loading branch information
1 parent
8382a8d
commit c6b85d8
Showing
4 changed files
with
306 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
gql_mutation_create_ticket = """ | ||
mutation createTicket { | ||
createTicket(input: { | ||
category: "%s", | ||
title: "%s", | ||
resolution: "%s", | ||
priority: "%s", | ||
dateOfIncident: "%s", | ||
channel: "%s", | ||
flags: "%s", | ||
clientMutationId: "%s" | ||
}) { | ||
clientMutationId | ||
} | ||
} | ||
""" | ||
|
||
|
||
gql_mutation_update_ticket = """ | ||
mutation updateTicket { | ||
updateTicket(input: { | ||
id: "%s", | ||
category: "%s", | ||
title: "%s", | ||
resolution: "%s", | ||
priority: "%s", | ||
dateOfIncident: "%s", | ||
channel: "%s", | ||
flags: "%s", | ||
status: %s, | ||
clientMutationId: "%s" | ||
}) { | ||
clientMutationId | ||
} | ||
} | ||
""" |
129 changes: 129 additions & 0 deletions
129
grievance_social_protection/tests/test_gql_ticket_create.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
from django.test import TestCase | ||
from core.models import MutationLog | ||
from graphene import Schema | ||
from graphene.test import Client | ||
from core.test_helpers import create_test_interactive_user | ||
from grievance_social_protection.models import Ticket | ||
from grievance_social_protection.schema import Query, Mutation | ||
from grievance_social_protection.tests.gql_payloads import gql_mutation_create_ticket | ||
|
||
|
||
class GQLTicketCreateTestCase(TestCase): | ||
class GQLContext: | ||
def __init__(self, user): | ||
self.user = user | ||
|
||
user = None | ||
eu = None | ||
|
||
category = None | ||
title = None | ||
resolution = None | ||
priority = None | ||
dateOfIncident = None | ||
channel = None | ||
flags = None | ||
|
||
@classmethod | ||
def setUpClass(cls): | ||
super(GQLTicketCreateTestCase, cls).setUpClass() | ||
cls.user = create_test_interactive_user(username='user_authorized', roles=[7]) | ||
|
||
gql_schema = Schema( | ||
query=Query, | ||
mutation=Mutation | ||
) | ||
|
||
cls.category = "Default" | ||
cls.title = "TestMutationCreate" | ||
cls.resolution = "2,5" | ||
cls.priority = "Medium" | ||
cls.date_of_incident = "2024-11-20" | ||
cls.channel = "Channel A" | ||
cls.flags = "Default" | ||
|
||
cls.gql_client = Client(gql_schema) | ||
cls.gql_context = cls.GQLContext(cls.user) | ||
|
||
def test_create_ticket_success(self): | ||
mutation_id = "99g453h5g92h04gh88" | ||
payload = gql_mutation_create_ticket % ( | ||
self.category, | ||
self.title, | ||
self.resolution, | ||
self.gender_id, | ||
self.date_of_incident, | ||
self.channel, | ||
self.flags, | ||
mutation_id | ||
) | ||
|
||
_ = self.gql_client.execute(payload, context=self.gql_context) | ||
mutation_log = MutationLog.objects.get(client_mutation_id=mutation_id) | ||
self.assertFalse(mutation_log.error) | ||
tickets = Ticket.objects.filter(title=self.title) | ||
self.assertEquals(tickets.count(), 1) | ||
ticket = tickets.first() | ||
self.assertEquals(ticket.title, self.title) | ||
self.assertEquals(ticket.category, self.category) | ||
self.assertEquals(ticket.resolution, self.resolution) | ||
self.assertEquals(ticket.priority, self.priority) | ||
self.assertEquals(ticket.date_of_incident, self.date_of_incident) | ||
self.assertEquals(ticket.flags, self.flags) | ||
|
||
def test_create_ticket_false_invalid_resolution_format(self): | ||
mutation_id = "65g453h4g92h04gh98" | ||
payload = gql_mutation_create_ticket % ( | ||
self.category, | ||
self.title, | ||
"kjdslkdjslk", | ||
self.gender_id, | ||
self.date_of_incident, | ||
self.channel, | ||
self.flags, | ||
mutation_id | ||
) | ||
|
||
_ = self.gql_client.execute(payload, context=self.gql_context) | ||
mutation_log = MutationLog.objects.get(client_mutation_id=mutation_id) | ||
self.assertTrue(mutation_log.error) | ||
tickets = Ticket.objects.filter(title=self.title) | ||
self.assertEquals(tickets.count(), 0) | ||
|
||
def test_create_ticket_false_invalid_resolution_day_format(self): | ||
mutation_id = "62g453h4g92h04gh90" | ||
payload = gql_mutation_create_ticket % ( | ||
self.category, | ||
self.title, | ||
"99,3", | ||
self.gender_id, | ||
self.date_of_incident, | ||
self.channel, | ||
self.flags, | ||
mutation_id | ||
) | ||
|
||
_ = self.gql_client.execute(payload, context=self.gql_context) | ||
mutation_log = MutationLog.objects.get(client_mutation_id=mutation_id) | ||
self.assertTrue(mutation_log.error) | ||
tickets = Ticket.objects.filter(title=self.title) | ||
self.assertEquals(tickets.count(), 0) | ||
|
||
def test_create_ticket_false_invalid_resolution_hour_format(self): | ||
mutation_id = "15g453h4g92h04gh92" | ||
payload = gql_mutation_create_ticket % ( | ||
self.category, | ||
self.title, | ||
"4,66", | ||
self.gender_id, | ||
self.date_of_incident, | ||
self.channel, | ||
self.flags, | ||
mutation_id | ||
) | ||
|
||
_ = self.gql_client.execute(payload, context=self.gql_context) | ||
mutation_log = MutationLog.objects.get(client_mutation_id=mutation_id) | ||
self.assertTrue(mutation_log.error) | ||
tickets = Ticket.objects.filter(title=self.title) | ||
self.assertEquals(tickets.count(), 0) |
140 changes: 140 additions & 0 deletions
140
grievance_social_protection/tests/test_gql_ticket_update.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
from django.test import TestCase | ||
from core.models import MutationLog | ||
from graphene import Schema | ||
from graphene.test import Client | ||
from core.test_helpers import create_test_interactive_user | ||
from grievance_social_protection.models import Ticket | ||
from grievance_social_protection.schema import Query, Mutation | ||
from grievance_social_protection.tests.gql_payloads import gql_mutation_update_ticket | ||
from grievance_social_protection.tests.test_helpers import create_ticket | ||
|
||
|
||
class GQLTicketUpdateTestCase(TestCase): | ||
class GQLContext: | ||
def __init__(self, user): | ||
self.user = user | ||
|
||
user = None | ||
eu = None | ||
|
||
category = None | ||
title = None | ||
resolution = None | ||
priority = None | ||
dateOfIncident = None | ||
channel = None | ||
flags = None | ||
status = None | ||
|
||
@classmethod | ||
def setUpClass(cls): | ||
super(GQLTicketUpdateTestCase, cls).setUpClass() | ||
cls.user = create_test_interactive_user(username='user_authorized', roles=[7]) | ||
cls.existing_ticket = create_ticket(cls.user.username) | ||
|
||
gql_schema = Schema( | ||
query=Query, | ||
mutation=Mutation | ||
) | ||
|
||
cls.category = "Default" | ||
cls.title = "TestMutationUpdate" | ||
cls.resolution = "2,5" | ||
cls.priority = "Medium" | ||
cls.date_of_incident = "2024-11-20" | ||
cls.channel = "Channel A" | ||
cls.flags = "Default" | ||
cls.status = "OPEN" | ||
|
||
cls.gql_client = Client(gql_schema) | ||
cls.gql_context = cls.GQLContext(cls.user) | ||
|
||
def test_update_ticket_success(self): | ||
mutation_id = "99g453h5g92h04xc66" | ||
payload = gql_mutation_update_ticket % ( | ||
self.existing_ticket.id, | ||
self.category, | ||
self.title, | ||
self.resolution, | ||
self.gender_id, | ||
self.date_of_incident, | ||
self.channel, | ||
self.flags, | ||
self.status, | ||
mutation_id | ||
) | ||
|
||
_ = self.gql_client.execute(payload, context=self.gql_context) | ||
mutation_log = MutationLog.objects.get(client_mutation_id=mutation_id) | ||
self.assertFalse(mutation_log.error) | ||
ticket = Ticket.objects.get(id=self.existing_ticket.id) | ||
self.assertEquals(ticket.title, self.title) | ||
self.assertEquals(ticket.category, self.category) | ||
self.assertEquals(ticket.resolution, self.resolution) | ||
self.assertEquals(ticket.priority, self.priority) | ||
self.assertEquals(ticket.date_of_incident, self.date_of_incident) | ||
self.assertEquals(ticket.flags, self.flags) | ||
self.assertEquals(ticket.status, self.status) | ||
|
||
def test_update_ticket_false_invalid_resolution_format(self): | ||
mutation_id = "65g453h4g92h04yf43" | ||
payload = gql_mutation_update_ticket % ( | ||
self.existing_ticket.id, | ||
self.category, | ||
self.title, | ||
"kjdslkdjslk", | ||
self.gender_id, | ||
self.date_of_incident, | ||
self.channel, | ||
self.flags, | ||
self.status, | ||
mutation_id | ||
) | ||
|
||
_ = self.gql_client.execute(payload, context=self.gql_context) | ||
mutation_log = MutationLog.objects.get(client_mutation_id=mutation_id) | ||
self.assertTrue(mutation_log.error) | ||
ticket = Ticket.objects.get(id=self.existing_ticket.id) | ||
self.assertNotEquals(ticket.title, self.title) | ||
|
||
def test_update_ticket_false_invalid_resolution_day_format(self): | ||
mutation_id = "65g453h4g92h0zx54" | ||
payload = gql_mutation_update_ticket % ( | ||
self.existing_ticket.id, | ||
self.category, | ||
self.title, | ||
"99,3", | ||
self.gender_id, | ||
self.date_of_incident, | ||
self.channel, | ||
self.flags, | ||
self.status, | ||
mutation_id | ||
) | ||
|
||
_ = self.gql_client.execute(payload, context=self.gql_context) | ||
mutation_log = MutationLog.objects.get(client_mutation_id=mutation_id) | ||
self.assertTrue(mutation_log.error) | ||
ticket = Ticket.objects.get(id=self.existing_ticket.id) | ||
self.assertNotEquals(ticket.title, self.title) | ||
|
||
def test_update_ticket_false_invalid_resolution_hour_format(self): | ||
mutation_id = "65g453h4g92h04wl32" | ||
payload = gql_mutation_update_ticket % ( | ||
self.existing_ticket.id, | ||
self.category, | ||
self.title, | ||
"4,66", | ||
self.gender_id, | ||
self.date_of_incident, | ||
self.channel, | ||
self.flags, | ||
self.status, | ||
mutation_id | ||
) | ||
|
||
_ = self.gql_client.execute(payload, context=self.gql_context) | ||
mutation_log = MutationLog.objects.get(client_mutation_id=mutation_id) | ||
self.assertTrue(mutation_log.error) | ||
ticket = Ticket.objects.get(id=self.existing_ticket.id) | ||
self.assertNotEquals(ticket.title, self.title) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters