"""testing subjects utils""" import random from sqlalchemy.orm import Session from db.repository import subjects as db_rep_sub from schemas.subjects import SubjectCreate from utils.utils import fake def generate_subject_fake_data(): return { "name": fake.name(), "id_card": None, "birthday": str(fake.date_between_dates(date_start="-100y", date_end="-5y")), "gender": fake.subject_gender(), "rehabilitation_parts": fake.rehabilitation_parts() } def create_test_subject2db(db: Session, name=fake.name(), id_card=None, gender=fake.subject_gender(), birthday=fake.date_between_dates(date_start="-100y", date_end="-5y"), rehabilitation_parts=fake.rehabilitation_parts(), create_time=None) -> SubjectCreate: if create_time is None: subject = SubjectCreate(name=name, id_card=id_card, gender=gender, birthday=birthday, rehabilitation_parts=rehabilitation_parts) else: subject = SubjectCreate(name=name, id_card=id_card, gender=gender, birthday=birthday, rehabilitation_parts=rehabilitation_parts, create_time=create_time) subject = db_rep_sub.create_subject(subject, db) return subject def get_all_subject(db: Session): return db_rep_sub.list_subjects(db=db) def get_random_existing_subject(db: Session): subjects = get_all_subject(db) return random.choice(subjects)