Skip to content
This repository has been archived by the owner on Jan 25, 2018. It is now read-only.

Commit

Permalink
No notifications for failed sims (bug 847537)
Browse files Browse the repository at this point in the history
This is temporary until the API can support
failure notices.
  • Loading branch information
kumar303 committed Mar 6, 2013
1 parent 2d1897f commit dbc9e02
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion webpay/pay/tasks.py
Expand Up @@ -214,7 +214,7 @@ def _notify(notifier_task, trans, extra_response=None, simulated=NOT_SIMULATED,
algorithm='HS256')
success, last_error = send_pay_notice(url, trans['type'], signed_notice,
trans['uuid'], notifier_task,
task_args)
task_args, simulated=simulated)
s = Notice._meta.get_field_by_name('last_error')[0].max_length
last_error = last_error[:s] # truncate to fit
Notice.objects.create(transaction_uuid=trans['uuid'],
Expand Down
11 changes: 11 additions & 0 deletions webpay/pay/tests/test_tasks.py
Expand Up @@ -366,6 +366,17 @@ def test_retry_http_error(self, post, retry, slumber):
retry.assert_called_with(args=['issuer-key', payload],
max_retries=ANY, eta=ANY, exc=ANY)

@mock.patch('webpay.pay.utils.requests.post')
@mock.patch('webpay.pay.utils.notify_failure')
def test_no_notifications_on_simulate(self, notify_failure, post, slumber):
self.set_secret_mock(slumber, 'f')
post.side_effect = RequestException('500 error')

req = {'simulate': {'result': 'postback'}}
payload = self.payload(typ=TYP_POSTBACK, extra_req=req)
self.notify(payload)
assert not notify_failure.called, 'Notification should not be sent'


class TestStartPay(test_utils.TestCase):

Expand Down
13 changes: 11 additions & 2 deletions webpay/pay/utils.py
Expand Up @@ -12,6 +12,8 @@

from lib.marketplace.api import client

from .models import NOT_SIMULATED

log = logging.getLogger('w.pay.utils')


Expand All @@ -20,7 +22,7 @@ def format_exception(exception):


def send_pay_notice(url, notice_type, signed_notice, trans_id,
notifier_task, task_args):
notifier_task, task_args, simulated=NOT_SIMULATED):
"""
Send app a notification about a payment or chargeback.
Expand All @@ -39,6 +41,8 @@ def send_pay_notice(url, notice_type, signed_notice, trans_id,
celery task object
**task_args**
A list of args to send to the task when retrying after failures.
**simulated**
Type of payment simulation. The default is none.
A tuple of (url, success, last_error) is returned.
Expand Down Expand Up @@ -75,7 +79,12 @@ def send_pay_notice(url, notice_type, signed_notice, trans_id,

# If it's the last retry it will re-throw the original exception.
except Exception, final_exception:
notify_failure(url, trans_id)
if simulated == NOT_SIMULATED:
notify_failure(url, trans_id)
else:
# TODO(Kumar): Fix the API for this in bug 847537
log.info('Not notifying anyone about simulated failure '
'for %r' % trans_id)
return False, format_exception(final_exception)

else:
Expand Down

0 comments on commit dbc9e02

Please sign in to comment.