Skip to content

Commit

Permalink
Clean-up to get the alphanumeric tests fixed. v0.8.3
Browse files Browse the repository at this point in the history
  • Loading branch information
toastdriven committed Jul 24, 2010
1 parent 6ede26f commit 08e40e4
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 19 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Expand Up @@ -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.

Expand Down
4 changes: 2 additions & 2 deletions docs/conf.py
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion tastypie/__init__.py
@@ -1,2 +1,2 @@
__author__ = 'Daniel Lindsley, Cody Soyland, Matt Croydon'
__version__ = (0, 8, 2)
__version__ = (0, 8, 3)
11 changes: 9 additions & 2 deletions tastypie/resources.py
Expand Up @@ -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):
"""
Expand All @@ -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):
"""
Expand Down
3 changes: 2 additions & 1 deletion 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()
22 changes: 10 additions & 12 deletions tests/alphanumeric/tests/views.py
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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"}'
Expand All @@ -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"}'
Expand All @@ -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)
Expand All @@ -135,22 +133,22 @@ 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

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)
Expand Down

0 comments on commit 08e40e4

Please sign in to comment.