Skip to content

Commit

Permalink
fix refill
Browse files Browse the repository at this point in the history
  • Loading branch information
euhoro committed Jun 17, 2024
1 parent 88cffce commit b3158f8
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 38 deletions.
6 changes: 6 additions & 0 deletions tests/test_atm_service_fast_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ def test_max(self):
assert response.status_code == 422
assert response.json()["detail"] == "Amount exceeds the maximum withdrawal limit of 2000"

def test_bad(self):
self.client = TestClient(app)
response = self.client.post("/atm/withdrawal", json={})
assert response.status_code == 422
assert response.json()["detail"] == "Amount exceeds the maximum withdrawal limit of 2000"



if __name__ == "__main__":
Expand Down
76 changes: 38 additions & 38 deletions tests/test_atm_service_fast_api_refill.py
Original file line number Diff line number Diff line change
@@ -1,38 +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()
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()
result = 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()

0 comments on commit b3158f8

Please sign in to comment.