def test_successful_payment_creation(self): response = requests.Response() response._content = """{ "orderNumber": "12345", "token": "secret_token", "url": "https://payment.verkkomaksut.fi/payment/load/token/secret_token" }""" response.status_code = requests.codes.created client = Client() flexmock(client.session) client.session \ .should_receive('post') \ .with_args( 'https://payment.verkkomaksut.fi/api-payment/create', data='{"orderNumber": "12345"}', ) \ .and_return(response) payment = MockPayment(order_number='12345') assert client.create_payment(payment) == { 'order_number': '12345', 'token': 'secret_token', 'url': 'https://payment.verkkomaksut.fi/payment/load/token/' 'secret_token' }
def test_validate_payment_receipt_parameters_fail(self): client = Client() flexmock(client) \ .should_receive('_calculate_payment_receipt_hash') \ .with_args('order_number', 'timestamp', 'paid', 'method') \ .and_return('not_ok') assert not client._validate_payment_receipt_parameters( 'authcode', 'order_number', 'timestamp', 'paid', 'method')
def test_validate_payment_receipt_parameters_fail(self): client = Client() flexmock(client).should_receive("_calculate_payment_receipt_hash").with_args( "order_number", "timestamp", "paid", "method" ).and_return("not_ok") assert not client._validate_payment_receipt_parameters( "authcode", "order_number", "timestamp", "paid", "method" )
def test_payment_creation_failure(self): response = requests.Response() response._content = """{ "errorCode": "invalid-order-number", "errorMessage": "Missing or invalid order number" }""" response.status_code = requests.codes.bad_request client = Client() flexmock(client.session) client.session.should_receive("post").with_args( "https://payment.verkkomaksut.fi/api-payment/create", data='{"orderNumber": "12345"}' ).and_return(response) payment = MockPayment() with raises(VerkkomaksutException) as exc_info: client.create_payment(payment) assert exc_info.value.code == "invalid-order-number" assert exc_info.value.message == "Missing or invalid order number"
def test_successful_payment_creation(self): response = requests.Response() response._content = """{ "orderNumber": "12345", "token": "secret_token", "url": "https://payment.verkkomaksut.fi/payment/load/token/secret_token" }""" response.status_code = requests.codes.created client = Client() flexmock(client.session) client.session.should_receive("post").with_args( "https://payment.verkkomaksut.fi/api-payment/create", data='{"orderNumber": "12345"}' ).and_return(response) payment = MockPayment(order_number="12345") assert client.create_payment(payment) == { "order_number": "12345", "token": "secret_token", "url": "https://payment.verkkomaksut.fi/payment/load/token/" "secret_token", }
def test_payment_creation_failure(self): response = requests.Response() response._content = """{ "errorCode": "invalid-order-number", "errorMessage": "Missing or invalid order number" }""" response.status_code = requests.codes.bad_request client = Client() flexmock(client.session) client.session \ .should_receive('post') \ .with_args( 'https://payment.verkkomaksut.fi/api-payment/create', data='{"orderNumber": "12345"}', ) \ .and_return(response) payment = MockPayment() with raises(VerkkomaksutException) as exc_info: client.create_payment(payment) assert exc_info.value.code == 'invalid-order-number' assert exc_info.value.message == 'Missing or invalid order number'
def test_calculate_payment_receipt_hash(self): client = Client() hash_ = client._calculate_payment_receipt_hash('15153', '1176557554', '012345ABCDE', '1') assert hash_ == '555E0C0DE304938AACA5D594DB72F315'
def test_request_defines_api_version(self): client = Client() assert client.session.headers['X-Verkkomaksut-Api-Version'] == '1'
def test_request_accepts_json(self): client = Client() assert client.session.headers['Accept'] == 'application/json'
def test_request_content_type_is_json(self): client = Client() assert client.session.headers['Content-Type'] == 'application/json'
def test_custom_merchant_credentials(self): client = Client(merchant_id='12345', merchant_secret='secret') assert client.session.auth == ('12345', 'secret')
def test_defaults_to_merchant_test_account(self): client = Client() assert client.session.auth == \ ('13466', '6pKF4jkv97zmqBJ3ZL8gUw5DfT2NMQ')
def test_calculate_payment_receipt_hash(self): client = Client() hash_ = client._calculate_payment_receipt_hash("15153", "1176557554", "012345ABCDE", "1") assert hash_ == "555E0C0DE304938AACA5D594DB72F315"