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-2220: added tests for gql comments
- Loading branch information
1 parent
e1144b0
commit ac2e42d
Showing
6 changed files
with
203 additions
and
3 deletions.
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
97 changes: 97 additions & 0 deletions
97
grievance_social_protection/tests/test_gql_ticket_comment_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,97 @@ | ||
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 individual.models import Individual | ||
from individual.tests.data import ( | ||
service_add_individual_payload, | ||
service_group_individual_payload | ||
) | ||
from grievance_social_protection.models import Comment | ||
from grievance_social_protection.schema import Query, Mutation | ||
from grievance_social_protection.tests.gql_payloads import ( | ||
gql_mutation_create_comment, | ||
gql_mutation_create_comment_anonymous_user | ||
) | ||
from grievance_social_protection.tests.test_helpers import create_ticket | ||
|
||
|
||
class GQLTicketCommentCreateTestCase(TestCase): | ||
class GQLContext: | ||
def __init__(self, user): | ||
self.user = user | ||
|
||
user = None | ||
|
||
comment = None | ||
individual = None | ||
type = None | ||
existing_ticket = None | ||
|
||
@classmethod | ||
def setUpClass(cls): | ||
super(GQLTicketCommentCreateTestCase, 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.comment = "This is an awesome test comment!" | ||
cls.individual = cls.__create_individual() | ||
cls.type = "individual" | ||
|
||
cls.gql_client = Client(gql_schema) | ||
cls.gql_context = cls.GQLContext(cls.user) | ||
|
||
def test_create_comment_individual_success(self): | ||
mutation_id = "99g453h5g92h22xc33" | ||
payload = gql_mutation_create_comment % ( | ||
self.comment, | ||
self.existing_ticket.id, | ||
self.individual.id, | ||
self.type, | ||
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) | ||
comment = Comment.objects.get(id=self.existing_ticket.id) | ||
self.assertEquals(comment.ticket.id, self.existing_ticket.id) | ||
self.assertEquals(comment.comment, self.comment) | ||
self.assertEquals(comment.commenter_id, self.individual.id) | ||
self.assertEquals(comment.is_resolution, False) | ||
self.assertEquals(str(comment.commenter_type), self.type) | ||
|
||
def test_create_comment_anonymous_user_success(self): | ||
mutation_id = "99g453h5g92h04ww98" | ||
payload = gql_mutation_create_comment_anonymous_user % ( | ||
self.comment, | ||
self.existing_ticket.id, | ||
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) | ||
comment = Comment.objects.get(id=self.existing_ticket.id) | ||
self.assertEquals(comment.ticket.id, self.existing_ticket.id) | ||
self.assertEquals(comment.comment, self.comment) | ||
self.assertEquals(comment.commenter_id, None) | ||
self.assertEquals(comment.is_resolution, False) | ||
self.assertEquals(str(comment.commenter_type), None) | ||
|
||
@classmethod | ||
def __create_individual(cls): | ||
object_data = { | ||
**service_add_individual_payload | ||
} | ||
|
||
individual = Individual(**object_data) | ||
individual.save(username=cls.user.username) | ||
|
||
return individual |
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 |
---|---|---|
|
@@ -14,7 +14,6 @@ def __init__(self, user): | |
self.user = user | ||
|
||
user = None | ||
eu = None | ||
|
||
category = None | ||
title = None | ||
|
51 changes: 51 additions & 0 deletions
51
grievance_social_protection/tests/test_gql_ticket_resolve_by_comment.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,51 @@ | ||
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.schema import Query, Mutation | ||
from grievance_social_protection.tests.gql_payloads import gql_mutation_resolve_ticket_by_comment | ||
from grievance_social_protection.tests.test_helpers import ( | ||
create_ticket, | ||
create_comment_for_existing_ticket | ||
) | ||
|
||
|
||
class GQLTicketResolveByCommentTestCase(TestCase): | ||
class GQLContext: | ||
def __init__(self, user): | ||
self.user = user | ||
|
||
user = None | ||
|
||
existing_ticket = None | ||
existing_comment = None | ||
status = "CLOSED" | ||
|
||
@classmethod | ||
def setUpClass(cls): | ||
super(GQLTicketResolveByCommentTestCase, cls).setUpClass() | ||
cls.user = create_test_interactive_user(username='user_authorized', roles=[7]) | ||
cls.existing_ticket = create_ticket(cls.user.username) | ||
cls.existing_comment = create_comment_for_existing_ticket(cls.user, cls.existing_ticket) | ||
|
||
gql_schema = Schema( | ||
query=Query, | ||
mutation=Mutation | ||
) | ||
|
||
cls.gql_client = Client(gql_schema) | ||
cls.gql_context = cls.GQLContext(cls.user) | ||
|
||
def test_resolve_ticket_by_comment_success(self): | ||
mutation_id = "99g154h5b92h11sd33" | ||
payload = gql_mutation_resolve_ticket_by_comment % ( | ||
self.comment.id, | ||
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) | ||
self.assertEquals(self.existing_comment.is_resolution, True) | ||
self.assertEquals(self.existing_ticket.status, self.status) |
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
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 |
---|---|---|
@@ -1,8 +1,21 @@ | ||
from grievance_social_protection.models import Ticket | ||
from grievance_social_protection.models import ( | ||
Comment, | ||
Ticket | ||
) | ||
from grievance_social_protection.tests.data import service_add_ticket_payload | ||
|
||
|
||
def create_ticket(username): | ||
ticket = Ticket(**service_add_ticket_payload) | ||
ticket.save(username=username) | ||
return ticket | ||
|
||
|
||
def create_comment_for_existing_ticket(user, ticket): | ||
ticket.save(user=user) | ||
comment = Comment({ | ||
"ticket_id": ticket.id, | ||
"comment": "awesome comment" | ||
}) | ||
comment.save(user=user) | ||
return comment |