Ejemplo n.º 1
0
def change_job_application_state(id: int):  # noqa: E501
    """Changes a state of a job application by its id.

     # noqa: E501

    :param id:
    :type id: int

    :rtype: None
    """
    search_id_query = {"_id": id}
    try:
        new_state = connexion.request.json.get('state')
        update_object = {"state": new_state}
        if JobApplicationState.is_readonly(new_state):
            update_object['dateClosed'] = datetime.now()

        JobApplicationService.update_job_application(search_id_query,
                                                     update_object)
        return None, 200
    except RestException as re:
        print(re)
        return get_error_dto(re.error_type, re.status_code, re.info)
    except Exception as e:
        print(e)
        return get_error_dto("errors.job_applications.unknown")
Ejemplo n.º 2
0
    def test_update_job_application(self):
        job_application = TestDataGenerator.get_job_application()
        job_application_id = job_application['_id'] = get_next_id(
            'applicationId')
        job_application['state'] = JobApplicationState.NEW
        application.db.job_applications.insert_one(job_application)

        query = {"_id": job_application_id}
        new_state = JobApplicationState.ACCEPTED
        JobApplicationService.update_job_application(query,
                                                     {'state': new_state})

        actual = application.db.job_applications.find_one(query)
        self.assertEqual(new_state, actual['state'])
Ejemplo n.º 3
0
def create_job_application():  # noqa: E501
    """Creates a job application.

     # noqa: E501

    :rtype: GetJobApplicationDto
    """
    try:
        dto = CreateJobApplicationDto.from_dict(connexion.request.json)
        JobApplicationService.create_job_application(dto)
    except RestException as re:
        print(re)
        return get_error_dto(re.error_type, re.status_code, re.info)
    except Exception as e:
        print(e)
        return get_error_dto("errors.job_applications.unknown")
Ejemplo n.º 4
0
def get_job_offer(id: int, includeApplications=False):  # noqa: E501
    """Gets a job offer by its id.

     # noqa: E501

    :param id:
    :type id: int
    :param includeApplications:
    :type includeApplications: bool

    :rtype: JobOffer
    """
    search_id_query = {"_id": id}
    try:
        job_offer = JobOfferService.find_job_offer(search_id_query)

        if includeApplications:
            job_applications_query = {"jobOfferId": id}
            job_offer[
                'applications'] = JobApplicationService.find_job_applications(
                    job_applications_query)
        return job_offer, 200
    except RestException as re:
        print(re)
        return get_error_dto(re.error_type, re.status_code, re.info)
    except Exception as e:
        print(e)
        return get_error_dto("errors.job_offers.unknown")
Ejemplo n.º 5
0
    def test_create_job_application(self, eureka_mock):
        job_offer = TestDataGenerator.get_job_offer()
        job_offer_id = job_offer['_id'] = job_offer.pop('id')
        application.db.job_offers.insert_one(job_offer)
        json = TestDataGenerator.get_create_job_application_dto(job_offer_id)
        eureka_mock.return_value = {"id": json['applicantId']}
        expected = CreateJobApplicationDto.from_dict(json)

        actual = JobApplicationService.create_job_application(expected)

        self.assertEqual(expected.job_offer_id, actual['jobOfferId'])
        self.assertEqual(expected.applicant_id, actual['applicant']['id'])
        self.assertEqual(expected.note, actual['note'])
Ejemplo n.º 6
0
def update_job_application(id: int):  # noqa: E501
    """Updates an application by its id.

     # noqa: E501

    :param id:
    :type id: int

    :rtype: None
    """
    search_id_query = {"_id": id}
    new_note = connexion.request.json.get('note')
    update_object = {"note": new_note}
    try:
        JobApplicationService.update_job_application(search_id_query,
                                                     update_object)
        return None, 200
    except RestException as re:
        print(re)
        return get_error_dto(re.error_type, re.status_code, re.info)
    except Exception as e:
        print(e)
        return get_error_dto("errors.job_applications.unknown")
Ejemplo n.º 7
0
def get_job_applications():  # noqa: E501
    """Gets all Job applications.

     # noqa: E501


    :rtype: List[JobApplication]
    """
    try:
        job_applications = JobApplicationService.find_job_applications()
        return job_applications, 200
    except Exception as e:
        print(e)
        return get_error_dto("errors.job_applications.unknown")
Ejemplo n.º 8
0
def get_job_application(id: int):  # noqa: E501
    """Gets a job application by its id.

     # noqa: E501

    :param id:
    :type id: int

    :rtype: GetJobApplicationDto
    """
    search_id_query = {"_id": id}
    try:
        job_application = JobApplicationService.find_job_application(
            search_id_query)
        return job_application, 200
    except RestException as re:
        print(re)
        return get_error_dto(re.error_type, re.status_code, re.info)
    except Exception as e:
        print(e)
        return get_error_dto("errors.job_applications.unknown")
Ejemplo n.º 9
0
 def test_find_job_application(self):
     unknown_id = 5
     query = {"_id": unknown_id}
     with self.assertRaises(RestException):
         JobApplicationService.find_job_application(query)