Ejemplo n.º 1
0
    def put(task_id):
        """Update a task."""
        request_json = request.get_json()
        token = g.jwt_oidc_token_info

        valid_format, errors = schema_utils.validate(request_json, 'task_request')
        if not valid_format:
            return {'message': schema_utils.serialize(errors)}, http_status.HTTP_400_BAD_REQUEST

        try:
            task = TaskService(TaskModel.find_by_task_id(task_id))
            if task:
                # Update task and its relationships
                origin = request.environ.get('HTTP_ORIGIN', 'localhost')
                response, status = task.update_task(task_info=request_json,
                                                    token_info=token,
                                                    origin_url=origin).as_dict(), http_status.HTTP_200_OK

            else:
                response, status = {'message': 'The requested task could not be found.'}, \
                                   http_status.HTTP_404_NOT_FOUND

        except BusinessException as exception:
            response, status = {'code': exception.code, 'message': exception.message}, exception.status_code
        return response, status
Ejemplo n.º 2
0
def test_update_task(session, keycloak_mock, monkeypatch):  # pylint:disable=unused-argument
    """Assert that a task can be updated."""
    user_with_token = TestUserInfo.user_bceid_tester
    user_with_token['keycloak_guid'] = TestJwtClaims.public_bceid_user['sub']
    user = factory_user_model_with_contact(user_with_token)

    patch_token_info(TestJwtClaims.public_bceid_user, monkeypatch)
    affidavit_info = TestAffidavit.get_test_affidavit_with_contact()
    AffidavitService.create_affidavit(affidavit_info=affidavit_info)
    org = OrgService.create_org(TestOrgInfo.org_with_mailing_address(),
                                user_id=user.id)
    org_dict = org.as_dict()
    assert org_dict['org_status'] == OrgStatus.PENDING_STAFF_REVIEW.value

    token_info = TestJwtClaims.get_test_user(sub=user.keycloak_guid,
                                             source=LoginSource.STAFF.value)
    patch_token_info(token_info, monkeypatch)

    tasks = TaskService.fetch_tasks(task_status=[TaskStatus.OPEN.value],
                                    page=1,
                                    limit=10)
    fetched_tasks = tasks['tasks']
    fetched_task = fetched_tasks[0]

    task_info = {'relationshipStatus': TaskRelationshipStatus.ACTIVE.value}
    task: TaskModel = TaskModel.find_by_task_id(fetched_task['id'])

    task = TaskService.update_task(TaskService(task), task_info=task_info)
    dictionary = task.as_dict()
    user = UserModel.find_by_id(user.id)
    assert dictionary['status'] == TaskStatus.COMPLETED.value
    assert dictionary[
        'relationship_status'] == TaskRelationshipStatus.ACTIVE.value
    assert user.verified
Ejemplo n.º 3
0
 def get(task_id):
     """Fetch task by id."""
     try:
         task = TaskService(TaskModel.find_by_task_id(task_id=task_id))
         response, status = task.as_dict(), http_status.HTTP_200_OK
     except BusinessException as exception:
         response, status = {'code': exception.code, 'message': exception.message}, exception.status_code
     return response, status
Ejemplo n.º 4
0
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