예제 #1
0
파일: test_forms.py 프로젝트: diox/solitude
 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)},
                      {})
예제 #2
0
 def test_failed(self):
     with self.assertRaises(ValidationError):
         check_status(
             {
                 'created': datetime.now(),
                 'status': constants.STATUS_FAILED
             }, {'status': constants.STATUS_PENDING})
예제 #3
0
 def test_completed_not_ok(self):
     with self.assertRaises(ValidationError):
         check_status(
             {
                 'created': datetime.now(),
                 'status': constants.STATUS_STARTED
             }, {'status': constants.STATUS_COMPLETED})
예제 #4
0
 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})
예제 #5
0
파일: test_forms.py 프로젝트: diox/solitude
 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})
예제 #6
0
 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)},
                      {})
예제 #7
0
 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},
                      {})
예제 #8
0
 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})
예제 #9
0
 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})
예제 #10
0
 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
             }, {})
예제 #11
0
 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})
예제 #12
0
    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
예제 #13
0
 def test_errored_ok(self):
     check_status({'created': datetime.now(),
                   'status': constants.STATUS_STARTED},
                  {'status': constants.STATUS_ERRORED})
예제 #14
0
파일: test_forms.py 프로젝트: diox/solitude
 def test_failed(self):
     with self.assertRaises(ValidationError):
         check_status({'created': datetime.now(), 'status':
                       constants.STATUS_FAILED},
                      {'status': constants.STATUS_PENDING})
예제 #15
0
 def test_completed_not_ok(self):
     with self.assertRaises(ValidationError):
         check_status({'created': datetime.now(),
                       'status': constants.STATUS_STARTED},
                      {'status': constants.STATUS_COMPLETED})
예제 #16
0
                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)
예제 #17
0
 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})
예제 #18
0
 def test_errored_ok(self):
     check_status(
         {
             'created': datetime.now(),
             'status': constants.STATUS_STARTED
         }, {'status': constants.STATUS_ERRORED})