def test_bank_is_successful(self): bank = Bank() payment = Payment() payment.source = "bank" payment.bank = bank self.assertTrue(payment.is_successful())
def test_is_successful(self): card = Card() card.status = "processed" payment = Payment(source='card') payment.card = card self.assertTrue(payment.is_successful())
def test_is_successful_declined(self): card = Card() card.status = "declined" payment = Payment(source='card') payment.card = card self.assertFalse(payment.is_successful())
def test_is_successful_errored(self): card = Card() card.status = "errored" payment = Payment() payment.card = card self.assertFalse(payment.is_successful())
def test_is_successful(self): bank = Bank() bank.status = "processed" payment = Payment() payment.source = "bank" payment.bank = bank self.assertTrue(payment.is_successful())
def test_is_successful_bank_payment(self): data = { "amount": "2000", "bank_account_id": "12345", "customer_id": "123", "date": "2019-02-01" } payment = Payment("bank", data) self.assertTrue(payment.is_successful())
def test_is_successful(self): data = { "amount": "2000", "card_id": "45", "card_status": "processed", "customer_id": "123", "date": "2019-02-01", } payment = Payment("card", data) self.assertTrue(payment.is_successful())
def get_payments(self, csv_path, source): payments = [] with open(csv_path) as f: reader = csv.DictReader(f) for row in reader: row.update({"source": source}) if source == 'bank': row.update({"bank_status": "processed"}) payments.append(Payment(row)) else: payments.append(Payment(row)) return payments
def test_init(self): payment = Payment() self.assertIsNone(payment.customer_id) self.assertIsNone(payment.date) self.assertIsNone(payment.amount) self.assertIsNone(payment.fee)
def test_init_with_data(self): payment_data = [({ "amount": "2000", "card_id": "45", "card_status": "processed", "customer_id": "123", "date": "2019-02-01", }, "card"), ({ "amount": "2000", "bank_account_id": "45", "customer_id": "123", "date": "2019-02-01" }, "bank")] for (data, source) in payment_data: payment = Payment(data, source) self.assertEqual(payment.customer_id, 123) self.assertEqual(payment.date, datetime(2019, 2, 1)) self.assertEqual(payment.amount, 1960) self.assertEqual(payment.fee, 40) if payment.card: card = payment.card self.assertIsInstance(card, Card) self.assertEqual(card.card_id, 45) self.assertEqual(card.status, "processed") if payment.bank: bank = payment.bank self.assertIsInstance(bank, Bank) self.assertEqual(bank.bank_account_id, "45") self.assertEqual(card.status, "processed")
def get_payments(self, csv_path, source): payments = [] with open(csv_path) as f: reader = csv.DictReader(f) for row in reader: payments.append(Payment(row, source)) return payments
def test_is_successful(self): card = Card() card.status = "processed" payment1 = Payment() payment1.card = card bank = Bank() bank.status = "processed" payment2 = Payment() payment2.bank = bank self.assertTrue(payment1.is_successful()) self.assertTrue(payment2.is_successful())
def test_init_with_data(self): card_data = { "amount": "2000", "card_id": "45", "card_status": "processed", "customer_id": "123", "date": "2019-02-01", } bank_data = { "amount": "900", "bank_account_id": "20", "customer_id": "123", "date": "2019-02-01", } card_payment = Payment(card_data, 'card') bank_payment = Payment(bank_data, 'bank') self.assertEqual(card_payment.customer_id, 123) self.assertEqual(card_payment.date, datetime(2019, 2, 1)) self.assertEqual(card_payment.amount, 1960) self.assertEqual(card_payment.fee, 40) self.assertEqual(bank_payment.customer_id, 123) self.assertEqual(bank_payment.date, datetime(2019, 2, 1)) self.assertEqual(bank_payment.amount, 882) self.assertEqual(bank_payment.fee, 18) card = card_payment.card bank_transfer = bank_payment.bank_transfer self.assertIsInstance(card, Card) self.assertEqual(card.card_id, 45) self.assertEqual(card.status, "processed") self.assertIsInstance(bank_transfer, BankTransfer) self.assertEqual(bank_transfer.bank_account_id, 20) self.assertEqual(bank_transfer.status, "pending")
def test_init_with_data(self): data = { "amount": "2000", "customer_id": "123", "date": "2019-02-01", } payment = Payment(data) self.assertEqual(payment.customer_id, 123) self.assertEqual(payment.date, datetime(2019, 2, 1)) self.assertEqual(payment.amount, 1960) self.assertEqual(payment.fee, 40)
def get_payments(self, csv_path, source): payments = [] with open(csv_path) as f: reader = csv.DictReader(f) for row in reader: ## this is where we make note of bank payments ## we change the header name to card_id since Payment only identifies card_id ## and we update transfer status if 'bank_account_id' in row: row["card_id"] = row["bank_account_id"] card_status = ["processed", "declined"] import random row["card_status"] = random.choice(card_status) payments.append(Payment(row)) return payments
def test_init_bank_account_with_data(self): data = { "amount": "2000", "bank_account_id": "50", "customer_id": "123", "date": "2019-02-01", } payment = Payment(data, "bank") self.assertEqual(payment.customer_id, 123) self.assertEqual(payment.date, datetime(2019, 2, 1)) self.assertEqual(payment.amount, 1960) self.assertEqual(payment.fee, 40) bank_account = payment.bank_account self.assertIsInstance(bank_account, BankAccount) self.assertEqual(bank_account.bank_account_id, 50) self.assertEqual(bank_account.is_successful(), True)
def test_init_with_data(self): data = { "amount": "2000", "card_id": "45", "card_status": "processed", "customer_id": "123", "date": "2019-02-01", } payment = Payment(data, "card") self.assertEqual(payment.customer_id, 123) self.assertEqual(payment.date, datetime(2019, 2, 1)) self.assertEqual(payment.amount, 1960) self.assertEqual(payment.fee, 40) card = payment.card self.assertIsInstance(card, Card) self.assertEqual(card.card_id, 45) self.assertEqual(card.status, "processed")
def test_init_with_data(self): data = { "amount": "2000", "bank_account_id": "45", "bank_status": "processed", "customer_id": "123", "date": "2019-02-01", "source": "bank", } payment = Payment(data) self.assertEqual(payment.customer_id, 123) self.assertEqual(payment.date, datetime(2019, 2, 1)) self.assertEqual(payment.amount, 1960) self.assertEqual(payment.fee, 40) bank = payment.bank self.assertIsInstance(bank, Bank) self.assertEqual(bank.bank_account_id, 45) self.assertEqual(bank.status, "processed")
def test_bank_is_successful(self): bank_account = BankAccount() payment = Payment() payment.bank_account = bank_account self.assertTrue(payment.is_successful())
def test_no_source_is_not_successful(self): card = Card() payment = Payment() payment.card = card self.assertFalse(payment.is_successful())
def create_payment(customer_id, amount): payment = Payment() payment.customer_id = customer_id payment.amount = amount return payment
def create_stub_payment(mock_is_successful): payment = Payment() payment.is_successful = lambda: mock_is_successful return payment