def test_payment_accepted_invalid_dict(self): """ Tests exception is thrown when params to payment_accepted don't have required key or have an bad value """ baseline = { 'orderNumber': '1', 'orderCurrency': 'usd', 'decision': 'ACCEPT', } wrong = { 'orderNumber': 'k', } # tests for missing key for key in baseline: params = baseline.copy() del params[key] with self.assertRaises(CCProcessorDataException): payment_accepted(params) # tests for keys with value that can't be converted to proper type for key in wrong: params = baseline.copy() params[key] = wrong[key] with self.assertRaises(CCProcessorDataException): payment_accepted(params)
def test_payment_accepted_order(self): """ Tests payment_accepted cases with an order """ student1 = UserFactory() student1.save() order1 = Order.get_cart_for_user(student1) params = { 'card_accountNumber': '1234', 'card_cardType': '001', 'billTo_firstName': student1.first_name, 'billTo_lastName': u"\u2603", 'orderNumber': str(order1.id), 'orderCurrency': 'usd', 'decision': 'ACCEPT', 'ccAuthReply_amount': '0.00' } # tests for an order number that doesn't match up params_bad_ordernum = params.copy() params_bad_ordernum['orderNumber'] = str(order1.id + 10) with self.assertRaises(CCProcessorDataException): payment_accepted(params_bad_ordernum) # tests for a reply amount of the wrong type params_wrong_type_amt = params.copy() params_wrong_type_amt['ccAuthReply_amount'] = 'ab' with self.assertRaises(CCProcessorDataException): payment_accepted(params_wrong_type_amt) # tests for a reply amount of the wrong type params_wrong_amt = params.copy() params_wrong_amt['ccAuthReply_amount'] = '1.00' with self.assertRaises(CCProcessorWrongAmountException): payment_accepted(params_wrong_amt) # tests for a not accepted order params_not_accepted = params.copy() params_not_accepted['decision'] = "REJECT" self.assertFalse(payment_accepted(params_not_accepted)['accepted']) # finally, tests an accepted order self.assertTrue(payment_accepted(params)['accepted'])