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 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_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
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