Пример #1
0
def test_fetch_tasks(session):  # pylint:disable=unused-argument
    """Assert that we can fetch all tasks."""
    user = factory_user_model()
    task_type = TaskTypePrefix.NEW_ACCOUNT_STAFF_REVIEW.value
    task = TaskModel(
        name='TEST',
        date_submitted=datetime.now(),
        relationship_type=TaskRelationshipType.ORG.value,
        relationship_id=10,
        type=task_type,
        due_date=datetime.now(),
        status=TaskStatus.OPEN.value,
        related_to=user.id,
        relationship_status=TaskRelationshipStatus.PENDING_STAFF_REVIEW.value)
    session.add(task)
    session.commit()
    found_tasks, count = TaskModel.fetch_tasks(
        task_relationship_status=TaskRelationshipStatus.PENDING_STAFF_REVIEW.
        value,
        task_type=task_type,
        task_status=TaskStatus.OPEN.value,
        page=1,
        limit=10)
    assert found_tasks
    assert count == 1

    for found_staff_task in found_tasks:
        assert found_staff_task.name == task.name
Пример #2
0
    def fetch_tasks(**kwargs):
        """Search all tasks."""
        task_type = kwargs.get('task_type')
        task_status = kwargs.get('task_status') or [TaskStatus.OPEN.value]
        task_relationship_status = kwargs.get('task_relationship_status')

        tasks = {'tasks': []}
        page: int = int(kwargs.get('page'))
        limit: int = int(kwargs.get('limit'))
        search_args = (task_type,
                       task_status,
                       task_relationship_status,
                       page,
                       limit)

        current_app.logger.debug('<fetch_tasks ')
        task_models, count = TaskModel.fetch_tasks(*search_args)  # pylint: disable=unused-variable

        if not task_models:
            return tasks

        for task in task_models:
            task_dict = Task(task).as_dict(exclude=['user'])
            tasks['tasks'].append(task_dict)

        tasks['total'] = count
        tasks['page'] = page
        tasks['limit'] = limit

        current_app.logger.debug('>fetch_tasks ')
        return tasks
Пример #3
0
def test_fetch_tasks_pagination(session):  # pylint:disable=unused-argument
    """Assert that we can fetch all tasks."""
    user = factory_user_model()
    factory_task_models(6, user.id)
    task_type = TaskTypePrefix.NEW_ACCOUNT_STAFF_REVIEW.value

    found_tasks, count = TaskModel.fetch_tasks(
        task_relationship_status=TaskRelationshipStatus.PENDING_STAFF_REVIEW.
        value,
        task_type=task_type,
        task_status=TaskStatus.OPEN.value,
        page=3,
        limit=2)
    assert found_tasks
    assert count == 6
Пример #4
0
def test_fetch_pending_tasks_descending(session):  # pylint:disable=unused-argument
    """Assert that we can fetch all tasks."""
    user = factory_user_model()
    task = TaskModel(
        name='TEST 1',
        date_submitted=datetime.now(),
        relationship_type=TaskRelationshipType.ORG.value,
        relationship_id=10,
        type=TaskTypePrefix.NEW_ACCOUNT_STAFF_REVIEW.value,
        status=TaskStatus.OPEN.value,
        related_to=user.id,
        relationship_status=TaskRelationshipStatus.PENDING_STAFF_REVIEW.value)
    task.save()
    task = TaskModel(
        name='TEST 2',
        date_submitted=datetime(2021, 5, 25),
        relationship_type=TaskRelationshipType.ORG.value,
        relationship_id=10,
        type=TaskTypePrefix.NEW_ACCOUNT_STAFF_REVIEW.value,
        status=TaskStatus.OPEN.value,
        related_to=user.id,
        relationship_status=TaskRelationshipStatus.PENDING_STAFF_REVIEW.value)
    task.save()
    task_type = TaskTypePrefix.NEW_ACCOUNT_STAFF_REVIEW.value

    found_tasks, count = TaskModel.fetch_tasks(
        task_relationship_status=TaskRelationshipStatus.PENDING_STAFF_REVIEW.
        value,
        task_type=task_type,
        task_status=TaskStatus.OPEN.value,
        page=1,
        limit=2)
    assert found_tasks
    assert found_tasks[0].name == 'TEST 2'
    assert found_tasks[1].name == 'TEST 1'
    assert count == 2