-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1445 from the-deep/features/organization-rest-to-…
…graphql Create graphql node for creating new organization
- Loading branch information
Showing
5 changed files
with
103 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,31 @@ | ||
import graphene | ||
from organization.schema import OrganizationType | ||
from organization.serializers import OrganizationGqSerializer | ||
|
||
from utils.graphene.mutation import ( | ||
generate_input_type_for_serializer, | ||
GrapheneMutation | ||
) | ||
|
||
from .models import Organization | ||
|
||
OrganizationInputType = generate_input_type_for_serializer( | ||
'OrganizationInputType', | ||
serializer_class=OrganizationGqSerializer, | ||
) | ||
|
||
|
||
class OrganizationCreate(GrapheneMutation): | ||
class Arguments: | ||
data = OrganizationInputType(required=True) | ||
model = Organization | ||
result = graphene.Field(OrganizationType) | ||
serializer_class = OrganizationGqSerializer | ||
|
||
@classmethod | ||
def check_permissions(cls, info, **kwargs): | ||
return True # global permission is always True | ||
|
||
|
||
class Mutation(): | ||
organization_create = OrganizationCreate.Field() |
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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from user.factories import UserFactory | ||
from utils.graphene.tests import GraphQLTestCase | ||
|
||
|
||
class TestOrganizationMutation(GraphQLTestCase): | ||
def test_orgainization_query(self): | ||
self.organization_query = ''' | ||
mutation MyMutation ($input : OrganizationInputType!) | ||
{ | ||
organizationCreate(data: $input){ | ||
errors | ||
ok | ||
result{ | ||
id | ||
longName | ||
shortName | ||
title | ||
url | ||
verified | ||
} | ||
} | ||
} | ||
''' | ||
|
||
user = UserFactory.create() | ||
minput = dict( | ||
title="Test Organization", | ||
shortName="Short Name", | ||
longName="This is long name" | ||
) | ||
|
||
def _query_check(minput, **kwargs): | ||
return self.query_check( | ||
self.organization_query, | ||
minput=minput, | ||
**kwargs | ||
) | ||
# without login | ||
_query_check(minput, assert_for_error=True) | ||
|
||
# with login | ||
|
||
self.force_login(user) | ||
|
||
content = _query_check(minput) | ||
self.assertEqual(content['data']['organizationCreate']['errors'], None) | ||
self.assertEqual(content['data']['organizationCreate']['result']['title'], 'Test Organization') | ||
self.assertEqual(content['data']['organizationCreate']['result']['verified'], False) |
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