示例#1
0
def test_job_seekers_crud_against_dynamo_db(endpoint_url):
    assert os.environ["JOB_SEEKERS_TABLE_NAME"] is not None
    print("\nseekers_table: ", os.environ["JOB_SEEKERS_TABLE_NAME"])

    job_seeker_id = str(uuid.uuid4())
    full_name = str(uuid.uuid4())
    address = str(uuid.uuid4())
    about_me = str(uuid.uuid4())
    job_ambitions = str(uuid.uuid4())
    hobbies = str(uuid.uuid4())
    job_seeker_dict = {
        "id": job_seeker_id,
        "full_name": full_name,
        "birth_date": 11003484,
        "address": address,
        "email": "*****@*****.**",
        "about_me": about_me,
        "job_ambitions": job_ambitions,
        "hobbies": hobbies
    }
    job_seeker = JobSeeker(**job_seeker_dict)
    job_seeker_repository.create(job_seeker=job_seeker, user="******")

    job_seeker_read = JobSeeker(**job_seeker_repository.get(
        job_seeker_id=job_seeker_id))

    assert job_seeker_read.creationTime is not None
    assert job_seeker_read.version == 0
    assert job_seeker_read.id == job_seeker_id
    assert job_seeker_read.address == address
    assert job_seeker_read.about_me == about_me
    assert job_seeker_read.job_ambitions == job_ambitions
    assert job_seeker_read.hobbies == hobbies

    # job_seeker_dict = job_seeker_repository.get(job_seeker_id)

    job_seeker_read.address = "new address"
    job_seeker_repository.update(job_seeker_read, user="******")

    job_seeker_read = JobSeeker(**job_seeker_repository.get(
        job_seeker_id=job_seeker_id))
    assert job_seeker_read.address == "new address"
    assert job_seeker_read.version == 1

    # delete and validate it does not exist
    job_seeker_repository.delete(job_seeker_id)
    try:
        JobSeeker(**job_seeker_repository.get(job_seeker_id=job_seeker_id))
        raise Exception("Expected NotFoundError")
    except NotFoundError:
        # all good
        pass
示例#2
0
def get_seeker_summary(event: dict, context: LambdaContext) -> dict:
    try:
        event: APIGatewayProxyEvent = APIGatewayProxyEvent(event)
        user_id = event.request_context.authorizer.claims["sub"]

        # convert to model
        job_seeker: JobSeeker = JobSeeker(**job_seeker_repository.get(user_id))

        job_seeker_experience_list: List[
            Experience] = job_seeker_experience_repository.get_all(user_id)

        job_seeker_answers = None

        try:
            job_seeker_answers: JobSeekerAnswers = \
                JobSeekerAnswers(**job_seeker_answers_repository.get_by_seeker_id(user_id))
        except NotFoundError:
            pass

        # TODO convert to resource
        resource: JobSeekerResource = JobSeekerResource(
            profile=job_seeker,
            experience_list=job_seeker_experience_list,
            answers=job_seeker_answers)
        # return resource
        return _build_response(http_status=HTTPStatus.OK, body=resource.json())
    except (ValidationError, TypeError) as err:
        return _build_error_response(err, HTTPStatus.BAD_REQUEST)
    except Exception as err:
        return _build_error_response(err)
示例#3
0
def get_seeker_profile_with_id(event: dict, context: LambdaContext) -> dict:
    try:
        job_seeker_id = event["pathParameters"]["id"]

        # convert to model
        job_seeker: JobSeeker = JobSeeker(
            **job_seeker_repository.get(job_seeker_id))

        # TODO convert to resource
        job_seeker.birth_date = int(job_seeker.birth_date)
        job_seeker.version = int(job_seeker.version)
        # return resource
        return _build_response(http_status=HTTPStatus.OK,
                               body=json.dumps(job_seeker.as_dict()))
    except (ValidationError, TypeError) as err:
        return _build_error_response(err, HTTPStatus.BAD_REQUEST)
    except Exception as err:
        return _build_error_response(err)
示例#4
0
def get_seeker_profile(event: dict, context: LambdaContext) -> dict:
    try:
        event: APIGatewayProxyEvent = APIGatewayProxyEvent(event)
        user_id = event.request_context.authorizer.claims["sub"]

        # convert to model
        job_seeker: JobSeeker = JobSeeker(**job_seeker_repository.get(user_id))

        # TODO convert to resource
        job_seeker.birth_date = int(job_seeker.birth_date)
        job_seeker.version = int(job_seeker.version)
        # return resource
        return _build_response(http_status=HTTPStatus.OK,
                               body=json.dumps(job_seeker.as_dict()))
    except (ValidationError, TypeError) as err:
        return _build_error_response(err, HTTPStatus.BAD_REQUEST)
    except Exception as err:
        return _build_error_response(err)
示例#5
0
def add_seeker_languages(event: dict, context: LambdaContext) -> dict:
    try:
        languages_list: List[str] = json.loads(event["body"])

        event: APIGatewayProxyEvent = APIGatewayProxyEvent(event)
        user_id = event.request_context.authorizer.claims["sub"]

        job_seeker: JobSeeker = JobSeeker(**job_seeker_repository.get(user_id))

        job_seeker.languages = languages_list

        job_seeker_repository.update(job_seeker)

        # return resource
        return _build_response(http_status=HTTPStatus.NO_CONTENT, body="")
    except (ValidationError, TypeError) as err:
        return _build_error_response(err, HTTPStatus.BAD_REQUEST)
    except Exception as err:
        return _build_error_response(err)
示例#6
0
def test_job_seekers_get_summary_debug(endpoint_url):
    assert os.environ["JOB_SEEKERS_TABLE_NAME"] is not None
    print("\nseekers_table: ", os.environ["JOB_SEEKERS_TABLE_NAME"])

    user_id = '751ef537-e95a-4217-9287-d89a8861d948'
    # convert to model
    job_seeker: JobSeeker = JobSeeker(**job_seeker_repository.get(user_id))

    job_seeker_answers: JobSeekerAnswers = \
        JobSeekerAnswers(**job_seeker_answers_repository.get_by_seeker_id(user_id))

    job_seeker_experience_list: List[
        Experience] = job_seeker_experience_repository.get_all(user_id)

    # TODO convert to resource
    resource: JobSeekerResource = JobSeekerResource(
        profile=job_seeker,
        experience_list=job_seeker_experience_list,
        answers=job_seeker_answers)
示例#7
0
def create_or_update_seeker_profile_with_id(event: dict,
                                            context: LambdaContext) -> dict:
    try:
        job_seeker_id = event["pathParameters"]["id"]

        profile_dto: JobSeekerProfileDto = JobSeekerProfileDto.parse_raw(
            event["body"])

        try:
            # try to update job seeker. If does not exists, create it.
            job_seeker: JobSeeker = JobSeeker(
                **job_seeker_repository.get(job_seeker_id))
            return __update_seeker_profile(profile_dto=profile_dto,
                                           job_seeker=job_seeker)
        except NotFoundError as err:
            return __create_seeker_profile(user_id=job_seeker_id,
                                           profile_dto=profile_dto)

    except (ValidationError, TypeError) as err:
        return _build_error_response(err, HTTPStatus.BAD_REQUEST)
    except Exception as err:
        return _build_error_response(err)
示例#8
0
def create_or_update_seeker_profile(event: dict,
                                    context: LambdaContext) -> dict:
    try:
        event: APIGatewayProxyEvent = APIGatewayProxyEvent(event)
        user_id = event.request_context.authorizer.claims["sub"]

        profile_dto: JobSeekerProfileDto = JobSeekerProfileDto.parse_raw(
            event["body"])

        try:
            # try to update job seeker. If does not exists, create it.
            job_seeker: JobSeeker = JobSeeker(
                **job_seeker_repository.get(user_id))
            return __update_seeker_profile(profile_dto=profile_dto,
                                           job_seeker=job_seeker)
        except NotFoundError as err:
            return __create_seeker_profile(user_id=user_id,
                                           profile_dto=profile_dto)

    except (ValidationError, TypeError) as err:
        return _build_error_response(err, HTTPStatus.BAD_REQUEST)
    except Exception as err:
        return _build_error_response(err)
示例#9
0
def add_seeker_answers_with_id(event: dict, context: LambdaContext) -> dict:
    try:
        answer_dto_list: List[JobSeekerAnswerDto] = [
            JobSeekerAnswerDto.parse_obj(item)
            for item in json.loads(event["body"])
        ]

        job_seeker_id = event["pathParameters"]["id"]

        job_seeker: JobSeeker = JobSeeker(
            **job_seeker_repository.get(job_seeker_id))

        job_seeker_answers: JobSeekerAnswers = JobSeekerAnswers(
            job_seeker_id=job_seeker_id, job_seeker_name=job_seeker.full_name)

        job_seeker_answers.a1 = answer_dto_list[0].answer
        job_seeker_answers.a2 = answer_dto_list[1].answer
        job_seeker_answers.a3 = answer_dto_list[2].answer
        job_seeker_answers.a4 = answer_dto_list[3].answer
        job_seeker_answers.a5 = answer_dto_list[4].answer
        job_seeker_answers.a6 = answer_dto_list[5].answer
        job_seeker_answers.a7 = answer_dto_list[6].answer
        job_seeker_answers.a8 = answer_dto_list[7].answer
        job_seeker_answers.a9 = answer_dto_list[8].answer
        job_seeker_answers.a10 = answer_dto_list[9].answer

        job_seeker_answers_repository.create(
            job_seeker_answers=job_seeker_answers)

        # return resource
        return _build_response(http_status=HTTPStatus.CREATED, body="")
    except (ValidationError, TypeError) as err:
        return _build_error_response(err, HTTPStatus.BAD_REQUEST)
    except NotFoundError as err:
        return _build_error_response(err, HTTPStatus.NOT_FOUND)
    except Exception as err:
        return _build_error_response(err)