-
Notifications
You must be signed in to change notification settings - Fork 3
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 #1 from flavors/support-multiple-content-type
Support multiple content type for parse body
- Loading branch information
Showing
4 changed files
with
93 additions
and
11 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
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,44 @@ | ||
import json | ||
|
||
from django.test import RequestFactory, testcases | ||
|
||
from graphql_persist import parser | ||
|
||
|
||
class ParserTests(testcases.TestCase): | ||
|
||
def setUp(self): | ||
self.factory = RequestFactory() | ||
|
||
def test_application_json(self): | ||
request = self.factory.post( | ||
'/', | ||
data=json.dumps({'test': True}), | ||
content_type='application/json') | ||
|
||
result = parser.parse_body(request) | ||
self.assertTrue(result['test']) | ||
|
||
def test_json_decode_error(self): | ||
request = self.factory.post( | ||
'/', | ||
data='error', | ||
content_type='application/json') | ||
|
||
result = parser.parse_body(request) | ||
self.assertIsNone(result) | ||
|
||
def test_x_www_form_urlencoded(self): | ||
request = self.factory.post('/', data={'test': True}) | ||
result = parser.parse_body(request) | ||
|
||
self.assertTrue(eval(result['test'])) | ||
|
||
def test_unknown_content_type(self): | ||
request = self.factory.post( | ||
'/', | ||
data={'test': True}, | ||
content_type='unknown') | ||
|
||
result = parser.parse_body(request) | ||
self.assertIsNone(result) |