您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

tests.py 3.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. from decimal import Decimal as D
  2. from xml.dom.minidom import parseString
  3. import datetime
  4. from django.test import TestCase
  5. from django.conf import settings
  6. from oscar.apps.payment.datacash.models import OrderTransaction
  7. from oscar.apps.payment.datacash.utils import Gateway, Facade
  8. from oscar.apps.payment.utils import Bankcard
  9. class OrderTransactionTests(TestCase):
  10. def test_cc_numbers_are_not_saved(self):
  11. request_xml = """<?xml version="1.0" encoding="UTF-8" ?>
  12. <Request>
  13. <Authentication>
  14. <client>99000001</client>
  15. <password>boomboom</password>
  16. </Authentication>
  17. <Transaction>
  18. <CardTxn>
  19. <Card>
  20. <pan>1000011100000004</pan>
  21. <expirydate>04/06</expirydate>
  22. <startdate>01/04</startdate>
  23. </Card>
  24. <method>auth</method>
  25. </CardTxn>
  26. <TxnDetails>
  27. <merchantreference>1000001</merchantreference>
  28. <amount currency="GBP">95.99</amount>
  29. </TxnDetails>
  30. </Transaction>
  31. </Request>"""
  32. response_xml = """<?xml version="1.0" encoding="UTF-8" ?>
  33. <Response>
  34. <CardTxn>
  35. <authcode>060642</authcode>
  36. <card_scheme>Switch</card_scheme>
  37. <country>United Kingdom</country>
  38. <issuer>HSBC</issuer>
  39. </CardTxn>
  40. <datacash_reference>3000000088888888</datacash_reference>
  41. <merchantreference>1000001</merchantreference>
  42. <mode>LIVE</mode>
  43. <reason>ACCEPTED</reason>
  44. <status>1</status>
  45. <time>1071567305</time>
  46. </Response>"""
  47. txn = OrderTransaction.objects.create(order_number='1000',
  48. method='auth',
  49. datacash_ref='3000000088888888',
  50. merchant_ref='1000001',
  51. amount=D('95.99'),
  52. status=1,
  53. reason='ACCEPTED',
  54. request_xml=request_xml,
  55. response_xml=response_xml)
  56. doc = parseString(txn.request_xml)
  57. element = doc.getElementsByTagName('pan')[0]
  58. self.assertEqual('XXXXXXXXXXXX0004', element.firstChild.data)
  59. class IntegrationTests(TestCase):
  60. def _test_for_smoke(self):
  61. gateway = Gateway(settings.DATACASH_CLIENT,
  62. settings.DATACASH_PASSWORD,
  63. host=settings.DATACASH_HOST)
  64. response = gateway.auth(card_number='1000011000000005',
  65. expiry_date='01/13',
  66. amount=D('50.00'),
  67. currency='GBP',
  68. merchant_reference='123456_%s' % datetime.datetime.now().microsecond)
  69. print response
  70. def _test_adapter(self):
  71. bankcard = Bankcard(card_number='1000011000000005', expiry_date='01/13')
  72. dc_facade = Facade()
  73. reference = dc_facade.debit('102910', D('23.00'), bankcard)
  74. print reference
  75. OrderTransaction.objects.get(order_number='102910')