Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

remove format list (bug 971359)

  • Loading branch information...
commit 0385c8cfb835616504ffaf3a287cc6f7a3205536 1 parent 7477e51
@andymckay andymckay authored
View
52 lib/solitude/api.py
@@ -46,23 +46,6 @@ def set_provider(self, provider=None):
self._provider = provider or settings.PAYMENT_PROVIDER
return self._provider
- def _object_from_response(self, res):
- obj = {}
- if res.get('errors'):
- return res
- elif res.get('objects'):
- obj = res['objects'][0]
- obj['id'] = res['objects'][0].get('resource_pk')
- elif res.get('resource_pk'):
- obj = res
- obj['id'] = res.get('resource_pk')
- try:
- if obj:
- obj['etag'] = res['meta']['headers'].get('etag', '')
- except KeyError:
- pass
- return obj
-
def create_buyer(self, uuid, pin=None):
"""Creates a buyer with an optional PIN in solitude.
@@ -70,9 +53,8 @@ def create_buyer(self, uuid, pin=None):
:param pin: Optional PIN that will be hashed.
:rtype: dictionary
"""
- res = self.safe_run(self.slumber.generic.buyer.post,
+ obj = self.safe_run(self.slumber.generic.buyer.post,
{'uuid': uuid, 'pin': pin})
- obj = self._object_from_response(res)
if 'etag' in obj:
etag = obj['etag']
cache.set('etag:%s' % uuid, etag)
@@ -89,12 +71,13 @@ def get_buyer(self, uuid, use_etags=True):
etag = cache.get(cache_key) if use_etags else None
headers = {'If-None-Match': etag} if etag else {}
try:
- res = self.safe_run(self.slumber.generic.buyer.get,
+ obj = self.safe_run(self.slumber.generic.buyer.get_object_or_404,
headers=headers, uuid=uuid)
except ResourceNotModified:
return (cache.get('buyer:%s' % etag)
or self.get_buyer(uuid, use_etags=False))
- obj = self._object_from_response(res)
+ except ObjectDoesNotExist:
+ obj = {}
if 'etag' in obj:
etag = obj['etag']
cache.set(cache_key, etag)
@@ -109,8 +92,8 @@ def set_needs_pin_reset(self, uuid, value=True, etag=''):
not, defaults to True
:rtype: dictionary
"""
- buyer = self.get_buyer(uuid)
- res = self.safe_run(self.slumber.generic.buyer(id=buyer['id']).patch,
+ id_ = self.get_buyer(uuid).get('resource_pk')
+ res = self.safe_run(self.slumber.generic.buyer(id=id_).patch,
{'needs_pin_reset': value, 'new_pin': None},
headers={'If-Match': etag})
if 'errors' in res:
@@ -123,8 +106,8 @@ def unset_was_locked(self, uuid, etag=''):
:param uuid: String to identify the buyer by.
:rtype: dictionary
"""
- buyer = self.get_buyer(uuid)
- res = self.safe_run(self.slumber.generic.buyer(id=buyer['id']).patch,
+ id_ = self.get_buyer(uuid).get('resource_pk')
+ res = self.safe_run(self.slumber.generic.buyer(id=id_).patch,
{'pin_was_locked_out': False},
headers={'If-Match': etag})
if 'errors' in res:
@@ -140,8 +123,8 @@ def change_pin(self, uuid, pin, etag=''):
:param pin: PIN the user would like to change to.
:rtype: dictionary
"""
- buyer = self.get_buyer(uuid)
- res = self.safe_run(self.slumber.generic.buyer(id=buyer['id']).patch,
+ id_ = self.get_buyer(uuid).get('resource_pk')
+ res = self.safe_run(self.slumber.generic.buyer(id=id_).patch,
{'pin': pin},
headers={'If-Match': etag})
# Empty string is a good thing from tastypie for a PATCH.
@@ -157,8 +140,8 @@ def set_new_pin(self, uuid, new_pin, etag=''):
:param pin: PIN the user would like to change to.
:rtype: dictionary
"""
- buyer = self.get_buyer(uuid)
- res = self.safe_run(self.slumber.generic.buyer(id=buyer['id']).patch,
+ id_ = self.get_buyer(uuid).get('resource_pk')
+ res = self.safe_run(self.slumber.generic.buyer(id=id_).patch,
{'new_pin': new_pin},
headers={'If-Match': etag})
# Empty string is a good thing from tastypie for a PATCH.
@@ -173,7 +156,7 @@ def get_active_product(self, public_id):
:param public_id: Product public_id.
:rtype: dictionary
"""
- return self.slumber.generic.product.get_object(
+ return self.slumber.generic.product.get_object_or_404(
seller__active=True, public_id=public_id)
def confirm_pin(self, uuid, pin):
@@ -388,7 +371,8 @@ def configure_product_for_billing(self, transaction_uuid,
redirect_url_onerror = absolutify(reverse('bango.error'))
try:
- seller = self.slumber.generic.seller.get_object(uuid=seller_uuid)
+ seller = self.slumber.generic.seller.get_object_or_404(
+ uuid=seller_uuid)
except ObjectDoesNotExist:
raise SellerNotConfigured('Seller with uuid %s does not exist'
% seller_uuid)
@@ -397,9 +381,9 @@ def configure_product_for_billing(self, transaction_uuid,
seller_id))
try:
- bango_product = self.slumber.bango.product.get_object(
- seller_product__seller=seller_id,
- seller_product__external_id=product_id)
+ bango_product = self.slumber.bango.product.get_object_or_404(
+ seller_product__seller=seller_id,
+ seller_product__external_id=product_id)
except ObjectDoesNotExist:
bango_product = self.create_product(product_id, product_name,
seller)
View
30 lib/solitude/tests.py
@@ -39,23 +39,24 @@ class FakeResponse(object):
return error_response
def test_get_buyer(self, slumber):
- slumber.generic.buyer.get.return_value = self.buyer_data
+ slumber.generic.buyer.get_object_or_404.return_value = self.buyer_data
buyer = client.get_buyer(self.uuid)
eq_(buyer.get('uuid'), self.uuid)
assert buyer.get('pin')
- assert buyer.get('id')
+ assert buyer.get('resource_pk')
assert buyer.get('etag')
def test_get_buyer_with_etag(self, slumber):
- slumber.generic.buyer.get.return_value = self.buyer_data
+ slumber.generic.buyer.get_object_or_404.return_value = self.buyer_data
buyer = client.get_buyer(self.uuid)
eq_(buyer.get('uuid'), self.uuid)
- slumber.generic.buyer.get.side_effect = ResourceNotModified()
+ slumber.generic.buyer.get_object_or_404.side_effect = (
+ ResourceNotModified())
buyer2 = client.get_buyer(self.uuid)
eq_(buyer.get('etag'), buyer2.get('etag'))
def test_non_existent_get_buyer(self, slumber):
- slumber.generic.buyer.get.side_effect = HttpClientError(
+ slumber.generic.buyer.get_object_or_404.side_effect = HttpClientError(
response=self.create_error_response())
buyer = client.get_buyer('something-that-does-not-exist')
assert 'errors' in buyer
@@ -68,7 +69,7 @@ def test_create_buyer_without_pin(self, slumber):
buyer = client.create_buyer(uuid)
eq_(buyer.get('uuid'), uuid)
assert not buyer.get('pin')
- assert buyer.get('id')
+ assert buyer.get('resource_pk')
def test_create_buyer_with_pin(self, slumber):
uuid = 'with_pin'
@@ -77,7 +78,7 @@ def test_create_buyer_with_pin(self, slumber):
buyer = client.create_buyer(uuid, self.pin)
eq_(buyer.get('uuid'), uuid)
assert buyer.get('pin')
- assert buyer.get('id')
+ assert buyer.get('resource_pk')
def test_create_buyer_with_alpha_pin(self, slumber):
slumber.generic.buyer.post.side_effect = HttpClientError(
@@ -279,6 +280,8 @@ def test_unset_needs_pin_reset_with_wrong_etag(self, slumber):
client.set_needs_pin_reset(self.uuid, False, etag=wrong_etag)
+@mock.patch.object(settings, 'UNIVERSAL_PROVIDER', False)
+@mock.patch.object(settings, 'PAYMENT_PROVIDER', 'bango')
class CreateBangoTest(TestCase):
uuid = 'some:pin'
seller = {'bango': {'seller': 's', 'resource_uri': 'r',
@@ -305,27 +308,28 @@ def test_create_bango(self, slumber):
@mock.patch('lib.solitude.api.client.slumber')
def test_no_seller(self, slumber):
- slumber.generic.seller.get_object.side_effect = ObjectDoesNotExist
+ slumber.generic.seller.get_object_or_404.side_effect = (
+ ObjectDoesNotExist)
with self.assertRaises(SellerNotConfigured):
client.configure_product_for_billing(*range(0, 8))
@mock.patch('lib.solitude.api.client.slumber')
def test_no_bango(self, slumber):
- slumber.generic.seller.get_object.return_value = self.seller
+ slumber.generic.seller.get_object_or_404.return_value = self.seller
slumber.bango.billing.post.return_value = {
'billingConfigurationId': 'bar'}
- slumber.bango.product.get_object.side_effect = ObjectDoesNotExist
+ slumber.bango.product.get_object_or_404.side_effect = (
+ ObjectDoesNotExist)
eq_(client.configure_product_for_billing(*range(0, 8)),
('bar', 'foo'))
@mock.patch('lib.solitude.api.client.slumber')
def test_has_bango(self, slumber):
- slumber.generic.seller.get_object.return_value = self.seller
+ slumber.generic.seller.get_object_or_404.return_value = self.seller
slumber.bango.billing.post.return_value = {
'billingConfigurationId': 'bar'}
slumber.bango.product.get_object.return_value = {
- 'resource_uri': 'foo'
- }
+ 'resource_uri': 'foo'}
eq_(client.configure_product_for_billing(*range(0, 8)),
('bar', 'foo'))
View
33 webpay/api/tests/test_api.py
@@ -1,6 +1,7 @@
import json
from django.conf import settings
+from django.core.exceptions import ObjectDoesNotExist
from django.core.urlresolvers import reverse
import mock
@@ -48,9 +49,6 @@ def error(self, status):
error.response = Response(404)
return error
- def wrap(self, data):
- return {'objects': [data]}
-
class PIN(BaseCase):
@@ -75,15 +73,17 @@ def test_anon(self):
eq_(self.client.get(self.url).status_code, 403)
def test_no_pin(self):
- self.solitude.generic.buyer.get.side_effect = self.error(404)
+ self.solitude.generic.buyer.get_object_or_404.side_effect = (
+ ObjectDoesNotExist)
res = self.client.get(self.url)
eq_(res.status_code, 404)
def test_some_pin(self):
- self.solitude.generic.buyer.get.return_value = self.wrap({'pin': True})
+ self.solitude.generic.buyer.get_object_or_404.return_value = {
+ 'pin': True}
res = self.client.get(self.url)
- self.solitude.generic.buyer.get.assert_called_with(headers={},
- uuid='a')
+ self.solitude.generic.buyer.get_object_or_404.assert_called_with(
+ headers={}, uuid='a')
eq_(json.loads(res.content)['pin'], True)
@@ -98,22 +98,23 @@ def test_no_data(self):
eq_(res.status_code, 400)
def test_no_user(self):
- self.solitude.generic.buyer.get.side_effect = self.error(404)
+ self.solitude.generic.buyer.get_object_or_404.side_effect = (
+ ObjectDoesNotExist)
res = self.client.post(self.url, {'pin': '1234'})
self.solitude.generic.buyer.post.assert_called_with({'uuid': 'a',
'pin': '1234'})
eq_(res.status_code, 201)
def test_user(self):
- self.solitude.generic.buyer.get.return_value = self.wrap(
- {'pin': False, 'resource_pk': 'abc'})
+ self.solitude.generic.buyer.get_object_or_404.return_value = {
+ 'pin': False, 'resource_pk': 'abc'}
res = self.client.post(self.url, {'pin': '1234'})
eq_(res.status_code, 201)
self.solitude.generic.buyer.assert_called_with(id='abc')
def test_user_with_pin(self):
- self.solitude.generic.buyer.get.return_value = self.wrap(
- {'pin': True, 'resource_pk': 'abc'})
+ self.solitude.generic.buyer.get_object_or_404.return_value = {
+ 'pin': True, 'resource_pk': 'abc'}
res = self.client.post(self.url, {'pin': '1234'})
eq_(res.status_code, 400)
@@ -151,8 +152,8 @@ def test_not_reverified(self):
eq_(res.status_code, 400)
def test_change(self):
- self.solitude.generic.buyer.get.return_value = self.wrap(
- {'pin': True, 'resource_pk': 'abc'})
+ self.solitude.generic.buyer.get_object_or_404.return_value = {
+ 'pin': True, 'resource_pk': 'abc'}
res = self.patch(self.url, data={'pin': '1234'})
eq_(res.status_code, 204)
# TODO: figure out how to check that patch was called.
@@ -160,8 +161,8 @@ def test_change(self):
eq_(res.status_code, 204)
def test_reverified(self):
- self.solitude.generic.buyer.get.return_value = self.wrap(
- {'pin': True, 'resource_pk': 'abc'})
+ self.solitude.generic.buyer.get_object_or_404.return_value = {
+ 'pin': True, 'resource_pk': 'abc'}
res = self.patch(self.url, data={'pin': '1234'})
eq_(res.status_code, 204)
# A cheap way to confirm that was_reverified was flipped.
View
65 webpay/auth/tests/test_decorators.py
@@ -1,6 +1,6 @@
import json
-from django.core.exceptions import PermissionDenied
+from django.core.exceptions import ObjectDoesNotExist, PermissionDenied
from django.core.urlresolvers import reverse
from django.http import HttpRequest
@@ -41,9 +41,8 @@ def do_auth(self):
@mock.patch('lib.solitude.api.client.slumber')
def test_no_user(self, slumber):
- slumber.generic.buyer.get.return_value = {
- 'meta': {'total_count': 0}
- }
+ slumber.generic.buyer.get_object_or_404.side_effect = (
+ ObjectDoesNotExist)
data = self.do_auth()
eq_(self.client.session.get('uuid_has_pin'), False)
eq_(data['needs_redirect'], True)
@@ -51,12 +50,8 @@ def test_no_user(self, slumber):
@mock.patch('lib.solitude.api.client.slumber')
def test_user_no_pin(self, slumber):
- slumber.generic.buyer.get.return_value = {
- 'meta': {'total_count': 1},
- 'objects': [{'pin': False,
- 'pin_confirmed': False,
- 'needs_pin_reset': False}]
- }
+ slumber.generic.buyer.get_object_or_404.return_value = {
+ 'pin': False, 'pin_confirmed': False, 'needs_pin_reset': False}
data = self.do_auth()
eq_(self.client.session.get('uuid_has_pin'), False)
eq_(self.client.session.get('uuid_has_confirmed_pin'), False)
@@ -65,12 +60,8 @@ def test_user_no_pin(self, slumber):
@mock.patch('lib.solitude.api.client.slumber')
def test_user_with_unconfirmed_pin(self, slumber):
- slumber.generic.buyer.get.return_value = {
- 'meta': {'total_count': 1},
- 'objects': [{'pin': True,
- 'pin_confirmed': False,
- 'needs_pin_reset': False}]
- }
+ slumber.generic.buyer.get_object_or_404.return_value = {
+ 'pin': True, 'pin_confirmed': False, 'needs_pin_reset': False}
data = self.do_auth()
eq_(self.client.session.get('uuid_has_pin'), False)
eq_(self.client.session.get('uuid_has_confirmed_pin'), False)
@@ -79,12 +70,8 @@ def test_user_with_unconfirmed_pin(self, slumber):
@mock.patch('lib.solitude.api.client.slumber')
def test_user_with_confirmed_pin(self, slumber):
- slumber.generic.buyer.get.return_value = {
- 'meta': {'total_count': 1},
- 'objects': [{'pin': True,
- 'pin_confirmed': True,
- 'needs_pin_reset': False}]
- }
+ slumber.generic.buyer.get_object_or_404.return_value = {
+ 'pin': True, 'pin_confirmed': True, 'needs_pin_reset': False}
data = self.do_auth()
eq_(self.client.session.get('uuid_has_pin'), True)
eq_(self.client.session.get('uuid_has_confirmed_pin'), True)
@@ -106,29 +93,22 @@ def do_auth(self):
@mock.patch('lib.solitude.api.client.slumber')
def test_no_user(self, slumber):
- slumber.generic.buyer.get.return_value = {
- 'meta': {'total_count': 0}
- }
+ slumber.generic.buyer.get_object_or_404.side_effect = (
+ ObjectDoesNotExist)
self.do_auth()
eq_(self.client.session.get('uuid_needs_pin_reset'), False)
@mock.patch('lib.solitude.api.client.slumber')
def test_user_no_reset_pin_flag(self, slumber):
- slumber.generic.buyer.get.return_value = {
- 'meta': {'total_count': 1},
- 'objects': [{'pin': True,
- 'needs_pin_reset': False}]
- }
+ slumber.generic.buyer.get_object_or_404.return_value = {
+ 'pin': True, 'needs_pin_reset': False}
self.do_auth()
eq_(self.client.session.get('uuid_needs_pin_reset'), False)
@mock.patch('lib.solitude.api.client.slumber')
def test_user_with_reset_pin_flag(self, slumber):
- slumber.generic.buyer.get.return_value = {
- 'meta': {'total_count': 1},
- 'objects': [{'pin': True,
- 'needs_pin_reset': True}]
- }
+ slumber.generic.buyer.get_object_or_404.return_value = {
+ 'pin': True, 'needs_pin_reset': True}
self.do_auth()
eq_(self.client.session.get('uuid_needs_pin_reset'), True)
@@ -147,21 +127,16 @@ def do_auth(self):
@mock.patch('lib.solitude.api.client.slumber')
def test_user_is_locked_out(self, slumber):
- slumber.generic.buyer.get.return_value = {
- 'meta': {'total_count': 1},
- 'objects': [{'pin': True,
- 'pin_is_locked_out': True}]
- }
+ slumber.generic.buyer.get_object_or_404.return_value = {
+ 'pin': True, 'pin_is_locked_out': True}
+
self.do_auth()
eq_(self.client.session.get('uuid_pin_is_locked'), True)
@mock.patch('lib.solitude.api.client.slumber')
def test_user_was_locked_out(self, slumber):
- slumber.generic.buyer.get.return_value = {
- 'meta': {'total_count': 1},
- 'objects': [{'pin': True,
- 'pin_was_locked_out': True}]
- }
+ slumber.generic.buyer.get_object_or_404.return_value = {
+ 'pin': True, 'pin_was_locked_out': True}
self.do_auth()
eq_(self.client.session.get('uuid_pin_was_locked'), True)
View
2  webpay/pay/tests/test_tasks.py
@@ -511,7 +511,7 @@ def test_marketplace_seller_switch(self, marketplace, solitude):
self.start()
# Check that the seller_uuid was switched to that of the app seller.
- solitude.generic.seller.get_object.assert_called_with(
+ solitude.generic.seller.get_object_or_404.assert_called_with(
uuid=app_seller_uuid)
@mock.patch.object(settings, 'KEY', 'marketplace-domain')
View
3  webpay/settings/base.py
@@ -386,9 +386,6 @@
# that decision. See bug 862588.
ALLOWED_CALLBACK_SCHEMES = ['http', 'https']
-# When we are ready to having curling format lists for us, flip this to True.
-CURLING_FORMAT_LISTS = False
-
# Number of retries on a payment postback.
POSTBACK_ATTEMPTS = 5
Please sign in to comment.
Something went wrong with that request. Please try again.