Ejemplo n.º 1
0
def test_single_row_switch_handler(c):
    single_row(True)

    assert Office.get(0) is not None
    assert [Task.get(0)] == Office.get(0).tasks

    single_row(False)

    assert Office.get(0) is None
Ejemplo n.º 2
0
def test_single_row_switch_handler(c):
    with c.application.app_context():
        single_row(True)

        assert Office.get(0) is not None
        assert [Task.get(0)] == Office.get(0).tasks

        single_row(False)

        assert Office.get(0) is None
Ejemplo n.º 3
0
 def __init__(self, current_prefix=None, *args, **kwargs):
     super(OfficeForm, self).__init__(*args, **kwargs)
     prefixes = Office.get_all_available_prefixes()
     self.prefix.choices = [
         (p, p)
         for p in prefixes + (current_prefix and [current_prefix] or [])
     ]
Ejemplo n.º 4
0
Archivo: core.py Proyecto: picsldev/FQM
def test_pull_common_task_strict_pulling(_, c):
    with c.application.app_context():
        # NOTE: Finding the proper next common ticket to be pulled
        ticket_to_be_pulled = None
        tickets = Serial.query.order_by(Serial.number)\
                              .filter(Serial.number != 100, Serial.p != True)\
                              .all()

        for ticket in tickets:
            task = Task.get(ticket.task_id)
            office = Office.get(ticket.office_id)

            if task.common:
                ticket_to_be_pulled = ticket
                break

    response = c.get(f'/pull/{task.id}/{office.id}', follow_redirects=True)
    pulled_ticket = Serial.query.filter_by(number=ticket_to_be_pulled.number,
                                           office_id=office.id,
                                           task_id=task.id,
                                           p=True)\
                                .order_by(Serial.number)\
                                .first()

    assert response.status == '200 OK'
    assert pulled_ticket is not None
    assert pulled_ticket.task_id == task.id
    assert pulled_ticket.office_id == office.id
Ejemplo n.º 5
0
    def __init__(self, *args, **kwargs):
        super(UserForm, self).__init__(*args, **kwargs)
        self.offices.choices = [(o.id, f'{self.translate("Office : ")}{o.prefix}{o.name}')
                                for o in Office.query.all()]

        has_offices = bool(Office.get())
        for _id, role in USER_ROLES.items():
            if _id != 3 or has_offices:
                self.role.choices = (self.role.choices or []) + [(_id, role)]
Ejemplo n.º 6
0
def test_single_row_pulling(_, c):
    if not Settings.get().single_row:
        c.get('/settings/single_row', follow_redirects=True)

    assert Settings.get().single_row is True

    office = Office.get(0)
    tickets_length = office.tickets.count()
    last_number = getattr(
        office.tickets.order_by(Serial.timestamp.desc()).first(), 'number',
        100)

    response = c.get(f'/pull', follow_redirects=True)

    assert response.status == '200 OK'
    assert Office.get(0).tickets.count() - 1 == tickets_length
    assert Office.get(0).tickets.first().number - 1 == last_number
    assert Office.get(0).tickets.first().p is True
Ejemplo n.º 7
0
def fill_offices(entry_number=10):
    for _ in range(entry_number):
        prefix = choice([
            p
            for p in PREFIXES if not Office.query.filter_by(prefix=p).first()
        ] or [None]) or None

        prefix and db.session.add(Office(randint(10000, 9999999), prefix))

    db.session.commit()
Ejemplo n.º 8
0
def single_row(status):
    ''' `single_row` flag setting switch handler.

    Parameters
    ----------
        status: bool
            setting switched to status.
    '''
    office = Office.get(id=0)
    task = Task.get(id=0)

    if status:  # NOTE: Enabled
        office = office or Office.create_generic(id=0)
        task = task or Task.create_generic(id=0)

        task.offices.append(office)
        db.session.commit()
    else:
        office and office.delete_all()
Ejemplo n.º 9
0
    def getter():
        tickets = Serial.query.order_by(Serial.number)\
                              .filter(Serial.number != 100, Serial.p != True)\
                              .all()

        for ticket in tickets:
            task = Task.get(ticket.task_id)
            office = Office.get(ticket.office_id)

            if task.common:
                return ticket, office, task
Ejemplo n.º 10
0
def test_reset_office(c):
    ticket = Serial.query.order_by(Serial.number.desc()).first()
    office = Office.get(ticket.office_id)
    tickets = Serial.query.filter_by(office_id=office.id).all()

    response = c.get(f'/serial_r/{office.id}', follow_redirects=True)

    assert response.status == '200 OK'
    assert Serial.query.filter_by(office_id=office.id).count() != len(tickets)
    assert Serial.query.filter(Serial.office_id == office.id, Serial.number != 100)\
                       .count() == 0
Ejemplo n.º 11
0
def test_list_operators(c):
    bundles = []

    with c.application.app_context():
        bundles += [(User.get(o.id), Office.get(o.office_id))
                    for o in Operators.query.all()]

    for user, office in bundles:
        response = c.get(f'/operators/{office.id}')
        page_content = response.data.decode('utf-8')

        assert f'<strong>{user.id}. {user.name}</strong>' in page_content
Ejemplo n.º 12
0
def test_update_office(c):
    with c.application.app_context():
        office = choice(Office.query.all())
        office_name = office.name

    updated_office_name = 9999
    response = c.post(f'/offices/{office.id}',
                      data={'name': 9999},
                      follow_redirects=True)

    assert response.status == '200 OK'
    assert office_name != updated_office_name
    assert Office.get(office.id).name == office_name
Ejemplo n.º 13
0
def test_update_office(c):
    office = choice(Office.query.all())
    office_name = office.name
    updated_office_name = 'updated999'

    response = c.post(f'/offices/{office.id}',
                      data={
                          'name': updated_office_name,
                          'prefix': office.prefix
                      },
                      follow_redirects=True)

    assert response.status == '200 OK'
    assert office_name != updated_office_name
    assert Office.get(office.id).name == updated_office_name
Ejemplo n.º 14
0
        def post(self):
            ''' Generate a new ticket. '''
            registered = api.payload.get('n', False)
            name_or_number = api.payload.get('name', None)
            task = Task.get(api.payload.get('task_id', None))
            office = Office.get(api.payload.get('office_id', None))

            if not task:
                abort(message='Task not found', code=HTTPStatus.NOT_FOUND)

            if registered and not name_or_number:
                abort(message='Name must be entered for registered tickets.',
                      code=HTTPStatus.NOT_FOUND)

            ticket, exception = Serial.create_new_ticket(
                task, office, name_or_number)

            if exception:
                abort(message=str(exception))

            return ticket, HTTPStatus.OK
Ejemplo n.º 15
0
def test_delete_office_before_reset(c):
    office = get_first_office_with_tickets(c)
    response = c.get(f'/office_d/{office.id}', follow_redirects=True)

    assert response.status == '200 OK'
    assert Office.get(office.id) is not None