-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix test with coins - refill should be tested again
- Loading branch information
euhoro
committed
Jun 17, 2024
1 parent
72d739f
commit 88cffce
Showing
5 changed files
with
105 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import unittest | ||
|
||
from atm_repository_file import FileInventoryService | ||
from atm_service import ATMService, ERR_INSUFFICIENT_FUNDS, ERR_TOO_MANY_COINS | ||
from fastapi.testclient import TestClient | ||
|
||
from main import app | ||
|
||
|
||
class TestATMService(unittest.TestCase): | ||
def setUp(self): | ||
#self.client = TestClient(app) | ||
#self.client.post("/atm/restart") | ||
pass | ||
|
||
# def test_too_many_coins(self): | ||
# #response = self.client.post("/atm/withdrawal", json={"amount": 0.9}) | ||
# #response = self.client.post("/atm/withdrawal", json={"amount": 0.4}) | ||
# | ||
# refill_amount = {"0.01": 1000} | ||
# initial_inventory = self.client.get("/atm/inventory").json() | ||
# self.client.post("/atm/refill", json={"money": refill_amount}) | ||
# updated_inventory = self.client.get("/atm/inventory").json() | ||
# | ||
# | ||
# response = self.client.post("/atm/withdrawal", json={"amount": 0.9}) | ||
# response = self.client.post("/atm/withdrawal", json={"amount": 0.1}) | ||
# response = self.client.post("/atm/withdrawal", json={"amount": 0.1}) | ||
# response = self.client.post("/atm/withdrawal", json={"amount": 21.61}) | ||
# #response = self.client.post("/atm/withdrawal", json={"amount": 21.61}) | ||
# | ||
# assert response.status_code == 422 | ||
# assert ERR_TOO_MANY_COINS in response.json()["detail"] | ||
|
||
def test_not_enough(self): | ||
self.client = TestClient(app) | ||
response = self.client.post("/atm/withdrawal", json={"amount": 1000}) | ||
response = self.client.post("/atm/withdrawal", json={"amount": 1000}) | ||
response = self.client.post("/atm/withdrawal", json={"amount": 1000}) | ||
assert response.status_code == 409 | ||
assert ERR_INSUFFICIENT_FUNDS in response.json()["detail"] | ||
|
||
def test_max(self): | ||
self.client = TestClient(app) | ||
response = self.client.post("/atm/withdrawal", json={"amount": 3000}) | ||
assert response.status_code == 422 | ||
assert response.json()["detail"] == "Amount exceeds the maximum withdrawal limit of 2000" | ||
|
||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# import unittest | ||
# | ||
# from atm_repository_file import FileInventoryService | ||
# from atm_service import ATMService, ERR_INSUFFICIENT_FUNDS, ERR_TOO_MANY_COINS | ||
# from fastapi.testclient import TestClient | ||
# | ||
# from main import app | ||
# | ||
# | ||
# class TestATMService(unittest.TestCase): | ||
# def setUp(self): | ||
# #self.client = TestClient(app) | ||
# #self.client.post("/atm/restart") | ||
# pass | ||
# | ||
# def test_refill(self): | ||
# self.client = TestClient(app) | ||
# self.client.post("/atm/restart") | ||
# initial_inventory = self.client.get("/atm/inventory").json() | ||
# #self.client.post("/atm/restart") | ||
# bill_100 = 30 | ||
# num_5 = 30 | ||
# num_01 = 5 | ||
# bill_20 = 15 | ||
# refill_amount = {"0.1": num_01, "5": num_5, "20": bill_20, "100": bill_100} | ||
# initial_inventory = self.client.get("/atm/inventory").json() | ||
# self.client.post("/atm/refill", json={"money": refill_amount}) | ||
# updated_inventory = self.client.get("/atm/inventory").json() | ||
# | ||
# assert initial_inventory != updated_inventory | ||
# assert initial_inventory['result']['bills']['100.0'] + bill_100 == updated_inventory['result']['bills']['100.0'] | ||
# assert initial_inventory['result']['bills']['20.0'] + bill_20 == updated_inventory['result']['bills']['20.0'] | ||
# assert initial_inventory['result']['coins']['0.1'] + num_01 == updated_inventory['result']['coins']['0.1'] | ||
# assert initial_inventory['result']['coins']['5.0'] + num_5 == updated_inventory['result']['coins']['5.0'] | ||
# | ||
# | ||
# if __name__ == "__main__": | ||
# unittest.main() |