-
-
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.
- Loading branch information
Showing
5 changed files
with
85 additions
and
41 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
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,18 +1,15 @@ | ||
import graphene | ||
|
||
from api.models import RecordType | ||
from api.schema.RecordType import CreateRecordType, RecordTypeQL | ||
from api.schema.RecordTypeSchema import CreateRecordType, RecordTypeQL | ||
|
||
|
||
class Mutation(graphene.ObjectType): | ||
create_record_type = CreateRecordType.Field() | ||
|
||
|
||
class Query(graphene.ObjectType): | ||
record_types = graphene.List(RecordTypeQL, type=graphene.String()) | ||
all_record_type = graphene.List(RecordTypeQL) | ||
|
||
def resolve_record_types(self, info, **kwargs): | ||
_type = kwargs.get('type') | ||
if _type is not None: | ||
return RecordType.objects.filter(type__contains=_type) | ||
def resolve_all_record_type(self, info, **kwargs): | ||
return RecordType.objects.all() |
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,42 @@ | ||
# GraphQL Unittest | ||
|
||
### django-graphene unittest | ||
|
||
> Test failed | ||
```python | ||
from graphene_django.utils.testing import GraphQLTestCase | ||
|
||
class RecordTypeQLTestCase(GraphQLTestCase): | ||
def test_record_type_query(self): | ||
response = self.query( | ||
''' | ||
query { | ||
allRecordType{ | ||
id | ||
type | ||
} | ||
} | ||
''', | ||
) | ||
|
||
self.assertResponseNoErrors(response) | ||
self.assertEqual(response.status_code, 200) | ||
|
||
def test_record_type_mutation(self): | ||
response = self.query( | ||
''' | ||
mutation { | ||
createRecordType(recordTypeData: {type: "heartbeat"}) { | ||
success | ||
recordType { | ||
id | ||
type | ||
} | ||
} | ||
} | ||
''', | ||
) | ||
|
||
self.assertResponseNoErrors(response) | ||
``` |
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,39 +1,43 @@ | ||
from django.test import TestCase | ||
from graphene.test import Client | ||
from api import schema | ||
from api.models import RecordType | ||
|
||
|
||
class RecordTypeQueryTestCase(TestCase): | ||
def setUp(self): | ||
self.water_record_type = RecordType.objects.create(type="water") | ||
self.food_record_type = RecordType.objects.create(type="food") | ||
self.client = Client(schema) | ||
import logging | ||
|
||
def test_record_types_query(self): | ||
query = """ | ||
query { | ||
recordTypes(type: "water") { | ||
type | ||
} | ||
} | ||
""" | ||
|
||
response = self.client.execute(query) | ||
from django.test.utils import TestCase | ||
from graphene.test import Client | ||
from graphene_django.utils.testing import GraphQLTestCase | ||
from PetMonitoringSystemBackend.schema import schema | ||
|
||
self.assertEqual(response.status_code, 200) | ||
self.assertEqual(response.data['data']['recordTypes'][0]['type'], "water") | ||
logger = logging.getLogger(__name__) | ||
|
||
def test_record_types_query_all(self): | ||
query = """ | ||
query { | ||
recordTypes { | ||
type | ||
} | ||
} | ||
""" | ||
|
||
response = self.client.execute(query) | ||
class RecordTypeQLTestCase(GraphQLTestCase): | ||
def setUp(self) -> None: | ||
self.client = Client(schema) | ||
|
||
self.assertEqual(response.status_code, 200) | ||
self.assertEqual(len(response.data['data']['recordTypes']), 2) | ||
def test_record_type_query(self): | ||
executed = self.client.execute( | ||
''' | ||
query { | ||
allRecordType{ | ||
id | ||
type | ||
} | ||
} | ||
''', | ||
) | ||
self.assertIsNotNone(executed) | ||
|
||
def test_record_type_mutation(self): | ||
executed = self.client.execute( | ||
''' | ||
mutation { | ||
createRecordType(recordTypeData: {type: "heartbeat"}) { | ||
success | ||
recordType { | ||
id | ||
type | ||
} | ||
} | ||
} | ||
''', | ||
) | ||
|
||
self.assertIsNotNone(executed) |