Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Clean-up to get the alphanumeric tests fixed. v0.8.3

  • Loading branch information...
commit 08e40e467d8bb3b75e21ebc41cebc218d76a5854 1 parent 6ede26f
@toastdriven toastdriven authored
View
1  AUTHORS
@@ -9,6 +9,7 @@ Contributors:
* mdornseif for various patches
* Jeff Triplett (jefftriplett) for various reports/patches.
+* Christian Klein (cklein) for the work on alphanumeric PK support.
Thanks to Tav for providing validate_jsonp.py, placed in public domain.
View
4 docs/conf.py
@@ -45,9 +45,9 @@
# built documents.
#
# The short X.Y version.
-version = '0.8.2'
+version = '0.8.3'
# The full version, including alpha/beta/rc tags.
-release = '0.8.2-beta'
+release = '0.8.3-beta'
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
View
2  setup.py
@@ -4,7 +4,7 @@
setup(
name='django-tastypie',
- version='0.8.2',
+ version='0.8.3',
description='A flexible & capable API layer for Django.',
author='Daniel Lindsley',
author_email='daniel@toastdriven.com',
View
2  tastypie/__init__.py
@@ -1,2 +1,2 @@
__author__ = 'Daniel Lindsley, Cody Soyland, Matt Croydon'
-__version__ = (0, 8, 2)
+__version__ = (0, 8, 3)
View
11 tastypie/resources.py
@@ -1182,7 +1182,11 @@ def obj_get_list(self, filters=None, **kwargs):
the query.
"""
applicable_filters = self.build_filters(filters)
- return self._meta.queryset.filter(**applicable_filters)
+
+ try:
+ return self._meta.queryset.filter(**applicable_filters)
+ except ValueError, e:
+ raise NotFound("Invalid resource lookup data provided (mismatched type).")
def obj_get(self, **kwargs):
"""
@@ -1191,7 +1195,10 @@ def obj_get(self, **kwargs):
Takes optional ``kwargs``, which are used to narrow the query to find
the instance.
"""
- return self._meta.queryset.get(**kwargs)
+ try:
+ return self._meta.queryset.get(**kwargs)
+ except ValueError, e:
+ raise NotFound("Invalid resource lookup data provided (mismatched type).")
def obj_create(self, bundle, **kwargs):
"""
View
3  tests/alphanumeric/api/resources.py
@@ -1,10 +1,11 @@
+from tastypie.authorization import Authorization
from tastypie.fields import CharField
from tastypie.resources import ModelResource
from alphanumeric.models import Product
class ProductResource(ModelResource):
-
class Meta:
resource_name = 'products'
queryset = Product.objects.all()
+ authorization = Authorization()
View
22 tests/alphanumeric/tests/views.py
@@ -17,8 +17,6 @@ def test_gets(self):
resp = self.client.get('/api/v1/products/', data={'format': 'json'})
self.assertEqual(resp.status_code, 200)
deserialized = json.loads(resp.content)
- #import pprint
- #pprint.pprint(deserialized)
self.assertEqual(len(deserialized), 2)
self.assertEqual(deserialized['meta']['limit'], 20)
self.assertEqual(len(deserialized['objects']), 6)
@@ -30,7 +28,7 @@ def test_gets(self):
deserialized = json.loads(resp.content)
self.assertEqual(len(deserialized), 5)
self.assertEqual(deserialized['name'], u'Skateboardrampe')
-
+
resp = self.client.get('/api/v1/products/set/11111;76123/', data={'format': 'json'})
self.assertEqual(resp.status_code, 200)
deserialized = json.loads(resp.content)
@@ -65,7 +63,7 @@ def test_gets(self):
self.assertEqual(len(deserialized), 1)
self.assertEqual(len(deserialized['objects']), 2)
self.assertEqual([obj['name'] for obj in deserialized['objects']], [u'Bigwheel', u'Laufrad'])
-
+
resp = self.client.get('/api/v1/products/WS65150/01-01/', data={'format': 'json'})
self.assertEqual(resp.status_code, 200)
deserialized = json.loads(resp.content)
@@ -87,14 +85,14 @@ def test_posts(self):
resp = self.client.post('/api/v1/products/', data=post_data, content_type='application/json')
self.assertEqual(resp.status_code, 201)
self.assertEqual(resp['location'], 'http://testserver/api/v1/products/12345/')
-
+
# make sure posted object exists
resp = self.client.get('/api/v1/products/12345/', data={'format': 'json'})
self.assertEqual(resp.status_code, 200)
obj = json.loads(resp.content)
self.assertEqual(obj['name'], 'Ball')
self.assertEqual(obj['artnr'], '12345')
-
+
# With appended characters
request = HttpRequest()
post_data = '{"name": "Ball 2", "artnr": "12345ABC"}'
@@ -103,14 +101,14 @@ def test_posts(self):
resp = self.client.post('/api/v1/products/', data=post_data, content_type='application/json')
self.assertEqual(resp.status_code, 201)
self.assertEqual(resp['location'], 'http://testserver/api/v1/products/12345ABC/')
-
+
# make sure posted object exists
resp = self.client.get('/api/v1/products/12345ABC/', data={'format': 'json'})
self.assertEqual(resp.status_code, 200)
obj = json.loads(resp.content)
self.assertEqual(obj['name'], 'Ball 2')
self.assertEqual(obj['artnr'], '12345ABC')
-
+
# With prepended characters
request = HttpRequest()
post_data = '{"name": "Ball 3", "artnr": "WK12345"}'
@@ -119,7 +117,7 @@ def test_posts(self):
resp = self.client.post('/api/v1/products/', data=post_data, content_type='application/json')
self.assertEqual(resp.status_code, 201)
self.assertEqual(resp['location'], 'http://testserver/api/v1/products/WK12345/')
-
+
# make sure posted object exists
resp = self.client.get('/api/v1/products/WK12345/', data={'format': 'json'})
self.assertEqual(resp.status_code, 200)
@@ -135,14 +133,14 @@ def test_posts(self):
resp = self.client.post('/api/v1/products/', data=post_data, content_type='application/json')
self.assertEqual(resp.status_code, 201)
self.assertEqual(resp['location'], 'http://testserver/api/v1/products/76123/03/')
-
+
# make sure posted object exists
resp = self.client.get('/api/v1/products/76123/03/', data={'format': 'json'})
self.assertEqual(resp.status_code, 200)
obj = json.loads(resp.content)
self.assertEqual(obj['name'], 'Bigwheel')
self.assertEqual(obj['artnr'], '76123/03')
-
+
request = HttpRequest()
post_data = '{"name": "Trampolin", "artnr": "WS65150/02"}'
request._raw_post_data = post_data
@@ -150,7 +148,7 @@ def test_posts(self):
resp = self.client.post('/api/v1/products/', data=post_data, content_type='application/json')
self.assertEqual(resp.status_code, 201)
self.assertEqual(resp['location'], 'http://testserver/api/v1/products/WS65150/02/')
-
+
# make sure posted object exists
resp = self.client.get('/api/v1/products/WS65150/02/', data={'format': 'json'})
self.assertEqual(resp.status_code, 200)
Please sign in to comment.
Something went wrong with that request. Please try again.