def test_get_commerce_key(self): testing_path = os.path.join(os.path.dirname(__file__), 'keys', 'test_commerce.pem') with open(testing_path, 'r') as testing_file: commerce = Commerce(id=12345, testing=True) commerce.key = Commerce.TEST_COMMERCE_KEY expected_key = RSA.importKey(testing_file.read()) self.assertEqual(expected_key, commerce.get_commerce_key())
def test_get_config_tbk_production(self): config_path = os.path.join(os.path.dirname(__file__), 'fixtures', 'tbk_config.dat.production') with open(config_path, 'r') as config_file: expected = config_file.read() commerce = Commerce(id="597026007977", key=Commerce.TEST_COMMERCE_KEY, testing=False) self.assertEqual(expected, commerce.get_config_tbk(confirmation_url="http://54.198.45.70:80/prodwebpay/result"))
def test_get_config_tbk_testing(self): config_path = os.path.join(os.path.dirname(__file__), 'fixtures', 'tbk_config.dat.testing') with open(config_path, 'r') as config_file: expected = config_file.read() commerce = Commerce(testing=True) self.assertEqual(expected, commerce.get_config_tbk(confirmation_url="http://54.198.45.69:8080/webpay/confirmation"))
def test_get_webpay_key(self): webpay_path = os.path.join(os.path.dirname(__file__), 'keys', 'webpay.101.pem') with open(webpay_path, 'r') as testing_file: commerce = Commerce(id=12345, testing=True) commerce.testing = False expected_key = RSA.importKey(testing_file.read()) key = commerce.get_webpay_key() self.assertEqual(expected_key, key)
def test_webpay_decrypt_binary(self, Decryption, get_webpay_key, get_commerce_key): commerce = Commerce(id=12345, testing=True) message = b"encrypted" result = commerce.webpay_decrypt(message) Decryption.assert_called_once_with(get_commerce_key.return_value, get_webpay_key.return_value) decryption = Decryption.return_value decryption.decrypt.assert_called_once_with(message) get_webpay_key.assert_called_once_with() get_commerce_key.assert_called_once_with() self.assertEqual(result, decryption.decrypt.return_value)
def test_webpay_encrypt_binary(self, Encryption, get_webpay_key, get_commerce_key): commerce = Commerce(id="12345", testing=True) message = b"decrypted" result = commerce.webpay_encrypt(message) Encryption.assert_called_once_with(get_commerce_key.return_value, get_webpay_key.return_value) encryption = Encryption.return_value encryption.encrypt.assert_called_once_with(message) get_webpay_key.assert_called_once_with() get_commerce_key.assert_called_once_with() self.assertEqual(result, encryption.encrypt.return_value)
def test_no_id_given_testing(self): """ init Commerce sets test_commerce key when no id is given and testings is True """ commerce = Commerce(key="commerce_key", testing=True) self.assertEqual(commerce.id, Commerce.TEST_COMMERCE_ID)
def test_no_key_given_testing(self): """ init Commerce sets test_commerce key when no key is given and testings is True """ commerce = Commerce(id="12345", testing=True) self.assertEqual(commerce.key, Commerce.TEST_COMMERCE_KEY)
def test_create_commerce_with_no_commerce_id(self): """ create_commerce create a commerce with environ TBK_COMMERCE_TESTING=True """ commerce = Commerce.create_commerce() self.assertEqual(commerce.id, commerce.TEST_COMMERCE_ID) self.assertTrue(commerce.testing) self.assertEqual(commerce.key, commerce.TEST_COMMERCE_KEY)
def test_called_with_all_arguments(self): """ init Commerce can be done with all it's arguments """ commerce = Commerce(id="12345", key="commerce_key", testing=True) self.assertEqual(commerce.id, "12345") self.assertEqual(commerce.key, "commerce_key") self.assertTrue(commerce.testing) self.assertEqual(101, commerce.webpay_key_id)
from tbk.webpay.commerce import Commerce from tbk.webpay.payment import Payment from tbk.webpay.confirmation import Confirmation from tbk.webpay.logging import configure_logger from tbk.webpay.logging.official import WebpayOfficialHandler from utils import * import json import os import ast LOG_BASE_PATH = os.path.join(os.path.dirname(__file__), "log") configure_logger(WebpayOfficialHandler(LOG_BASE_PATH)) commerce = Commerce(testing=True) #Pruebas Reales usar: #commerce = Commerce.create_commerce() webpay = Blueprint('webpay', __name__) def initialize_app(app): app.register_blueprint(webpay) # Genera un pago con transbank, se encarga de comunicarse y # entrega la url dada por transbank para redirigir al usuario. @webpay.route("/webpay/payment", methods=["POST"]) @webpay.route("/webpay/payment/", methods=["POST"]) def payment(): global commerce
def test_no_testing_given(self): """ init Commerce set testing to False """ commerce = Commerce(id="12345", key=Commerce.TEST_COMMERCE_KEY) self.assertFalse(commerce.testing)
def test_reject(self, webpay_encrypt): commerce = Commerce(id="597026007977", key=Commerce.TEST_COMMERCE_KEY, testing=False) self.assertEqual(webpay_encrypt.return_value, commerce.reject) webpay_encrypt.assert_called_once_with('ERR')
def test_acknowledge(self, webpay_encrypt): commerce = Commerce(id="597026007977", key=Commerce.TEST_COMMERCE_KEY, testing=False) self.assertEqual(webpay_encrypt.return_value, commerce.acknowledge) webpay_encrypt.assert_called_once_with('ACK')
def test_get_public_key(self): private_key = RSA.generate(2048) commerce_key = private_key.exportKey() commerce = Commerce(id="12345", key=commerce_key) self.assertEqual(private_key.publickey().exportKey(), commerce.get_public_key())