From 47208a7259f61855e43a6453e916d0172474933b Mon Sep 17 00:00:00 2001 From: "sentry-autofix[bot]" <157164994+sentry-autofix[bot]@users.noreply.github.com> Date: Wed, 30 Oct 2024 14:56:46 +0000 Subject: [PATCH 1/3] Add unit tests for BankAccount class --- billing/tests/test_accounts.py | 58 ++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 billing/tests/test_accounts.py diff --git a/billing/tests/test_accounts.py b/billing/tests/test_accounts.py new file mode 100644 index 0000000000..8e821c271b --- /dev/null +++ b/billing/tests/test_accounts.py @@ -0,0 +1,58 @@ +import unittest +from billing.accounts import BankAccount + +class TestBankAccount(unittest.TestCase): + def setUp(self): + self.account = BankAccount("John Doe", 100.0) + + def test_init(self): + self.assertEqual(self.account.owner, "John Doe") + self.assertEqual(self.account.balance, 100.0) + with self.assertRaises(ValueError): + BankAccount("Jane Doe", -50.0) + + def test_deposit(self): + new_balance = self.account.deposit(50.0) + self.assertEqual(new_balance, 150.0) + self.assertEqual(self.account.balance, 150.0) + with self.assertRaises(ValueError): + self.account.deposit(-10.0) + with self.assertRaises(ValueError): + self.account.deposit(0) + + def test_withdraw(self): + new_balance = self.account.withdraw(50.0) + self.assertEqual(new_balance, 50.0) + self.assertEqual(self.account.balance, 50.0) + with self.assertRaises(ValueError): + self.account.withdraw(-10.0) + with self.assertRaises(ValueError): + self.account.withdraw(0) + with self.assertRaises(ValueError): + self.account.withdraw(1000.0) + + def test_transfer(self): + other_account = BankAccount("Jane Doe", 50.0) + balances = self.account.transfer(other_account, 30.0) + self.assertEqual(balances, (70.0, 80.0)) + self.assertEqual(self.account.balance, 70.0) + self.assertEqual(other_account.balance, 80.0) + + with self.assertRaises(ValueError): + self.account.transfer(other_account, -10.0) + with self.assertRaises(ValueError): + self.account.transfer(other_account, 0) + with self.assertRaises(ValueError): + self.account.transfer(other_account, 1000.0) + with self.assertRaises(ValueError): + self.account.transfer("not an account", 10.0) + + def test_get_balance(self): + self.assertEqual(self.account.get_balance(), 100.0) + self.account.deposit(50.0) + self.assertEqual(self.account.get_balance(), 150.0) + self.account.withdraw(30.0) + self.assertEqual(self.account.get_balance(), 120.0) + +if __name__ == '__main__': + unittest.main() \ No newline at end of file From 39cb82dea3639c2589a29b0792a52344c80894e1 Mon Sep 17 00:00:00 2001 From: Rohit Date: Wed, 30 Oct 2024 11:15:40 -0400 Subject: [PATCH 2/3] Lint --- billing/tests/test_accounts.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/billing/tests/test_accounts.py b/billing/tests/test_accounts.py index 8e821c271b..bd6e00aade 100644 --- a/billing/tests/test_accounts.py +++ b/billing/tests/test_accounts.py @@ -1,6 +1,7 @@ import unittest from billing.accounts import BankAccount + class TestBankAccount(unittest.TestCase): def setUp(self): self.account = BankAccount("John Doe", 100.0) @@ -54,5 +55,6 @@ def test_get_balance(self): self.account.withdraw(30.0) self.assertEqual(self.account.get_balance(), 120.0) -if __name__ == '__main__': - unittest.main() \ No newline at end of file + +if __name__ == "__main__": + unittest.main() From c6c45896eb9e9fed2b967355a1993883f6f7f39d Mon Sep 17 00:00:00 2001 From: Rohit Date: Wed, 30 Oct 2024 11:22:14 -0400 Subject: [PATCH 3/3] Sort import --- billing/tests/test_accounts.py | 1 + 1 file changed, 1 insertion(+) diff --git a/billing/tests/test_accounts.py b/billing/tests/test_accounts.py index bd6e00aade..6960c5af93 100644 --- a/billing/tests/test_accounts.py +++ b/billing/tests/test_accounts.py @@ -1,4 +1,5 @@ import unittest + from billing.accounts import BankAccount