jespern / django-piston (http://bitbucket.org/jespern/)
Piston is a Django mini-framework creating APIs.
Clone this repository (size: 470.9 KB): HTTPS / SSH
$ hg clone http://bitbucket.org/jespern/django-piston/
| commit 211: | ac9c7fe24cc4 |
| parent 210: | 1b139755d6f9 |
| branch: | default |
fixed tests
6 months ago
Changed (Δ164 bytes):
raw changeset »
piston/utils.py (8 lines added, 8 lines removed)
tests/test_project/apps/testapp/handlers.py (2 lines added, 2 lines removed)
tests/test_project/apps/testapp/tests.py (12 lines added, 10 lines removed)
Up to file-list piston/utils.py:
| … | … | @@ -217,15 +217,15 @@ class Mimer(object): |
217 |
217 |
if not self.is_multipart() and ctype: |
218 |
218 |
loadee = self.loader_for_type(ctype) |
219 |
219 |
|
220 |
if loadee: |
|
221 |
try: |
|
222 |
|
|
220 |
try: |
|
221 |
self.request.data = loadee(self.request.raw_post_data) |
|
223 |
222 |
|
224 |
# Reset both POST and PUT from request, as its |
|
225 |
# misleading having their presence around. |
|
226 |
self.request.POST = self.request.PUT = dict() |
|
227 |
except (TypeError, ValueError): |
|
228 |
|
|
223 |
# Reset both POST and PUT from request, as its |
|
224 |
# misleading having their presence around. |
|
225 |
self.request.POST = self.request.PUT = dict() |
|
226 |
except (TypeError, ValueError): |
|
227 |
# This also catches if loadee is None. |
|
228 |
raise MimerDataException |
|
229 |
229 |
|
230 |
230 |
return self.request |
231 |
231 |
Up to file-list tests/test_project/apps/testapp/handlers.py:
| … | … | @@ -38,7 +38,7 @@ class ExpressiveHandler(BaseHandler): |
38 |
38 |
return inst |
39 |
39 |
|
40 |
40 |
def create(self, request): |
41 |
if request.content_type |
|
41 |
if request.content_type and request.data: |
|
42 |
42 |
data = request.data |
43 |
43 |
|
44 |
44 |
em = self.model(title=data['title'], content=data['content']) |
| … | … | @@ -49,7 +49,7 @@ class ExpressiveHandler(BaseHandler): |
49 |
49 |
|
50 |
50 |
return rc.CREATED |
51 |
51 |
else: |
52 |
super(Expressive |
|
52 |
super(ExpressiveHandler, self).create(request) |
|
53 |
53 |
|
54 |
54 |
class AbstractHandler(BaseHandler): |
55 |
55 |
fields = ('id', 'some_other', 'some_field') |
Up to file-list tests/test_project/apps/testapp/tests.py:
| … | … | @@ -88,17 +88,19 @@ class OAuthTests(MainTests): |
88 |
88 |
|
89 |
89 |
# Response should be a redirect... |
90 |
90 |
self.assertEqual(302, response.status_code) |
91 |
self. |
|
91 |
self.failUnless(response['Location'].startswith("http://printer.example.com/request_token_ready?")) |
|
92 |
self.failUnless(('oauth_token='+oatoken.key in response['Location'])) |
|
93 |
||
94 |
# Actually we can't test this last part, since it's 1.0a. |
|
95 |
# Obtain access token... |
|
96 |
# request = oauth.OAuthRequest.from_consumer_and_token(oaconsumer, token=oatoken, |
|
97 |
# http_url='http://testserver/api/oauth/access_token') |
|
98 |
# request.sign_request(self.signature_method, oaconsumer, oatoken) |
|
99 |
# response = self.client.get('/api/oauth/access_token', request.parameters) |
|
92 |
100 |
|
93 |
# Obtain access token... |
|
94 |
request = oauth.OAuthRequest.from_consumer_and_token(oaconsumer, token=oatoken, |
|
95 |
http_url='http://testserver/api/oauth/access_token') |
|
96 |
request.sign_request(self.signature_method, oaconsumer, oatoken) |
|
97 |
response = self.client.get('/api/oauth/access_token', request.parameters) |
|
98 |
||
99 |
oa_atoken = oauth.OAuthToken.from_string(response.content) |
|
100 |
atoken = Token.objects.get(key=oa_atoken.key, token_type=Token.ACCESS) |
|
101 |
|
|
101 |
# oa_atoken = oauth.OAuthToken.from_string(response.content) |
|
102 |
# atoken = Token.objects.get(key=oa_atoken.key, token_type=Token.ACCESS) |
|
103 |
# self.assertEqual(atoken.secret, oa_atoken.secret) |
|
102 |
104 |
|
103 |
105 |
class BasicAuthTest(MainTests): |
104 |
106 |
