def test_limits_on_reviews_per_resume_per_sme(): job = Job(id=1) job.save() sme = SME(job=job) sme.save() profile = Profile(job=job) profile.save() resume = ProfileResume(profile=profile) resume.save() assert choose_random_unreviewed_resume_for_sme(sme).id == resume.id SMEFeedback(sme=sme, profile_resume=resume, should_interview=True).save() SMEFeedback(sme=sme, profile_resume=resume, should_interview=True).save() SMEFeedback(sme=sme, profile_resume=resume, should_interview=True).save() new_resume = ProfileResume(profile=profile) new_resume.save() SMEFeedback(sme=sme, profile_resume=new_resume, should_interview=False).save() SMEFeedback(sme=sme, profile_resume=new_resume, should_interview=False).save() assert choose_random_unreviewed_resume_for_sme(sme) is None
def test_has_candidate_accepted_request_for_job_associated_with_user(): candidate_profile = Profile() candidate_profile.save() viewer_user = User.objects.create_user(username="******", password="******") viewer_user.save() assert not has_candidate_accepted_request_for_job_associated_with_user(candidate_profile.id, viewer_user.id) job_family = JobFamily() job_family.save() job = Job(job_family=job_family) job.save() employer = Employer(job_family=job_family) employer.save() employer_job = EmployerJob(employer=employer, job=job) employer_job.save() EmployerUser(employer=employer, user=viewer_user).save() employer_candidate = EmployerCandidate(profile=candidate_profile, employer_job=employer_job) employer_candidate.save() assert not has_candidate_accepted_request_for_job_associated_with_user(candidate_profile.id, viewer_user.id) employer_candidate.responded = True employer_candidate.accepted = True employer_candidate.save() assert has_candidate_accepted_request_for_job_associated_with_user(candidate_profile.id, viewer_user.id)
def test_loading_sme_feedback_page(): job = Job() job.save() sme = SME(guid="first", job=job) sme.save() client = Client() url = "/sme_feedback/" # load SME page with no token page = client.get(url) assert "error:" in contents_of_page(page).lower() # load SME page with bad token page = client.get(url + "?token=bad") assert "error:" in contents_of_page(page).lower() # load SME page with correct token page = client.get(url + "?token=first") assert "error:" not in contents_of_page(page).lower() # there are no resumes yet, so the page should say "try again later" assert "try again later" in contents_of_page(page).lower() # let's add a resume and check that that message is gone profile = Profile(job=job) profile.save() ProfileResume(profile=profile).save() page = client.get(url + "?token=first") assert "try again later" not in contents_of_page(page).lower() assert "see description" in contents_of_page(page).lower()
def test_pipl_facebook_profiles(): job = Job() job.save() profile = Profile(job=job) profile.save() ProfileReverseLookup(profile=profile, provider='pipl', output=PIPL_EXAMPLE).save() fb_profiles = get_facebook_profiles_for_profile(profile) assert len(fb_profiles) == 2
def test_rereview_probability_for_job(): desired_probabilities = { 1: 1.0, 5: 0.95, 8: 0.4, 20: 0.4, } default_probability = 0.05 for job_id in (1, 5, 8, 20, 1000): job = Job(id=job_id) job.save() assert rereview_probability_for_job(job) == desired_probabilities.get( job_id, default_probability)
def test_resume_regions(): add_cities() PA, NJ, CA = [ LookupState.objects.get(state_code=state_code) for state_code in ["PA", "NJ", "CA"] ] pa_region = LookupRegion(city="Philadelphia", state=PA) pa_region.save() ca_region = LookupRegion(city="San Francisco", state=CA) ca_region.save() job = Job() job.save() create_resumes_for_location(job, 3, "Philadelphia", PA) create_resumes_for_location(job, 5, "Haddonfield", NJ) create_resumes_for_location(job, 6, "San Francisco", CA) all_resumes = ProfileResume.objects.filter(profile__job=job) assert filter_resumes_by_region(all_resumes, None).count() == 14 assert filter_resumes_by_region(all_resumes, pa_region).count() == 8 assert filter_resumes_by_region(all_resumes, ca_region).count() == 6 pa_sme = SME(job=job, region=pa_region, guid="pa") pa_sme.save() ca_sme = SME(job=job, region=ca_region, guid="ca") ca_sme.save() for _ in range(20): resume = choose_random_unreviewed_resume_for_sme(pa_sme) assert resume.profile.state.state_code in ("PA", "NJ") resume = choose_random_unreviewed_resume_for_sme(ca_sme) assert resume.profile.state.state_code == "CA" # test region radius assert filter_resumes_by_region(all_resumes, pa_region).count() == 8 pa_region.radius = 100 pa_region.save() assert filter_resumes_by_region(all_resumes, pa_region).count() == 8 pa_region.radius = 5 pa_region.save() assert filter_resumes_by_region(all_resumes, pa_region).count() == 3
def test_create_and_remove_sme(): user = User.objects.create_user(username="******", password="******") client = Client() client.force_login(user) assert SME.objects.count() == 0 family = JobFamily(family_name="nursing") family.save() job = Job(job_name="Nurse", id=1, job_family=family) job.save() sme_data = { "first_name": "Bob", "last_name": "Loblaw", "email": "*****@*****.**", "review_limit": "10", "job": "1", "pay_rate": "0.05" } # first try to add without having staff privilege client.post(reverse("sme_manager:create_sme"), sme_data) assert SME.objects.count() == 0 assert SME.objects.filter(active=True).count() == 0 user.is_staff = True user.save() client.post(reverse("sme_manager:create_sme"), sme_data) assert SME.objects.count() == 1 assert SME.objects.filter(active=True).count() == 1 sme = SME.objects.first() assert sme.first_name == "Bob" assert sme.last_name == "Loblaw" assert sme.job_id == 1 assert SMEPayRate.objects.count() == 1 pay_rate = SMEPayRate.objects.get(sme=sme) assert pay_rate.pay_rate == Decimal("0.05") sme_data = {"sme_id": SME.objects.first().id} client.post(reverse("sme_manager:delete_sme", kwargs=sme_data)) assert SME.objects.count() == 1 assert SME.objects.filter(active=True).count() == 0
def test_sme_post(): job = Job(id=1) job.save() sme = SME(id=4, guid="four", job=job) sme.save() Profile(id=2, job_id=1).save() ProfileResume(id=4, profile_id=2).save() url = reverse("resumes:sme_feedback") client = Client() params = { "token": "four", "comment": "comment", "should_interview": "1", "resume_id": 4, "feedback_guid": "1234", "bscore_value": "501", } assert SMEFeedback.objects.count() == 0 client.post(url, params) assert SMEFeedback.objects.count() == 1 client.post(url, params) assert SMEFeedback.objects.count() == 1 feedback = SMEFeedback.objects.first() assert feedback.bscore_value == 501 assert feedback.comment == "comment" assert feedback.wrong_language is False params['feedback_guid'] = "5678" params['column_wrong_language'] = True client.post(url, params) assert SMEFeedback.objects.count() == 2 assert SMEFeedback.objects.filter(wrong_language=True).count() == 1 params['feedback_guid'] = "9abc" params['token'] = "wrong" with pytest.raises(Exception): client.post(url, params) assert SMEFeedback.objects.count() == 2
def test_rereview_probability_for_job(): job = Job(id=1) job.save() assert rereview_probability_for_job(job) == 0.01 guids = list(str(n) for n in range(5000)) for _ in range(600): resume = create_resume_for_job(job) resume.save() sme = SME(job=job, guid=guids.pop(0)) sme.save() SMEFeedback(sme=sme, profile_resume=resume, should_interview=False).save() assert rereview_probability_for_job(job) == 0.60 # review each resume three more times for resume in ProfileResume.objects.all(): for _ in range(3): sme = SME(job=job, guid=guids.pop(0)) sme.save() SMEFeedback(sme=sme, profile_resume=resume, should_interview=False).save() assert rereview_probability_for_job(job) == 0.01 # bring number of reviewed resumes up to 1400 for _ in range(800): resume = create_resume_for_job(job) resume.save() sme = SME(job=job, guid=guids.pop(0)) sme.save() SMEFeedback(sme=sme, profile_resume=resume, should_interview=False).save() assert rereview_probability_for_job(job) == 0.5
def set_up_test(is_bakround_employee): insert_real_distance_records() job_family = JobFamily() job_family.save() job = Job(job_family=job_family) job.save() employer = Employer(job_family=job_family) employer.save() employer_job = EmployerJob(job=job, employer=employer, city="Philadelphia", state=LookupState.objects.get(state_code="PA")) employer_job.save() user = User.objects.create_user(username="******", email="b") user.save() employer_user = EmployerUser(user=user, employer=employer, is_bakround_employee=is_bakround_employee) employer_user.save() EmployerJobUser(employer_job=employer_job, employer_user=employer_user).save() PA = LookupState.objects.get(state_code="PA") for i in range(5): profile = Profile(first_name=str(i), last_name=str(i), job=job, city="Philadelphia", state=PA) profile.save() search_parameters = { "page": 1, "certs": None, "score": None, "skills": None, "distance": 50, "ordering": "score", "languages": None, "page_size": 20, "experience": None, "state_filter": None, "min_education": None } saved_search = EmployerSavedSearch(employer_job=employer_job, employer_user=employer_user, search_parameters=search_parameters) saved_search.save() # Add two more profiles that appeared in a previous search. These should not # go into the queue. for i in [10, 11]: profile = Profile(first_name=str(i), last_name=str(i), job=job, city="Philadelphia", state=PA) profile.save() EmployerSearchResult(profile=profile, employer_user=employer_user, employer_saved_search=saved_search, opened=True).save()
def test_new_page_sizes(): insert_real_distance_records() create_search_view() PA = LookupState.objects.get(state_code="PA") job = Job("job name") job.save() for i in range(90): profile = Profile(job=job, first_name="{}".format(i), last_name="_", city="Philadelphia", state=PA) profile.save() Score(job=job, profile=profile, score_value=700-i).save() for page_number in (0, 1, 2, 3, 4): search = find_fresh_profiles_for_criteria( job_id=job.id, city="Philadelphia", state=PA, distance=100, ordering='score', page_number=page_number, page_size=20, ) profiles = search['profiles'] assert len(profiles) == 10 if page_number == 4 else 20 assert first_names_of_profiles(profiles) == \ [str(i) for i in range(20*page_number, 20*page_number+20) if i < 90] for page_number in (0, 1): search = find_fresh_profiles_for_criteria( job_id=job.id, city="Philadelphia", state=PA, distance=100, ordering='score', page_number=page_number, page_size=50, ) profiles = search['profiles'] assert len(profiles) == 40 if page_number == 1 else 50 assert first_names_of_profiles(profiles) == \ [str(i) for i in range(50 * page_number, 50 * page_number + 50) if i < 90] for page_number in (0, 1, 2, 3, 4): search = find_profiles_for_criteria( job_id=job.id, city="Philadelphia", state=PA, distance=100, ordering='score', page_number=page_number, page_size=20, ) profiles = search['profiles'] assert len(profiles) == 10 if page_number == 4 else 20 assert first_names_of_profiles(profiles) == \ [str(i) for i in range(20 * page_number, 20 * page_number + 20) if i < 90] for page_number in (0, 1): search = find_profiles_for_criteria( job_id=job.id, city="Philadelphia", state=PA, distance=100, ordering='score', page_number=page_number, page_size=50, ) profiles = search['profiles'] assert len(profiles) == 40 if page_number == 1 else 50 assert first_names_of_profiles(profiles) == \ [str(i) for i in range(50 * page_number, 50 * page_number + 50) if i < 90]
def test_closeability(): insert_real_distance_records() PA = LookupState.objects.get(state_code="PA") profile = Profile(id=19) profile.save() attach_experience_to_profiles({profile.id: profile}) assert average_time_in_each_job(profile) == timedelta(days=0) job_family = JobFamily(id=1) job_family.save() job = Job(job_family=job_family) job.save() employer = Employer(id=1) employer.save() employer_job = EmployerJob(id=1, employer_id=1, job=job, city="Philadelphia", state=PA) employer_job.save() cache.clear() clos = fetch_closeability_metric_for_profile_ids([19], 1) assert list(clos.keys()) == [19] assert isinstance(clos[19], float) assert clos[19] == -1.0 profile.city = "Philadelphia" profile.state = PA profile.save() cache.clear() assert fetch_closeability_metric_for_profile_ids([19], 1)[19] == 0.0 assert time_in_current_job(profile).days == 0 now = timezone.now() ProfileExperience(profile=profile, start_date=now - timedelta(days=365 * 10), end_date=now - timedelta(days=365), is_current_position=False).save() ProfileExperience(profile=profile, start_date=now - timedelta(days=180), city="Philadelphia", state=PA, is_current_position=True).save() attach_experience_to_profiles({profile.id: profile}) assert time_in_current_job(profile).days == 180 # the profile's total work time is a little less than 9.5 years average_time = average_time_in_each_job(profile) assert 365 * 4.5 < average_time.days < 365 * 5 cache.clear() new_metric = fetch_closeability_metric_for_profile_ids([19], 1)[19] assert abs(new_metric - 0.5) < 0.1 # ================================================================== # to test batching, we'll calculate the metric for 1000 profiles now profile_ids = list(range(1000, 2000)) for pid in profile_ids: Profile(id=pid, city="Philadelphia", state=PA).save() ProfileExperience(profile=profile, start_date=now - timedelta(days=365), end_date=now - timedelta(days=30), is_current_position=False).save() cache.clear() metrics = fetch_closeability_metric_for_profile_ids(profile_ids, 1) # make sure we have a result for every profile assert sorted(metrics.keys()) == profile_ids