-
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.
- Loading branch information
1 parent
ec722f5
commit 22c56f2
Showing
8 changed files
with
113 additions
and
123 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
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 |
---|---|---|
|
@@ -2,26 +2,31 @@ | |
mock class | ||
""" | ||
|
||
from datetime import datetime, timedelta | ||
|
||
from car.service import CarService | ||
from chat.service import ChatService as _ | ||
from database.database import Base, db_session, engine, init_db | ||
from parking_lot.service import ParkingLotService | ||
from payment.service import PaymentService | ||
from reservation.service import ReservationService | ||
from database.database import db_session, engine, init_db | ||
from settings.service import SettingService | ||
from user.service import UserService | ||
|
||
from mock.seed_car import seed_car | ||
from mock.seed_chat import seed_chat | ||
from mock.seed_parking_lot import seed_parking_lot | ||
from mock.seed_reservation import seed_reservation | ||
from mock.seed_user import seed_user | ||
|
||
|
||
class Mock: | ||
# drop all | ||
@staticmethod | ||
def clean_db(): | ||
Base.metadata.drop_all(bind=engine) | ||
try: | ||
with engine.connect() as conn: | ||
conn.execute("SET FOREIGN_KEY_CHECKS=0") | ||
conn.execute( | ||
"DROP TABLE `cars`, `chats`, `chat_heads`, `invoices`, `parking_lots`, `reservations`, `settings`, `users`" | ||
) | ||
conn.execute("SET FOREIGN_KEY_CHECKS=1") | ||
except Exception as e: | ||
print(e) | ||
|
||
# setup database | ||
@staticmethod | ||
|
@@ -39,113 +44,16 @@ def mock(): | |
# mock chat | ||
seed_chat() | ||
|
||
# get root user | ||
user = UserService.find_by_email("[email protected]") | ||
|
||
# mock user car | ||
car_1 = CarService.add(user, "A11111", "Tesla") | ||
car_2 = CarService.add(user, "A22222", "Starship") | ||
car_3 = CarService.add(user, "A33333", "Falcon9") | ||
|
||
# get all car | ||
# user_cars = CarService.find_all_car_by_user(user) | ||
# for car in user_cars: | ||
# print(car) | ||
# mock car | ||
seed_car() | ||
|
||
# mock parking lot | ||
parking_lot_1 = ParkingLotService.add("Floor 1", True) | ||
parking_lot_2 = ParkingLotService.add("Floor 2", True) | ||
parking_lot_3 = ParkingLotService.add("Floor 3", False) | ||
|
||
for i in range(1, 11): | ||
# mock reservation | ||
reservation = ReservationService.create_reservation( | ||
user, car_1, parking_lot_1, datetime.utcnow() | ||
) | ||
|
||
if i < 10: | ||
# end created reservation | ||
ReservationService.end_reservation( | ||
reservation, reservation.start_time + timedelta(hours=1) | ||
) | ||
|
||
# create invoice | ||
invoice = PaymentService.create_invoice(reservation) | ||
invoice.charge_amount = PaymentService.calculate_charge(reservation) | ||
PaymentService.update_invoice(invoice) | ||
|
||
# try: | ||
# PaymentService.setup_payment() | ||
# invoice = PaymentService.create_invoice(reservation) | ||
|
||
# intent = PaymentService.create_pay_token(invoice) | ||
seed_parking_lot() | ||
|
||
# print(intent.client_secret) | ||
# print(intent.id) | ||
|
||
# PaymentService.handle_stripe_payment(intent) | ||
# except Exception as err: | ||
# print(err) | ||
|
||
# reservation_2 = ReservationService.create_reservation( | ||
# user, | ||
# car_1, | ||
# parking_lot_1, | ||
# datetime.utcnow() | ||
# ) | ||
|
||
# reservation_2 = ReservationService.create_reservation( | ||
# user, | ||
# car_2, | ||
# parking_lot_2, | ||
# datetime.utcnow() | ||
# ) | ||
|
||
# reservation_3 = ReservationService.create_reservation( | ||
# user, | ||
# car_3, | ||
# parking_lot_3, | ||
# datetime.utcnow() | ||
# ) | ||
|
||
# debug | ||
# print(ParkingLotService.is_parking_lot_available(parking_lot_1)) | ||
# print(ParkingLotService.is_parking_lot_available(parking_lot_2)) | ||
# print(ParkingLotService.is_parking_lot_available(parking_lot_3)) | ||
|
||
# try create reservation on busy parking lot | ||
# try: | ||
# ReservationService.create_reservation( | ||
# user, | ||
# car_1, | ||
# parking_lot_1, | ||
# datetime.utcnow() | ||
# ) | ||
# except Exception as e: | ||
# print(e) | ||
|
||
# try: | ||
# ReservationService.end_reservation(reservation_2) | ||
# t2_reserve = ReservationService.create_reservation( | ||
# user, | ||
# car_2, | ||
# parking_lot_2, | ||
# datetime.utcnow() | ||
# ) | ||
# ReservationService.end_reservation(t2_reserve) | ||
# except Exception as e: | ||
# print(e) | ||
|
||
# try: | ||
# t_reserve = ReservationService.create_reservation( | ||
# user, | ||
# car_3, | ||
# parking_lot_3, | ||
# datetime.utcnow() | ||
# ) | ||
# ReservationService.end_reservation(t_reserve) | ||
# except Exception as e: | ||
# print(e) | ||
# mock reservation | ||
seed_reservation() | ||
|
||
# remove database session | ||
db_session.remove() | ||
|
||
print("Mocking complete!") |
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,18 @@ | ||
""" | ||
seed car | ||
""" | ||
|
||
|
||
def seed_car(): | ||
from car.service import CarService | ||
from user.service import UserService | ||
|
||
print("Mocking car...") | ||
|
||
# get root user | ||
user = UserService.find_by_email("[email protected]") | ||
|
||
# mock user car | ||
CarService.add(user, "A11111", "Tesla") | ||
CarService.add(user, "A22222", "Starship") | ||
CarService.add(user, "A33333", "Falcon9") |
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,13 @@ | ||
""" | ||
seed parking lot | ||
""" | ||
|
||
|
||
def seed_parking_lot(): | ||
from parking_lot.service import ParkingLotService | ||
|
||
print("Mocking parking lot...") | ||
|
||
ParkingLotService.add("Floor 1", True) | ||
ParkingLotService.add("Floor 2", True) | ||
ParkingLotService.add("Floor 3", False) |
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,36 @@ | ||
""" | ||
seed reservation | ||
""" | ||
|
||
|
||
def seed_reservation(): | ||
print("Mocking reservation...") | ||
|
||
from datetime import datetime, timedelta | ||
|
||
from car.service import CarService | ||
from parking_lot.service import ParkingLotService | ||
from payment.service import PaymentService | ||
from reservation.service import ReservationService | ||
from user.service import UserService | ||
|
||
user = UserService.find_by_id(2) | ||
car_1 = CarService.find_by_id(1) | ||
parking_lot_1 = ParkingLotService.find_by_id(1) | ||
|
||
for i in range(1, 11): | ||
# mock reservation | ||
reservation = ReservationService.create_reservation( | ||
user, car_1, parking_lot_1, datetime.utcnow() | ||
) | ||
|
||
if i < 10: | ||
# end created reservation | ||
ReservationService.end_reservation( | ||
reservation, reservation.start_time + timedelta(hours=1) | ||
) | ||
|
||
# create invoice | ||
invoice = PaymentService.create_invoice(reservation) | ||
invoice.charge_amount = PaymentService.calculate_charge(reservation) | ||
PaymentService.update_invoice(invoice) |
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 |
---|---|---|
|
@@ -6,7 +6,9 @@ | |
def seed_user(): | ||
from user.service import UserService | ||
|
||
root = UserService.register( | ||
print("Mocking user...") | ||
|
||
UserService.register( | ||
"[email protected]", | ||
"root-password", | ||
"root", | ||
|
@@ -15,7 +17,8 @@ def seed_user(): | |
"0000000000", | ||
"0000000000000", | ||
) | ||
annie = UserService.register( | ||
|
||
UserService.register( | ||
"[email protected]", | ||
"annie-password", | ||
"annie", | ||
|
@@ -24,7 +27,8 @@ def seed_user(): | |
"1111111111", | ||
"1111111111111", | ||
) | ||
bobbie = UserService.register( | ||
|
||
UserService.register( | ||
"[email protected]", | ||
"bobbie-password", | ||
"bobbie", | ||
|
@@ -33,7 +37,8 @@ def seed_user(): | |
"2222222222", | ||
"2222222222222", | ||
) | ||
charlie = UserService.register( | ||
|
||
UserService.register( | ||
"[email protected]", | ||
"charlie-password", | ||
"charlie", | ||
|
@@ -42,3 +47,4 @@ def seed_user(): | |
"3333333333", | ||
"3333333333333", | ||
) | ||
|
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