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
def create_task(task_info: dict, do_commit: bool = True): """Create a new task record.""" current_app.logger.debug('<create_task ') task_model = TaskModel(**camelback2snake(task_info)) task_model.flush() if do_commit: # Task mostly comes as a part of parent transaction.So do not commit unless asked. db.session.commit() current_app.logger.debug('>create_task ') return Task(task_model)
def factory_task_models(count: int, user_id: int): """Produce a collection of Task models.""" task_type = TaskTypePrefix.NEW_ACCOUNT_STAFF_REVIEW.value for i in range(0, count): task = TaskModel(name='TEST {}'.format(i), date_submitted=datetime.datetime.now(), relationship_type=TaskRelationshipType.ORG.value, relationship_id=10, type=task_type, status=TaskStatus.OPEN.value, related_to=user_id, relationship_status=TaskRelationshipStatus. PENDING_STAFF_REVIEW.value) task.save()
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
def factory_task_model(user_id: int = 1, org_id: int = 1): """Produce a Task model.""" task_type = TaskTypePrefix.NEW_ACCOUNT_STAFF_REVIEW.value task = TaskModel( id=1, name='foo', date_submitted=datetime.datetime.now(), relationship_type=TaskRelationshipType.ORG.value, relationship_id=org_id, type=task_type, status=TaskStatus.OPEN.value, related_to=user_id, relationship_status=TaskRelationshipStatus.PENDING_STAFF_REVIEW.value) task.save() return task
def test_task_model(session): """Assert that a task can be stored in the service.""" 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, status=TaskStatus.OPEN.value, related_to=user.id) session.add(task) session.commit() assert task.id is not None assert task.name == 'TEST'
def test_find_task_by_id(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) session.add(task) session.commit() found_task = TaskModel.find_by_task_id(task.id) assert found_task assert found_task.name == task.name
def test_finding_task_by_relationship_id(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() found_task = TaskModel.find_by_task_relationship_id( task_relationship_type=TaskRelationshipType.ORG.value, relationship_id=10) assert found_task assert found_task.name == 'TEST 1' assert found_task.relationship_id == 10 assert found_task.status == TaskStatus.OPEN.value
def test_find_by_task_for_user(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.USER.value, relationship_id=user.id, type=TaskTypePrefix.BCEID_ADMIN.value, status=TaskStatus.OPEN.value, related_to=user.id, account_id=10, relationship_status=TaskRelationshipStatus.PENDING_STAFF_REVIEW.value) task.save() found_task = TaskModel.find_by_user_and_status( org_id=10, status=TaskStatus.OPEN.value) assert found_task assert found_task.name == 'TEST 1' assert found_task.relationship_id == user.id assert found_task.status == TaskStatus.OPEN.value