Tests and helpers
This commit is contained in:
+10
-4
@@ -1,5 +1,6 @@
|
||||
from uuid import uuid4
|
||||
from core.transaction import Transaction
|
||||
from utils.helpers import validate_pin, parse_price
|
||||
|
||||
|
||||
class Tracker:
|
||||
@@ -70,7 +71,7 @@ class Tracker:
|
||||
from uuid import uuid4
|
||||
from core.transaction import Transaction
|
||||
|
||||
transaction = Transaction(str(uuid4()), user_id, "adjustment", -amount)
|
||||
transaction = Transaction(str(uuid4()), user_id, "Abbuchung", -amount)
|
||||
self.transactions.append(transaction)
|
||||
self.data_manager.save_transactions(self.transactions)
|
||||
|
||||
@@ -97,12 +98,15 @@ class Tracker:
|
||||
def set_user_pin(self, user_id, pin):
|
||||
if user_id not in self.users:
|
||||
return {"status": "error", "message": "User not found"}
|
||||
if not validate_pin(pin):
|
||||
return {"status": "error", "message": "Invalid PIN format"}
|
||||
self.users[user_id].pin = pin
|
||||
self.data_manager.save_users(self.users)
|
||||
return {"status": "success", "message": "PIN updated successfully"}
|
||||
|
||||
def add_user(self, user_id, name):
|
||||
from core.user import User
|
||||
|
||||
if user_id in self.users:
|
||||
return {"status": "error", "message": "User ID already exists"}
|
||||
self.users[user_id] = User(user_id, name, "4242")
|
||||
@@ -123,6 +127,8 @@ class Tracker:
|
||||
def edit_user(self, user_id, name, pin=None):
|
||||
if user_id not in self.users:
|
||||
return {"status": "error", "message": "User not found"}
|
||||
if pin is not None and not validate_pin(pin):
|
||||
return {"status": "error", "message": "Invalid PIN format"}
|
||||
self.users[user_id].name = name
|
||||
if pin is not None:
|
||||
self.users[user_id].pin = pin
|
||||
@@ -131,10 +137,11 @@ class Tracker:
|
||||
|
||||
def add_item(self, item_id, name, price):
|
||||
from core.item import Item
|
||||
|
||||
if item_id in self.items:
|
||||
return {"status": "error", "message": "Item ID already exists"}
|
||||
try:
|
||||
price_val = float(price)
|
||||
price_val = parse_price(str(price))
|
||||
except ValueError:
|
||||
return {"status": "error", "message": "Invalid price value"}
|
||||
self.items[item_id] = Item(item_id, name, price_val)
|
||||
@@ -153,11 +160,10 @@ class Tracker:
|
||||
if item_id not in self.items:
|
||||
return {"status": "error", "message": "Item not found"}
|
||||
try:
|
||||
price_val = float(price)
|
||||
price_val = parse_price(str(price))
|
||||
except ValueError:
|
||||
return {"status": "error", "message": "Invalid price value"}
|
||||
self.items[item_id].name = name
|
||||
self.items[item_id].price = price_val
|
||||
self.data_manager.save_items(self.items)
|
||||
return {"status": "success", "message": f"Item {name} updated successfully"}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user