Skip to content
Browse files

all transactions to be looked up by uuid (bug 820198)

  • Loading branch information...
1 parent 9fa9052 commit d4f4de58f7d7595245bdfa2853f9826a3178944f @andymckay andymckay committed Dec 21, 2012
Showing with 28 additions and 5 deletions.
  1. +13 −2 lib/transactions/resources.py
  2. +15 −3 lib/transactions/tests/test_api.py
View
15 lib/transactions/resources.py
@@ -1,5 +1,7 @@
import uuid
+from django.conf.urls.defaults import url
+
from tastypie import fields
from lib.transactions.models import Transaction
@@ -19,15 +21,24 @@ class Meta(ModelResource.Meta):
fields = ['uuid', 'seller_product', 'amount', 'currency', 'provider',
'uid_pay', 'uid_support', 'type', 'status', 'related',
'notes']
- list_allowed_methods = ['get', 'post', 'patch']
- allowed_methods = ['get', 'put']
+ list_allowed_methods = ['get', 'post']
+ allowed_methods = ['get', 'patch']
resource_name = 'transaction'
filtering = {
'uuid': 'exact',
'seller': 'exact',
'provider': 'exact'
}
+ def override_urls(self):
+ return [
+ url(r"^(?P<resource_name>transaction)/(?P<uuid>.*)/$",
+ self.wrap_view('dispatch_detail'),
+ name="api_dispatch_detail"),
+ ]
+
+ prepend_urls = override_urls
+
def hydrate_uuid(self, bundle):
bundle.data.setdefault('uuid', str(uuid.uuid4()))
return bundle
View
18 lib/transactions/tests/test_api.py
@@ -1,5 +1,7 @@
import json
+from django.core.urlresolvers import reverse
+
from nose.tools import eq_, ok_
from lib.sellers.tests.utils import make_seller_paypal
@@ -20,11 +22,14 @@ def setUp(self):
seller_product=self.product,
provider=constants.SOURCE_PAYPAL,
uuid=self.uuid)
- self.detail_url = self.get_detail_url('transaction', self.trans.pk)
+ self.detail_url = reverse('api_dispatch_detail',
+ kwargs={'api_name': self.api_name,
+ 'resource_name': 'transaction',
+ 'uuid': self.uuid})
def test_list_allowed(self):
- self.allowed_verbs(self.list_url, ['get', 'post', 'patch'])
- self.allowed_verbs(self.detail_url, ['get', 'put'])
+ self.allowed_verbs(self.list_url, ['get', 'post'])
+ self.allowed_verbs(self.detail_url, ['get', 'patch'])
def test_list(self):
res = self.client.get(self.list_url, data={'uuid': self.uuid})
@@ -48,3 +53,10 @@ def test_provider(self):
constants.SOURCE_BANGO})
eq_(res.status_code, 200)
eq_(json.loads(res.content)['meta']['total_count'], 0, res.content)
+
+ def test_patch(self):
+ res = self.client.patch(self.detail_url,
+ data={'status': constants.STATUS_COMPLETED})
+ eq_(res.status_code, 202)
+ eq_(Transaction.objects.get(pk=self.trans.pk).status,
+ constants.STATUS_COMPLETED)

0 comments on commit d4f4de5

Please sign in to comment.
Something went wrong with that request. Please try again.