def test_delete_ccf_outside_of_users_domain(self, access_token_first, access_token_second, candidate_first, domain_custom_fields, user_second_candidate): """ Test: Attempt to delete ccf that do not belong to user's domain Expect: 403 """ # Add candidate custom fields for candidate data = { 'candidate_custom_fields': [{ 'custom_field_id': domain_custom_fields[0].id, 'value': VALUE }] } create_resp = send_request('post', URL % candidate_first.id, access_token_first, data) print response_info(create_resp) ccf_id = create_resp.json()['candidate_custom_fields'][0]['id'] url = CandidateApiUrl.CUSTOM_FIELD % (user_second_candidate.id, ccf_id) del_resp = send_request('delete', url, access_token_second) print response_info(del_resp) assert del_resp.status_code == requests.codes.FORBIDDEN assert del_resp.json( )['error']['code'] == custom_error.CUSTOM_FIELD_FORBIDDEN
def test_get_candidate_via_id_and_email(self, access_token_first, user_first, talent_pool): """ Test: Retrieve candidate via candidate's ID and candidate's Email address Expect: 200 in both cases """ # Create candidate data = generate_single_candidate_data([talent_pool.id]) create_resp = send_request('post', CandidateApiUrl.CANDIDATES, access_token_first, data) print response_info(create_resp) resp_dict = create_resp.json() # Retrieve candidate candidate_id = resp_dict['candidates'][0]['id'] get_resp = send_request('get', CandidateApiUrl.CANDIDATE % candidate_id, access_token_first) # Candidate Email candidate_email = get_resp.json()['candidate']['emails'][0]['address'] # Get candidate via Candidate ID get_resp = send_request('get', CandidateApiUrl.CANDIDATE % candidate_id, access_token_first) resp_dict = get_resp.json() print response_info(get_resp) assert get_resp.status_code == 200 assert isinstance(resp_dict, dict) # Get candidate via Candidate Email get_resp = send_request('get', CandidateApiUrl.CANDIDATE % candidate_email, access_token_first) resp_dict = get_resp.json() print response_info(get_resp) assert get_resp.status_code == 200 assert isinstance(resp_dict, dict)
def test_data_validations(self, access_token_first): """ Test: Validate json data Expect: 400 """ data = {'candidate': [{}]} resp = send_request('patch', CandidateApiUrl.CANDIDATES, access_token_first, data) print response_info(resp) assert resp.status_code == 400 data = {'candidates': {}} resp = send_request('patch', CandidateApiUrl.CANDIDATES, access_token_first, data) print response_info(resp) assert resp.status_code == 400 data = {'candidates': [{}]} resp = send_request('patch', CandidateApiUrl.CANDIDATES, access_token_first, data) print response_info(resp) assert resp.status_code == 400 data = {'candidates': [{'id': 5, 'phones': [{}]}]} resp = send_request('patch', CandidateApiUrl.CANDIDATES, access_token_first, data) print response_info(resp) assert resp.status_code == 400
def test_delete_address_of_a_diff_candidate(self, access_token_first, talent_pool): """ Test: Attempt to delete the address of a different Candidate Expect: 403 """ data_1 = generate_single_candidate_data([talent_pool.id]) data_2 = generate_single_candidate_data([talent_pool.id]) # Create candidate_1 and candidate_2 create_resp = send_request('post', CandidateApiUrl.CANDIDATES, access_token_first, data_1) candidate_1_id = create_resp.json()['candidates'][0]['id'] create_resp = send_request('post', CandidateApiUrl.CANDIDATES, access_token_first, data_2) candidate_2_id = create_resp.json()['candidates'][0]['id'] # Retrieve candidate_2's addresses get_resp = send_request('get', CandidateApiUrl.CANDIDATE % candidate_2_id, access_token_first) can_2_addresses = get_resp.json()['candidate']['addresses'] # Delete candidate_2's id using candidate_1_id url = CandidateApiUrl.ADDRESS % (candidate_1_id, can_2_addresses[0]['id']) updated_resp = send_request('delete', url, access_token_first) print response_info(updated_resp) assert updated_resp.status_code == 403 assert updated_resp.json( )['error']['code'] == custom_error.ADDRESS_FORBIDDEN
def test_delete_all_of_candidates_addresses(self, access_token_first, talent_pool): """ Test: Remove all of candidate's addresses from db Expect: 204, Candidate should not have any addresses left """ # Create Candidate data = generate_single_candidate_data([talent_pool.id]) create_resp = send_request('post', CandidateApiUrl.CANDIDATES, access_token_first, data) # Remove all of Candidate's addresses candidate_id = create_resp.json()['candidates'][0]['id'] updated_resp = send_request('delete', CandidateApiUrl.ADDRESSES % candidate_id, access_token_first, data) print response_info(updated_resp) # Retrieve Candidate after update get_resp = send_request('get', CandidateApiUrl.CANDIDATE % candidate_id, access_token_first) can_dict_after_update = get_resp.json()['candidate'] assert updated_resp.status_code == 204 assert len(can_dict_after_update['addresses']) == 0
def test_delete_can_edu_degree_bullets_of_a_different_candidate( self, access_token_first, talent_pool): """ Test: Attempt to delete degree-bullets of a different Candidate Expect: 403 """ # Create candidate_1 and candidate_2 data_1 = generate_single_candidate_data([talent_pool.id]) data_2 = generate_single_candidate_data([talent_pool.id]) create_resp = send_request('post', CandidateApiUrl.CANDIDATES, access_token_first, data_1) candidate_1_id = create_resp.json()['candidates'][0]['id'] create_resp = send_request('post', CandidateApiUrl.CANDIDATES, access_token_first, data_2) candidate_2_id = create_resp.json()['candidates'][0]['id'] # Retrieve candidate_2's degree-bullets get_resp = send_request('get', CandidateApiUrl.CANDIDATE % candidate_2_id, access_token_first) can_2_edu = get_resp.json()['candidate']['educations'][0] can_2_edu_degree = can_2_edu['degrees'][0] can_2_edu_degree_bullet = can_2_edu['degrees'][0]['bullets'][0] # Delete candidate_2's degree bullet using candidate_1_id url = CandidateApiUrl.DEGREE_BULLET % (candidate_1_id, can_2_edu['id'], can_2_edu_degree['id'], can_2_edu_degree_bullet['id']) updated_resp = send_request('delete', url, access_token_first) print response_info(updated_resp) assert updated_resp.status_code == 404 assert updated_resp.json( )['error']['code'] == custom_error.DEGREE_NOT_FOUND
def test_bulk_delete_using_ids(self, user_first, access_token_first, talent_pool): """ Test: Delete candidates in bulk """ user_first.role_id = Role.get_by_name('DOMAIN_ADMIN').id db.session.commit() # Create 50 candidates number_of_candidates = 5 candidates_data = generate_single_candidate_data( talent_pool_ids=[talent_pool.id], number_of_candidates=number_of_candidates) create_resp = send_request('post', CandidateApiUrl.CANDIDATES, access_token_first, candidates_data) assert create_resp.status_code == requests.codes.CREATED print response_info(create_resp) created_candidates = create_resp.json()['candidates'] assert len(created_candidates) == number_of_candidates # Delete all 50 candidates candidates_for_delete = dict(_candidate_ids=[ candidate['id'] for candidate in created_candidates ]) bulk_del_resp = send_request('delete', CandidateApiUrl.CANDIDATES, access_token_first, candidates_for_delete) print response_info(bulk_del_resp) assert bulk_del_resp.status_code == requests.codes.NO_CONTENT
def test_delete_candidate_phone(self, access_token_first, talent_pool): """ Test: Remove Candidate's phone from db Expect: 204, Candidate's phones must be less 1 """ # Create Candidate data = generate_single_candidate_data([talent_pool.id]) create_resp = send_request('post', CandidateApiUrl.CANDIDATES, access_token_first, data) # Retrieve Candidate's phones candidate_id = create_resp.json()['candidates'][0]['id'] get_resp = send_request('get', CandidateApiUrl.CANDIDATE % candidate_id, access_token_first) can_phones = get_resp.json()['candidate']['phones'] # Current number of candidate's phones phones_count_before_delete = len(can_phones) # Delete Candidate's phone url = CandidateApiUrl.PHONE % (candidate_id, can_phones[0]['id']) updated_resp = send_request('delete', url, access_token_first) print response_info(updated_resp) # Retrieve Candidate's phones after update get_resp = send_request('get', CandidateApiUrl.CANDIDATE % candidate_id, access_token_first) can_phones_after_delete = get_resp.json()['candidate']['phones'] assert updated_resp.status_code == requests.codes.NO_CONTENT assert len(can_phones_after_delete) == phones_count_before_delete - 1
def test_multiple_is_current_experiences(self, access_token_first, talent_pool): """ Test: Add more than one CandidateExperience with is_current set to True Expect: 200, but only one CandidateExperience must have is_current True, the rest must be False """ # Create Candidate data = generate_single_candidate_data([talent_pool.id]) create_resp = send_request('post', CandidateApiUrl.CANDIDATES, access_token_first, data) # Add a new work experience to the existing Candidate with is_current set to True candidate_id = create_resp.json()['candidates'][0]['id'] send_request('patch', CandidateApiUrl.CANDIDATES, access_token_first, data) # Retrieve Candidate after update get_resp = send_request('get', CandidateApiUrl.CANDIDATE % candidate_id, access_token_first) updated_candidate_dict = get_resp.json()['candidate'] updated_can_experiences = updated_candidate_dict['work_experiences'] # Only one of the experiences must be current! assert sum([ 1 for experience in updated_can_experiences if experience['is_current'] ]) == 1
def test_add_candidate_with_duplicate_phone_number(self, access_token_first, talent_pool): """ Test: Add candidate using identical phone numbers Expect: Successful response but only one of the phone numbers should be added to the candidate's profile """ # Create candidate with identical phone numbers phone_number = fake.phone_number() data = { 'candidates': [{ 'talent_pool_ids': { 'add': [talent_pool.id] }, 'phones': [{ 'value': phone_number }, { 'value': phone_number }] }] } create_resp = send_request('post', CandidateApiUrl.CANDIDATES, access_token_first, data) print response_info(create_resp) assert create_resp.status_code == requests.codes.CREATED # Retrieve candidate and assert that it has only one phone number candidate_id = create_resp.json()['candidates'][0]['id'] get_resp = send_request('get', CandidateApiUrl.CANDIDATE % candidate_id, access_token_first) print response_info(get_resp) candidate_created_phones = get_resp.json()['candidate']['phones'] assert len(candidate_created_phones) == 1
def test_add_candidate_using_an_existing_number(self, access_token_first, talent_pool): """ Test: Add a candidate using a phone number that already exists in candidate's domain """ # Create candidate with phone number phone_number = fake.phone_number() data = { 'candidates': [{ 'talent_pool_ids': { 'add': [talent_pool.id] }, 'phones': [{ 'value': phone_number }] }] } send_request('post', CandidateApiUrl.CANDIDATES, access_token_first, data) # Create another candidate using the same phone number as above create_resp = send_request('post', CandidateApiUrl.CANDIDATES, access_token_first, data) print response_info(create_resp) assert create_resp.status_code == requests.codes.BAD assert create_resp.json( )['error']['code'] == custom_error.CANDIDATE_ALREADY_EXISTS assert 'id' in create_resp.json()['error']
def test_create_candidate_phones(self, access_token_first, talent_pool): """ Test: Create CandidatePhones for Candidate Expect: 201 """ # Create Candidate data = candidate_phones(talent_pool) create_resp = send_request('post', CandidateApiUrl.CANDIDATES, access_token_first, data) print response_info(create_resp) assert create_resp.status_code == requests.codes.CREATED # Retrieve Candidate candidate_id = create_resp.json()['candidates'][0]['id'] get_resp = send_request('get', CandidateApiUrl.CANDIDATE % candidate_id, access_token_first) candidate_dict = get_resp.json()['candidate'] # Assert data sent in = data retrieved can_phones = candidate_dict['phones'] can_phones_data = data['candidates'][0]['phones'] assert isinstance(can_phones, list) assert can_phones_data[0]['value'] == data['candidates'][0]['phones'][ 0]['value'] assert can_phones_data[0]['label'] == data['candidates'][0]['phones'][ 0]['label']
def test_check_for_id(access_token_first, talent_pool): """ Test: Send candidate-dicts to check_for_id to ensure the function is behaving as expected Expect: False if candidate-dict has missing id-key(s) """ # Create candidate data = generate_single_candidate_data([talent_pool.id]) resp = send_request('post', CandidateApiUrl.CANDIDATES, access_token_first, data) print response_info(resp) candidate_id = resp.json()['candidates'][0]['id'] get_resp = send_request('get', CandidateApiUrl.CANDIDATE % candidate_id, access_token_first) candidate_dict = get_resp.json()['candidate'] r = check_for_id(_dict=candidate_dict) assert r is None # Send candidate-dict with an empty dict, e.g. work_preference = {} _dict = candidate_dict.copy() _dict['work_preference'] = {} r = check_for_id(_dict=_dict) assert r is None # Remove top-level id-key _dict = candidate_dict.copy() del _dict['id'] r = check_for_id(_dict=_dict) assert r is False # Remove id-key of the first address-dict in addresses _dict = candidate_dict.copy() del _dict['addresses'][0]['id'] r = check_for_id(_dict=_dict) assert r is False # Remove id-key from first education-dict in educations _dict = candidate_dict.copy() del _dict['educations'][0]['id'] r = check_for_id(_dict=_dict) assert r is False # Remove id-key from first degree-dict in educations _dict = candidate_dict.copy() del _dict['educations'][0]['degrees'][0]['id'] r = check_for_id(_dict=_dict) assert r is False # Remove id-key from first degree_bullet-dict in degrees _dict = candidate_dict.copy() del _dict['educations'][0]['degrees'][0]['bullets'][0]['id'] r = check_for_id(_dict=_dict) assert r is False # Remove id-key from work_preference _dict = candidate_dict.copy() del _dict['work_preference']['id'] r = check_for_id(_dict=_dict) assert r is False
def test_add_candidate_custom_field_with_whitespaced_value( self, access_token_first, domain_custom_fields, candidate_first): """ Test: Add candidate custom field with a value that contains whitespaces Expect: 201, whitespace must be removed before inserting into db """ data = { 'candidate_custom_fields': [{ 'custom_field_id': domain_custom_fields[0].id, 'value': ' ' + VALUE + ' ' }] } # Add candidate custom fields for candidate create_resp = send_request('post', URL % candidate_first.id, access_token_first, data) print response_info(create_resp) assert create_resp.status_code == requests.codes.CREATED # Retrieve candidate custom field via ID ccf_id = create_resp.json()['candidate_custom_fields'][0]['id'] get_resp = send_request( 'get', CandidateApiUrl.CUSTOM_FIELD % (candidate_first.id, ccf_id), access_token_first) print response_info(get_resp) assert get_resp.status_code == requests.codes.OK assert get_resp.json()['candidate_custom_field'][ 'custom_field_id'] == domain_custom_fields[0].id assert get_resp.json()['candidate_custom_field']['value'] == data[ 'candidate_custom_fields'][0]['value'].strip()
def test_delete_candidate_education_degrees(self, access_token_first, talent_pool): """ Test: Remove all of candidate's degrees from db Expect: 204; Candidate should not have any degrees left; Candidate's Education should not be removed """ # Create Candidate data = generate_single_candidate_data([talent_pool.id]) create_resp = send_request('post', CandidateApiUrl.CANDIDATES, access_token_first, data) # Retrieve Candidate candidate_id = create_resp.json()['candidates'][0]['id'] get_resp = send_request('get', CandidateApiUrl.CANDIDATE % candidate_id, access_token_first) can_educations = get_resp.json()['candidate']['educations'] # Current number of candidate educations count_of_edu_degrees_before_deleting = len(can_educations[0]) # Remove all of Candidate's degrees url = CandidateApiUrl.DEGREES % (candidate_id, can_educations[0]['id']) updated_resp = send_request('delete', url, access_token_first) print response_info(updated_resp) # Retrieve Candidate after update get_resp = send_request('get', CandidateApiUrl.CANDIDATE % candidate_id, access_token_first) can_dict_after_update = get_resp.json()['candidate'] assert updated_resp.status_code == 204 assert len(can_dict_after_update['educations'][0]['degrees']) == 0 assert len(can_dict_after_update['educations'] [0]) == count_of_edu_degrees_before_deleting
def test_set_title_from_experiences_and_title(self, access_token_first, talent_pool): data = { 'candidates': [{ 'talent_pool_ids': { 'add': [talent_pool.id] }, 'first_name': fake.first_name(), 'title': 'engineerI', 'work_experiences': [{ 'position': 'engineerII', 'is_current': True }, { 'position': 'engineerIII', 'start_year': 2015, 'end_year': 2016 }] }] } r = send_request('post', CandidateApiUrl.CANDIDATES, access_token_first, data) print response_info(r) candidate_id = r.json()['candidates'][0]['id'] r = send_request('get', CandidateApiUrl.CANDIDATE % str(candidate_id), access_token_first) print response_info(r) assert r.json()['candidate']['title'] == data['candidates'][0]['title']
def test_delete_degree_bullets_of_a_candidate_belonging_to_a_diff_user( self, access_token_first, talent_pool, access_token_second): """ Test: Attempt to delete degree-bullets of a Candidate that belongs to a user from a diff domain Expect: 204 """ # Create candidate_1 & candidate_2 with user_first & user_first_2 data = generate_single_candidate_data([talent_pool.id]) create_resp_1 = send_request('post', CandidateApiUrl.CANDIDATES, access_token_first, data) # Retrieve candidate_1 candidate_1_id = create_resp_1.json()['candidates'][0]['id'] get_resp = send_request('get', CandidateApiUrl.CANDIDATE % candidate_1_id, access_token_first) can_1_educations = get_resp.json()['candidate']['educations'] # Delete candidate_1's degree-bullets with user_first_2 logged in url = CandidateApiUrl.DEGREE_BULLETS % ( candidate_1_id, can_1_educations[0]['id'], can_1_educations[0]['degrees'][0]['id']) updated_resp = send_request('delete', url, access_token_second) print response_info(updated_resp) assert updated_resp.status_code == 403 assert updated_resp.json( )['error']['code'] == custom_error.CANDIDATE_FORBIDDEN
def test_add_candidate_subscription_preference(self, access_token_first, talent_pool): """ Test: Add subscription preference for the candidate Expect: 204 """ # Create candidate and candidate subscription preference data = generate_single_candidate_data([talent_pool.id]) create_resp = send_request('post', CandidateApiUrl.CANDIDATES, access_token_first, data) candidate_id = create_resp.json()['candidates'][0]['id'] data = {'frequency_id': 1} resp = send_request( 'post', CandidateApiUrl.CANDIDATE_PREFERENCE % candidate_id, access_token_first, data) print response_info(resp) assert resp.status_code == 204 # Retrieve Candidate's subscription preference resp = send_request( 'get', CandidateApiUrl.CANDIDATE_PREFERENCE % candidate_id, access_token_first) print response_info(resp) assert resp.status_code == 200 assert resp.json( )['candidate']['subscription_preference']['frequency_id'] == 1
def test_delete_non_existing_candidate(self, access_token_first, user_first): """ Test: Attempt to delete a candidate that isn't recognized via ID or Email Expect: 404 """ user_first.role_id = Role.get_by_name('DOMAIN_ADMIN').id db.session.commit() last_candidate = Candidate.query.order_by(Candidate.id.desc()).first() non_existing_candidate_id = str(last_candidate.id * 100) # Delete non existing candidate via ID resp = send_request( 'delete', CandidateApiUrl.CANDIDATE % non_existing_candidate_id, access_token_first) print response_info(resp) assert resp.status_code == requests.codes.NOT_FOUND assert resp.json()['error']['code'] == custom_error.CANDIDATE_NOT_FOUND # Delete non existing candidate via Email bogus_email = '{}_{}'.format(fake.word(), fake.safe_email()) assert not CandidateEmail.get_by_address(email_address=bogus_email) resp = send_request('delete', CandidateApiUrl.CANDIDATE % bogus_email, access_token_first) print response_info(resp) assert resp.status_code == requests.codes.NOT_FOUND assert resp.json()['error']['code'] == custom_error.EMAIL_NOT_FOUND
def test_delete_candidate_preference(self, access_token_first, talent_pool): """ Test: Delete candidate's subscription preference Expect: 200, should just get an empty dict for subscription_preference """ # Create candidate and candidate's subscription preference data = generate_single_candidate_data([talent_pool.id]) create_resp = send_request('post', CandidateApiUrl.CANDIDATES, access_token_first, data) candidate_id = create_resp.json()['candidates'][0]['id'] send_request('post', CandidateApiUrl.CANDIDATE_PREFERENCE % candidate_id, access_token_first, {'frequency_id': 1}) # Update candidate's subscription preference resp = send_request( 'delete', CandidateApiUrl.CANDIDATE_PREFERENCE % candidate_id, access_token_first) print response_info(resp) assert resp.status_code == 204 # Retrieve candidate's subscription preference resp = send_request( 'get', CandidateApiUrl.CANDIDATE_PREFERENCE % candidate_id, access_token_first) print response_info(resp) assert resp.status_code == 200 assert resp.json()['candidate']['subscription_preference'] == {}
def test_archive_candidate_and_retrieve_it(self, access_token_first, talent_pool): """ Test: Archive a Candidate and then retrieve it Expect: 404, Not Found error """ # Create Candidate data = generate_single_candidate_data([talent_pool.id]) create_resp = send_request('post', CandidateApiUrl.CANDIDATES, access_token_first, data) # Archive Candidate candidate_id = create_resp.json()['candidates'][0]['id'] archive_data = {'candidates': [{'id': candidate_id, 'archive': True}]} resp = send_request('patch', CandidateApiUrl.CANDIDATES, access_token_first, archive_data) print response_info(resp) # Retrieve Candidate get_resp = send_request('get', CandidateApiUrl.CANDIDATE % candidate_id, access_token_first) print response_info(get_resp) assert get_resp.status_code == requests.codes.NOT_FOUND assert get_resp.json( )['error']['code'] == custom_error.CANDIDATE_IS_ARCHIVED
def test_create_candidate_educations_with_no_degrees( self, access_token_first, talent_pool): """ Test: Create CandidateEducation for Candidate Expect: 201 """ # Create Candidate without degrees data = generate_single_candidate_data([talent_pool.id]) create_resp = send_request('post', CandidateApiUrl.CANDIDATES, access_token_first, data) print response_info(create_resp) assert create_resp.status_code == 201 # Retrieve Candidate candidate_id = create_resp.json()['candidates'][0]['id'] get_resp = send_request('get', CandidateApiUrl.CANDIDATE % candidate_id, access_token_first) candidate_dict = get_resp.json()['candidate'] can_educations = candidate_dict['educations'] data_educations = data['candidates'][0]['educations'][0] assert isinstance(can_educations, list) assert can_educations[0]['city'] == data_educations['city'] assert can_educations[0]['school_name'] == data_educations[ 'school_name'] can_edu_degrees = can_educations[0]['degrees'] assert isinstance(can_edu_degrees, list)
def test_delete_can_address(self, access_token_first, talent_pool): """ Test: Remove Candidate's address from db Expect: 204, Candidate's addresses must be less 1 """ # Create Candidate data = generate_single_candidate_data([talent_pool.id]) create_resp = send_request('post', CandidateApiUrl.CANDIDATES, access_token_first, data) print response_info(create_resp) # Retrieve Candidate candidate_id = create_resp.json()['candidates'][0]['id'] get_resp = send_request('get', CandidateApiUrl.CANDIDATE % candidate_id, access_token_first) can_addresses = get_resp.json()['candidate']['addresses'] # Number of Candidate's addresses can_addresses_count = len(can_addresses) # Remove one of Candidate's addresses url = CandidateApiUrl.ADDRESS % (candidate_id, can_addresses[0]['id']) updated_resp = send_request('delete', url, access_token_first) print response_info(updated_resp) # Retrieve Candidate after update get_resp = send_request('get', CandidateApiUrl.CANDIDATE % candidate_id, access_token_first) can_dict_after_update = get_resp.json()['candidate'] assert updated_resp.status_code == 204 assert len( can_dict_after_update['addresses']) == can_addresses_count - 1
def test_update_education_of_a_diff_candidate(self, access_token_first, talent_pool): """ Test: Update education information of a different Candidate Expect: 403 """ # Create Candidate data_1 = generate_single_candidate_data([talent_pool.id]) data_2 = generate_single_candidate_data([talent_pool.id]) resp_1 = send_request('post', CandidateApiUrl.CANDIDATES, access_token_first, data_1) resp_2 = send_request('post', CandidateApiUrl.CANDIDATES, access_token_first, data_2) candidate_1_id = resp_1.json()['candidates'][0]['id'] candidate_2_id = resp_2.json()['candidates'][0]['id'] # Retrieve Candidate get_resp = send_request('get', CandidateApiUrl.CANDIDATE % candidate_1_id, access_token_first) candidate_dict = get_resp.json()['candidate'] # Update existing CandidateEducation of a different Candidate data = GenerateCandidateData.educations( candidate_id=candidate_2_id, education_id=candidate_dict['educations'][0]['id']) updated_resp = send_request('patch', CandidateApiUrl.CANDIDATES, access_token_first, data) print response_info(updated_resp) assert updated_resp.status_code == 403 assert updated_resp.json( )['error']['code'] == custom_error.EDUCATION_FORBIDDEN
def test_delete_can_custom_field(self, access_token_first, talent_pool, domain_custom_fields): """ Test: Remove Candidate's custom field from db Expect: 204, Candidate's custom fields must be less 1 AND no CustomField should be deleted """ # Create Candidate data = generate_single_candidate_data( [talent_pool.id], custom_fields=domain_custom_fields) create_resp = send_request('post', CandidateApiUrl.CANDIDATES, access_token_first, data) # Retrieve Candidate custom fields candidate_id = create_resp.json()['candidates'][0]['id'] get_resp = send_request('get', CandidateApiUrl.CANDIDATE % candidate_id, access_token_first) can_custom_fields = get_resp.json()['candidate']['custom_fields'] db.session.commit() custom_field_id_1 = CandidateCustomField.get_by_id( can_custom_fields[0]['id']).custom_field_id custom_field_id_2 = CandidateCustomField.get_by_id( can_custom_fields[1]['id']).custom_field_id # Remove one of Candidate's custom field url = CandidateApiUrl.CUSTOM_FIELD % (candidate_id, can_custom_fields[0]['id']) updated_resp = send_request('delete', url, access_token_first) print response_info(updated_resp) assert updated_resp.status_code == 204 assert CustomField.query.get( custom_field_id_1) # CustomField should still be in db assert CustomField.query.get( custom_field_id_2) # CustomField should still be in db
def test_with_empty_values(self, access_token_first, talent_pool): """ Test: Create candidate education degree with some whitespaces and empty values Expect: 201 """ data = { 'candidates': [{ 'talent_pool_ids': { 'add': [talent_pool.id] }, 'educations': [{ 'school_name': ' ', 'school_type': ' ', 'city': None, 'subdivision_code': '' }] }] } # Create candidate education with empty values create_resp = send_request('post', CandidateApiUrl.CANDIDATES, access_token_first, data) print response_info(create_resp) assert create_resp.status_code == requests.codes.CREATED # Retrieve candidate candidate_id = create_resp.json()['candidates'][0]['id'] get_resp = send_request('get', CandidateApiUrl.CANDIDATE % candidate_id, access_token_first) print response_info(get_resp) candidate_educations = get_resp.json()['candidate']['educations'] assert not candidate_educations, "Candidate education record not added to db because data was empty"
def test_schema_validation(self, access_token_first, talent_pool): """ Test: Schema validations for CandidatesResource/post() Expect: 400 unless if a dict of CandidateObject is provided with at least one talent_pool.id """ # Create Candidate data = {} resp = send_request('post', CandidateApiUrl.CANDIDATES, access_token_first, data) print response_info(resp) assert resp.status_code == 400 assert resp.json()['error']['code'] == custom_error.INVALID_INPUT data['candidates'] = [] resp = send_request('post', CandidateApiUrl.CANDIDATES, access_token_first, data) print response_info(resp) assert resp.status_code == 400 assert resp.json()['error']['code'] == custom_error.INVALID_INPUT data['candidates'] = [{}] resp = send_request('post', CandidateApiUrl.CANDIDATES, access_token_first, data) print response_info(resp) assert resp.status_code == 400 assert resp.json()['error']['code'] == custom_error.INVALID_INPUT data['candidates'] = [{'talent_pool_ids': {'add': [talent_pool.id]}}] resp = send_request('post', CandidateApiUrl.CANDIDATES, access_token_first, data) print response_info(resp) assert resp.status_code == 201
def test_delete_education_of_a_different_candidate(self, access_token_first, talent_pool): """ Test: Attempt to delete the education of a different Candidate in the same domain Expect: 403 """ # Create candidate_1 and candidate_2 data_1 = generate_single_candidate_data([talent_pool.id]) data_2 = generate_single_candidate_data([talent_pool.id]) create_resp = send_request('post', CandidateApiUrl.CANDIDATES, access_token_first, data_1) candidate_1_id = create_resp.json()['candidates'][0]['id'] create_resp = send_request('post', CandidateApiUrl.CANDIDATES, access_token_first, data_2) candidate_2_id = create_resp.json()['candidates'][0]['id'] # Retrieve candidate_2's educations get_resp = send_request('get', CandidateApiUrl.CANDIDATE % candidate_2_id, access_token_first) can_2_educations = get_resp.json()['candidate']['educations'] # Delete candidate_2's id using candidate_1_id url = CandidateApiUrl.EDUCATION % (candidate_1_id, can_2_educations[0]['id']) updated_resp = send_request('delete', url, access_token_first) print response_info(updated_resp) assert updated_resp.status_code == 403 assert updated_resp.json( )['error']['code'] == custom_error.EDUCATION_FORBIDDEN
def test_update_reference(self, access_token_first, candidate_first): """ """ # Create references for candidate create_resp = send_request('post', self.URL % candidate_first.id, access_token_first, data) print response_info(create_resp) assert create_resp.status_code == 201 # Update reference's info update_data = { 'candidate_references': [{ 'id': create_resp.json()['candidate_references'][0]['id'], 'comments': "in second thought, he ain't too bad" }] } update_resp = send_request('patch', self.URL % candidate_first.id, access_token_first, update_data) print response_info(update_resp) assert update_resp.status_code == 200 # Retrieve candidate's references get_resp = send_request('get', self.URL % candidate_first.id, access_token_first) print response_info(get_resp) assert get_resp.status_code == 200 assert len(get_resp.json()['candidate_references']) == len( data['candidate_references']) assert get_resp.json()['candidate_references'][0][ 'comments'] == update_data['candidate_references'][0]['comments']
def test_delete_ccf_of_forbidden_candidate(self, access_token_first, domain_custom_fields, candidate_first, candidate_second): """ Test: Attempt to delete the ccf of a different candidate Expect: 403 """ data = { 'candidate_custom_fields': [{ 'custom_field_id': domain_custom_fields[0].id, 'value': VALUE }] } # Add candidate custom fields for candidate create_resp = send_request('post', URL % candidate_first.id, access_token_first, data) print response_info(create_resp) # Retrieve ccf using a different candidate ID ccf_id = create_resp.json()['candidate_custom_fields'][0]['id'] url = CandidateApiUrl.CUSTOM_FIELD % (candidate_second.id, ccf_id) del_resp = send_request('delete', url, access_token_first) print response_info(del_resp) assert del_resp.status_code == requests.codes.FORBIDDEN assert del_resp.json( )['error']['code'] == custom_error.CUSTOM_FIELD_FORBIDDEN