mock script, og mock data.

This commit is contained in:
Albert Bayazidi 2025-03-29 22:48:30 +01:00
parent b2a6384f31
commit e69d04dcd0
3 changed files with 121 additions and 0 deletions

@ -20,6 +20,7 @@ subparsers = parser.add_subparsers(
subparsers.add_parser("loop", help="Run the dibbler loop")
subparsers.add_parser("create-db", help="Create the database")
subparsers.add_parser("slabbedasker", help="Find out who is slabbedasker")
subparsers.add_parser("seed-data",help="Fill with mock data")
def main():
@ -40,6 +41,12 @@ def main():
import dibbler.subcommands.slabbedasker as slabbedasker
slabbedasker.main()
elif args.subcommand == "seed-data":
import dibbler.subcommands.seed_test_data as seed_test_data
seed_test_data.main()
if __name__ == "__main__":

@ -0,0 +1,38 @@
import json
from dibbler.db import Session
from pathlib import Path
from dibbler.models.Product import Product
from dibbler.models.User import User
JSON_FILE = Path(__file__).parent.parent.parent/"mock_data.json"
def clear_db(session):
session.query(Product).delete()
session.query(User).delete()
session.commit()
def main() :
session = Session()
clear_db(session)
product_items = []
user_items = []
with open(JSON_FILE) as f:
json_obj = json.load(f)
for product in json_obj["products"]:
product_item = Product(bar_code=product["bar_code"], name=product["name"], price=product["price"], stock=product["stock"])
product_items.append(product_item)
for user in json_obj["users"]:
user_item = User(name=user ["name"], card=user [ "card" ], rfid=user [ "rfid" ], credit=user ["credit"])
user_items.append(user_item)
session.add_all(product_items)
session.add_all(user_items)
session.commit()

76
mock_data.json Normal file

@ -0,0 +1,76 @@
{
"products": [
{
"product_id": 1,
"bar_code": "1234567890123",
"name": "Wireless Mouse",
"price": 2999,
"stock": 150,
"hidden": false
},
{
"product_id": 2,
"bar_code": "9876543210987",
"name": "Mechanical Keyboard",
"price": 5999,
"stock": 75,
"hidden": false
},
{
"product_id": 3,
"bar_code": "1112223334445",
"name": "Gaming Monitor",
"price": 19999,
"stock": 20,
"hidden": false
},
{
"product_id": 4,
"bar_code": "5556667778889",
"name": "USB-C Docking Station",
"price": 8999,
"stock": 50,
"hidden": true
},
{
"product_id": 5,
"bar_code": "4445556667771",
"name": "Noise Cancelling Headphones",
"price": 12999,
"stock": 30,
"hidden": true
}
],
"users": [
{
"name": "Albert",
"credit": 42069,
"card": "NTU12345678",
"rfid": "a1b2c3d4e5"
},
{
"name": "lorem",
"credit": 2000,
"card": "9876543210",
"rfid": "f6e7d8c9b0"
},
{
"name": "ibsum",
"credit": 1000,
"card": "11122233",
"rfid": ""
},
{
"name": "dave",
"credit": 7500,
"card": "NTU56789012",
"rfid": "1234abcd5678"
},
{
"name": "eve",
"credit": 3000,
"card": null,
"rfid": "deadbeef1234"
}
]
}