def test_flip(self): process = Processor(notification(subject=subscription())) process.subscription = self.braintree_sub process.get_subscription() process.update_subscription(True) eq_(self.braintree_sub.reget().active, True) process.update_subscription(False) eq_(self.braintree_sub.reget().active, False)
def test_transactions_order(self): process = Processor(notification( subject=subscription(transactions=[ # Repeated transactions only most recent (first) # should be used. transaction(id='first:id'), transaction(id='another:id') ]), kind=self.kind)) process.process() eq_(process.transactions[0].uid_support, 'first:id')
def test_transactions_order(self): process = Processor( notification( subject=subscription(transactions=[ # Repeated transactions only most recent (first) # should be used. transaction(id='first:id'), transaction(id='another:id') ]), kind=self.kind)) process.process() eq_(process.transactions[0].uid_support, 'first:id')
def test_ok(self): sub = subscription(transactions=[ transaction(status='processor_declined', processor_response_code='nah') ]) Processor(notification(kind=self.kind, subject=sub)).process() eq_(Transaction.objects.get().status, constants.STATUS_FAILED)
def parse(request): form = WebhookParseForm(request.DATA) if not form.is_valid(): raise FormError(form.errors) # Parse the gateway without doing a validation on this server. # The validation has happened on the solitude-auth server. gateway = get_client().Configuration.instantiate().gateway() payload = base64.decodestring(form.cleaned_data['bt_payload']) attributes = XmlUtil.dict_from_xml(payload) parsed = WebhookNotification(gateway, attributes['notification']) log.info('Received webhook: {p.kind}.'.format(p=parsed)) debug_log.debug(parsed) processor = Processor(parsed) processor.process() data = processor.data return Response(data, status=200 if data else 204)
def test_subscription_inactive(self): Processor(notification(kind=self.kind, subject=self.sub)).process() eq_(self.braintree_sub.reget().active, False)
def test_ok(self): Processor(notification(kind=self.kind, subject=self.sub)).process() eq_(Transaction.objects.get().status, constants.STATUS_CHECKED)
def test_none(self): self.braintree_sub.delete() obj = Processor(notification(kind=self.kind, subject=self.sub)) with self.assertRaises(BraintreeSubscription.DoesNotExist): obj.process()
def test_subscription_active(self): self.braintree_sub.active = False self.braintree_sub.save() Processor(notification(kind=self.kind, subject=self.sub)).process() eq_(self.braintree_sub.reget().active, True)
def test_ok(self): Processor(notification(kind=self.kind, subject=self.sub)).process() transaction = Transaction.objects.get() eq_(transaction.status, constants.STATUS_CHECKED) eq_(BraintreeTransaction.objects.get().transaction, transaction) eq_(self.braintree_sub.reget().active, True)
def test_no_transactions_data(self): process = Processor( notification(subject=subscription(transactions=[]), kind=self.kind)) process.process() eq_(process.transaction, None)
def process(self, subscription): hook = Processor(notification(subject=subscription, kind=self.kind)) hook.process() hook.get_subscription() hook.update_transactions() return hook
def test_no_transactions_data(self): process = Processor(notification( subject=subscription(transactions=[]), kind=self.kind)) process.process() eq_(process.transaction, None)