class TestPaymentProcessor(unittest.TestCase): def setUp(self): self.payment_processor = PaymentProcessor() def test_get_payments(self): fixture = get_path("card_payments_mixed.csv") payments = self.payment_processor.get_payments(fixture, "card") self.assertEqual(len(payments), 3) self.assertEqual(payments[0].card.card_id, 30) self.assertEqual(payments[1].card.card_id, 45) self.assertEqual(payments[2].card.card_id, 10) def test_get_payments_empty(self): fixture = get_path("card_payments_empty.csv") payments = self.payment_processor.get_payments(fixture, "card") self.assertEqual(len(payments), 0) def test_verify_payments(self): payment1 = create_stub_payment(mock_is_successful=True) payment2 = create_stub_payment(mock_is_successful=False) payment3 = create_stub_payment(mock_is_successful=True) result = self.payment_processor.verify_payments( [payment1, payment2, payment3]) self.assertEqual(result, [payment1, payment3])
def main(csv_path, source, share_price): payment_processor = PaymentProcessor() payments = payment_processor.get_payments(csv_path, source) eligible_payments = payment_processor.verify_payments(payments) share_engine = ShareEngine() share_orders = share_engine.generate_share_orders(share_price, eligible_payments) return generate_csv(["customer_id", "shares"], sorted(share_orders))
class TestBankPaymentProcessor(unittest.TestCase): def setUp(self): self.payment_processor = PaymentProcessor() def test_get_payments(self): fixture = get_path("bank_payments_data.csv") payments = self.payment_processor.get_payments(fixture, "bank") self.assertEqual(len(payments), 2) self.assertEqual(payments[0].bank_account.bank_account_id, 20) self.assertEqual(payments[1].bank_account.bank_account_id, 60) def test_verify_payments(self): payment1 = create_stub_payment(mock_is_successful=True) payment2 = create_stub_payment(mock_is_successful=True) result = self.payment_processor.verify_payments([payment1, payment2]) self.assertEqual(result, [payment1, payment2])
class TestPaymentProcessor(unittest.TestCase): def setUp(self): self.payment_processor = PaymentProcessor() self.card_fixture = get_path("card_payments_mixed.csv") self.bank_fixture = get_path("bank_payments.csv") self.empty_card_fixture = get_path("card_payments_empty.csv") self.empty_bank_fixture = get_path("bank_payments_empty.csv") def test_get_payments(self): card_payments = self.payment_processor.get_payments( self.card_fixture, "card") self.assertEqual(len(card_payments), 3) self.assertEqual(card_payments[0].card.card_id, 30) self.assertEqual(card_payments[1].card.card_id, 45) self.assertEqual(card_payments[2].card.card_id, 10) bank_payments = self.payment_processor.get_payments( self.bank_fixture, "bank") self.assertEqual(len(bank_payments), 2) self.assertEqual(bank_payments[0].bank.bank_account_id, '20') self.assertEqual(bank_payments[1].bank.bank_account_id, '60') def test_get_payments_empty(self): card_payments = self.payment_processor.get_payments( self.empty_card_fixture, "card") bank_payments = self.payment_processor.get_payments( self.empty_bank_fixture, "bank") self.assertEqual(len(bank_payments), 0) self.assertEqual(len(card_payments), 0) def test_verify_payments(self): payment1 = create_stub_payment(mock_is_successful=True) payment2 = create_stub_payment(mock_is_successful=False) payment3 = create_stub_payment(mock_is_successful=True) result = self.payment_processor.verify_payments( [payment1, payment2, payment3]) self.assertEqual(result, [payment1, payment3])
class TestPaymentProcessor(unittest.TestCase): def setUp(self): self.payment_processor = PaymentProcessor() def test_get_payments(self): fixture = get_path("card_payments_mixed.csv") payments = self.payment_processor.get_payments(fixture, "card") self.assertEqual(len(payments), 3) self.assertEqual(payments[0].card.card_id, 30) self.assertEqual(payments[1].card.card_id, 45) self.assertEqual(payments[2].card.card_id, 10) def test_get_payments_empty(self): fixture = get_path("card_payments_empty.csv") payments = self.payment_processor.get_payments(fixture, "card") self.assertEqual(len(payments), 0) def test_verify_payments(self): payment1 = create_stub_payment(mock_is_successful=True) payment2 = create_stub_payment(mock_is_successful=False) payment3 = create_stub_payment(mock_is_successful=True) result = self.payment_processor.verify_payments( [payment1, payment2, payment3]) self.assertEqual(result, [payment1, payment3]) def test_get_available_card_handler(self): """Test getting a payment handler that is implemented""" payment_handler_class = self.payment_processor.payment_handler.create_instance( "card") self.assertEqual(payment_handler_class, CardPayment) def test_get_available_bank_handler(self): """Test getting a payment handler that is implemented""" payment_handler_class = self.payment_processor.payment_handler.create_instance( "bank") self.assertEqual(payment_handler_class, BankPayment)