def test_lockdown(self): check_status({'created': datetime.now() - timedelta(seconds=55), 'status': constants.STATUS_CHECKED}, {'status': constants.STATUS_COMPLETED}) with self.assertRaises(ValidationError): check_status({'created': datetime.now() - timedelta(seconds=65)}, {})
def test_failed(self): with self.assertRaises(ValidationError): check_status( { 'created': datetime.now(), 'status': constants.STATUS_FAILED }, {'status': constants.STATUS_PENDING})
def test_completed_not_ok(self): with self.assertRaises(ValidationError): check_status( { 'created': datetime.now(), 'status': constants.STATUS_STARTED }, {'status': constants.STATUS_COMPLETED})
def test_seller_product_needed(self): with self.assertRaises(ValidationError): check_status( { 'status': constants.STATUS_STARTED, 'provider': constants.PROVIDER_REFERENCE, 'created': datetime.now() }, {'status': constants.STATUS_COMPLETED})
def test_checked(self): with self.assertRaises(ValidationError): check_status({'created': datetime.now(), 'status': constants.STATUS_CHECKED}, {'status': constants.STATUS_PENDING}) check_status({'created': datetime.now(), 'status': constants.STATUS_CHECKED}, {'status': constants.STATUS_COMPLETED})
def test_lockdown(self): check_status( { 'created': datetime.now() - timedelta(seconds=55), 'status': constants.STATUS_CHECKED }, {'status': constants.STATUS_COMPLETED}) with self.assertRaises(ValidationError): check_status({'created': datetime.now() - timedelta(seconds=65)}, {})
def test_lockdown(self): check_status({'created': datetime.now() - timedelta(seconds=55), 'status': constants.STATUS_CHECKED, 'provider': constants.PROVIDER_BANGO, 'seller_product': 1}, {'status': constants.STATUS_COMPLETED}) with self.assertRaises(ValidationError): check_status({'created': datetime.now() - timedelta(seconds=65), 'status': constants.STATUS_CHECKED}, {})
def test_checked(self): with self.assertRaises(ValidationError): check_status({'created': datetime.now(), 'status': constants.STATUS_CHECKED, 'provider': constants.PROVIDER_BANGO, 'seller_product': 1}, {'status': constants.STATUS_PENDING}) check_status({'created': datetime.now(), 'status': constants.STATUS_CHECKED, 'provider': constants.PROVIDER_BANGO, 'seller_product': 1}, {'status': constants.STATUS_COMPLETED})
def test_checked(self): with self.assertRaises(ValidationError): check_status( { 'created': datetime.now(), 'status': constants.STATUS_CHECKED }, {'status': constants.STATUS_PENDING}) check_status( { 'created': datetime.now(), 'status': constants.STATUS_CHECKED }, {'status': constants.STATUS_COMPLETED})
def test_lockdown(self): check_status( { 'created': datetime.now() - timedelta(seconds=55), 'status': constants.STATUS_CHECKED, 'provider': constants.PROVIDER_BANGO, 'seller_product': 1 }, {'status': constants.STATUS_COMPLETED}) with self.assertRaises(ValidationError): check_status( { 'created': datetime.now() - timedelta(seconds=65), 'status': constants.STATUS_CHECKED }, {})
def test_checked(self): with self.assertRaises(ValidationError): check_status( { 'created': datetime.now(), 'status': constants.STATUS_CHECKED, 'provider': constants.PROVIDER_BANGO, 'seller_product': 1 }, {'status': constants.STATUS_PENDING}) check_status( { 'created': datetime.now(), 'status': constants.STATUS_CHECKED, 'provider': constants.PROVIDER_BANGO, 'seller_product': 1 }, {'status': constants.STATUS_COMPLETED})
def clean_notification(self): try: data = etree.fromstring(self.cleaned_data['notification']) except etree.XMLSyntaxError: log.error('XML parse error') raise forms.ValidationError('XML parse error') action = data.find('action') if action is None: # bool(action) is False, so check against None. raise forms.ValidationError('Action is required') if action.text != 'PAYMENT': raise forms.ValidationError('Action invalid: {0}' .format(action.text)) if data.find('data') is None: raise forms.ValidationError('Data is required') # Easier to work with a dictionary than etree. data = dict([c.values() for c in data.find('data').getchildren()]) if data.get('status') != OK: # Cannot find any other definitions of what state might be. raise forms.ValidationError('Unspecified state: {0}' .format(data.get('status'))) try: trans = Transaction.objects.get(uid_pay=data['transId']) except Transaction.DoesNotExist: raise forms.ValidationError('Transaction not found: {0}' .format(data['transId'])) data['new_status'] = {OK: STATUS_COMPLETED}[data['status']] old = {'status': trans.status, 'created': trans.created} new = {'status': data['new_status']} try: check_status(old, new) except forms.ValidationError: log.warning('Invalid status change to: {0} for transaction: {1}' .format(data['new_status'], trans.pk)) raise # Instead of having to get the Transaction again save it. self.cleaned_data['transaction'] = trans return data
def test_errored_ok(self): check_status({'created': datetime.now(), 'status': constants.STATUS_STARTED}, {'status': constants.STATUS_ERRORED})
def test_failed(self): with self.assertRaises(ValidationError): check_status({'created': datetime.now(), 'status': constants.STATUS_FAILED}, {'status': constants.STATUS_PENDING})
def test_completed_not_ok(self): with self.assertRaises(ValidationError): check_status({'created': datetime.now(), 'status': constants.STATUS_STARTED}, {'status': constants.STATUS_COMPLETED})
trans = Transaction.objects.get(uuid=data['externalCPTransID']) except Transaction.DoesNotExist: log.warning('Transaction not found by externalCPTransID' .format(data['externalCPTransID'])) else: log.warning('No externalCPTransID in notification.') if not trans: raise forms.ValidationError('Transaction not found, aborting.') data['new_status'] = {OK: STATUS_COMPLETED}[data['status']] old = model_to_dict(trans) old['created'] = trans.created new = {'status': data['new_status']} try: check_status(old, new) except forms.ValidationError: log.warning('Invalid status change to: {0} for transaction: {1}' .format(data['new_status'], trans.pk)) raise # Instead of having to get the Transaction again save it. self.cleaned_data['transaction'] = trans return data class GetLoginTokenForm(forms.Form): emailAddress = forms.EmailField(required=True) packageId = forms.IntegerField(required=True) personId = forms.IntegerField(required=True)
def test_seller_product_needed(self): with self.assertRaises(ValidationError): check_status({'status': constants.STATUS_STARTED, 'provider': constants.PROVIDER_REFERENCE, 'created': datetime.now()}, {'status': constants.STATUS_COMPLETED})
def test_errored_ok(self): check_status( { 'created': datetime.now(), 'status': constants.STATUS_STARTED }, {'status': constants.STATUS_ERRORED})