Example #1
0
def fill_tasks(entry_number=10):
    for _ in range(entry_number):
        name = f'TEST{randint(10000, 99999999)}'
        offices = []
        # First task will be uncommon task
        number_of_offices = 1 if _ == 0 else choice(range(1, 5))

        while number_of_offices > len(offices):
            office = choice(Office.query.all())

            if office not in offices:
                offices.append(office)
        
        task = Task(name)
        db.session.add(task)
        db.session.commit()
        task.offices = offices
        db.session.commit()


# TODO: get refactor the helper to fit the testing process
# def fill_tickets(entery_number=10, s_task=None):
#     for i in range(entery_number):
#         forin = Task.query if s_task is None else Task.query.filter_by(
#             id=s_task)
#         for task in forin:
#             num = Serial.query.order_by(Serial.timestamp.desc()).first()
#             num = num.number if num is not None else None
#             name = choice(names)
#             t_id = task.id
#             f_id = choice(task.offices).id
#             # if i >= 11: WTF ?!
#             db.session.add(Serial(number=num + 1,
#                                     office_id=f_id,
#                                     task_id=t_id, name=name, n=True))
#     for a in range(Waiting.query.count(), 11):
#         for b in Serial.query.filter_by(p=False).order_by(Serial.timestamp):
#             if Waiting.query.filter_by(office_id=b.office_id,
#                                        number=b.number,
#                                        task_id=b.task_id).first() is None:
#                 db.session.add(Waiting(b.number, b.office_id,
#                                        b.task_id, b.name, b.n))
#     db.session.commit()
Example #2
0
def fill_tasks(entry_number=ENTRY_NUMBER):
    for _ in range(entry_number):
        name = f'TEST{randint(10000, 99999999)}'
        offices = []
        # First task will be uncommon task and the second is common
        number_of_offices = 1 if _ == 0 else 2 if _ == 1 else choice(range(1, 5))

        while number_of_offices > len(offices):
            office = choice(Office.query.all())

            if office not in offices:
                offices.append(office)

        task = Task(name)
        db.session.add(task)
        db.session.commit()
        task.offices = offices
        # Add tasks initial tickets
        db.session.add(Serial(number=100, office_id=office.id, task_id=task.id))
        db.session.commit()