Пример #1
0
class TestBasePaymentForm(TestCase):
    def setUp(self):
        self.form_class = BasePaymentForm()

    def test_md5(self):
        cd = {
            'action': ACTION_CHECK,
            'orderSumAmount': '100',
            'orderSumCurrencyPaycash': '100',
            'orderSumBankPaycash': '123',
            'shopId': settings.YANDEX_MONEY_SHOP_ID,
            'invoiceId': '1',
            'customerNumber': '1'
        }

        hash_string = ';'.join(map(str, (
            cd['action'],
            cd['orderSumAmount'],
            cd['orderSumCurrencyPaycash'],
            cd['orderSumBankPaycash'],
            cd['shopId'],
            cd['invoiceId'],
            cd['customerNumber'],
            settings.YANDEX_MONEY_SHOP_PASSWORD
        )))
        hash_string = hash_string.encode('utf-8')
        md5string = md5(hash_string).hexdigest().upper()
        self.assertEqual(md5string, self.form_class.make_md5(cd))
Пример #2
0
    def test_notice(self):
        params = self.params.copy()
        params['customerNumber'] = self.payment.custome_number
        params['md5'] = BasePaymentForm.make_md5(params)

        res = self.app.post(self.url, params=params)

        self.assertEquals(res.content_type, 'application/xml',
                          'Content type is not XML')

        attrs = etree.fromstring(res.content).attrib
        self.assertEquals(attrs['code'], '0', 'Code is not success')
        self.assertEquals(attrs['shopId'], params['shopId'],
                          'ShopID is not valid')
        self.assertEquals(attrs['invoiceId'], params['invoiceId'],
                          'InvoiceId is not valid')
        self.assertEquals(len(attrs), 4, 'Response has excess attrs')

        payment = Payment.objects.get(pk=self.payment.pk)
        self.assertEquals(str(payment.order_currency),
                          params['orderSumCurrencyPaycash'])
        self.assertEquals(str(payment.shop_amount),
                          params['shopSumAmount'])
        self.assertEquals(str(payment.shop_currency),
                          params['shopSumCurrencyPaycash'])
        self.assertEquals(payment.payer_code,
                          params['paymentPayerCode'])
        self.assertEquals(payment.payment_type,
                          params['paymentType'])
Пример #3
0
    def test_bad_data(self):
        params = self.params.copy()
        params['customerNumber'] = self.payment.custome_number
        params['scid'] = 100500
        params['md5'] = BasePaymentForm.make_md5(params)

        res = self.app.post(self.url, params=params)

        attrs = etree.fromstring(res.content).attrib
        self.assertEquals(attrs['code'], '200',
                          'Code is not "200"')
        self.assertEquals(len(attrs), 1, 'Response has excess attrs')
Пример #4
0
    def test_check(self):
        params = self.params.copy()
        params['customerNumber'] = self.payment.custome_number
        params['md5'] = BasePaymentForm.make_md5(params)

        res = self.app.post(self.url, params=params)

        self.assertEquals(res.content_type, 'application/xml',
                          'Content type is not XML')

        attrs = etree.fromstring(res.content).attrib
        self.assertEquals(attrs['code'], '0', 'Code is not success')
        self.assertEquals(attrs['shopId'], params['shopId'],
                          'ShopID is not valid')
        self.assertEquals(attrs['invoiceId'], params['invoiceId'],
                          'InvoiceId is not valid')
        self.assertEquals(len(attrs), 4, 'Response has excess attrs')