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))
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'])
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')
def test_md5_sign(self): cd = { 'action': 'checkOrder', 'orderSumAmount': '87.10', 'orderSumCurrencyPaycash': '643', 'orderSumBankPaycash': '1001', 'shopId': '13', 'invoiceId': '55', 'customerNumber': '8123294469', 'md5': '1B35ABE38AA54F2931B0C58646FD1321', } res = BasePaymentForm.check_md5(cd) self.assertTrue(res, 'MD5 sign is not valid')
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')
def setUp(self): self.form_class = BasePaymentForm()