def test_get_sender_email():
    p = Profile()
    p.save()

    p_invalid = Profile()
    p_invalid.save()

    valid = ProfileEmail(value="*****@*****.**", profile=p)
    valid.save()
    invalid = ProfileEmail(value="*****@*****.**",
                           profile=p_invalid,
                           bounces=True)
    invalid.save()

    noti_a = Notification(type="email", sender_profile=p)
    noti_a.save()
    noti_b = Notification(type="email", sender_profile=p_invalid)
    noti_b.save()
    noti_c = Notification(type="email",
                          sender_profile=p_invalid,
                          sender_email="*****@*****.**")

    assert get_sender_email(noti_a) == valid.value
    assert get_sender_email(noti_b, "fallback") == "fallback"
    assert get_sender_email(noti_c, "fallback") == noti_c.sender_email
def test_profile_email_sanity():
    p = Profile()
    p.save()
    VALID_EMAIL = "*****@*****.**"
    INVALID_EMAIL = "*****@*****.**"

    # Invalid emails
    a = ProfileEmail(value=INVALID_EMAIL, profile=p, bounces=True, unsubscribed=False, reported_spam=False)
    b = ProfileEmail(value=INVALID_EMAIL, profile=p, bounces=False, unsubscribed=True, reported_spam=False)
    c = ProfileEmail(value=INVALID_EMAIL, profile=p, bounces=False, unsubscribed=False, reported_spam=True)
    d = ProfileEmail(value=INVALID_EMAIL, profile=p, bounces=True, unsubscribed=True, reported_spam=False)
    e = ProfileEmail(value=INVALID_EMAIL, profile=p, bounces=False, unsubscribed=True, reported_spam=True)
    f = ProfileEmail(value=INVALID_EMAIL, profile=p, bounces=True, unsubscribed=True, reported_spam=True)
    g = ProfileEmail(value=INVALID_EMAIL, profile=p, bounces=True, is_correct_person=True)

    # Valid emails
    h = ProfileEmail(value=VALID_EMAIL, profile=p, bounces=False, unsubscribed=False, reported_spam=False)

    for email in [a,b,c,d,e,f,g,h]:
        email.save()

    assert not a.sane
    assert not b.sane
    assert not c.sane
    assert not d.sane
    assert not e.sane
    assert not f.sane
    assert not g.sane
    assert h.sane

    sane = ProfileEmail.all_sane()
    assert len(sane) == 1
    assert sane.first().value == VALID_EMAIL
Esempio n. 3
0
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)
Esempio n. 4
0
def test_metric_for_profile_with_one_skill():
    profile = Profile()
    profile.save()

    skill = Skill(skill_name='whatever')
    skill.save()

    profile_skill = ProfileSkill(profile=profile,
                                 skill=skill,
                                 skill_name=skill.skill_name)
    profile_skill.save()

    metric = calculate_completeness_metric_and_hints(profile)
    assert metric['metric'] == 30
    assert set(metric['hints']['add'].keys()) == {'education', 'experience'}
    assert set(metric['hints']['detail'].keys()) == {'skill'}
    assert set(metric['hints']['error'].keys()) == set()

    profile_skill.experience_months = 5
    profile_skill.last_used_date = timezone.now()

    profile_skill.save()

    metric = calculate_completeness_metric_and_hints(profile)
    assert metric['metric'] == 33
    assert set(metric['hints']['add'].keys()) == {'education', 'experience'}
    assert set(metric['hints']['detail'].keys()) == set()
    assert set(metric['hints']['error'].keys()) == set()
Esempio n. 5
0
def collect_email_data(pe, delete_records=True):
    if type(pe) is str:
        v = ProfileEmail.objects.filter(value=pe).first(
        )  # TODO: collect for all email records with same value.
        if not v:
            p = Profile()
            p.save()
            collect_email_data(add_contact(ProfileEmail, pe, p.id))
        else:
            collect_email_data(v)
        return

    if NotificationBouncedEmail.objects.filter(email=pe.value).exists():
        pe.bounces = True
        pe.save(update_fields=['bounces'])

    # Replay email events for a given email address and update the ProfileEmail
    for recipient_event in NotificationRecipientEvent.objects.filter(
            email=pe.value).order_by('date_created'):
        event = recipient_event.action
        update_email_status_from_sendgrid(pe.value, event)

    if delete_records:
        NotificationRecipientEvent.objects.filter(email=pe.value).delete()
        NotificationBouncedEmail.objects.filter(email=pe.value).delete()
def create_resumes_for_location(job, count, city, state):
    for _ in range(count):
        profile = Profile(job=job, city=city, state=state)
        profile.save()

        resume = ProfileResume(profile=profile)
        resume.save()
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
Esempio n. 8
0
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()
Esempio n. 9
0
def test_metric_for_empty_profile():
    profile = Profile()
    profile.save()

    metric = calculate_completeness_metric_and_hints(profile)
    assert metric['metric'] == 0
    assert set(
        metric['hints']['add'].keys()) == {'skill', 'education', 'experience'}
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_collect_email_data():
    p = Profile()
    p.save()

    email = "*****@*****.**"
    pe = ProfileEmail(value=email, profile=p)
    pe.save()

    # First, test a bounced email.
    NotificationBouncedEmail(email=email).save()
    collect_email_data(pe)
    assert pe.bounces

    # unbounce it
    NotificationRecipientEvent(email=email, action="delivered").save()
    collect_email_data(pe)
    assert not pe.bounces

    # re-bounce it
    NotificationBouncedEmail(email=email).save()
    collect_email_data(pe)
    assert pe.bounces

    # open it - opening sets opens to True and bounces to False
    NotificationRecipientEvent(email=email, action="open").save()
    collect_email_data(pe)
    assert not pe.bounces and pe.opens

    # open it again. Make sure we're idempotent.
    NotificationRecipientEvent(email=email, action="open").save()
    collect_email_data(pe)
    assert not pe.bounces and pe.opens

    # re-bounce it, but differently
    NotificationRecipientEvent(email=email, action="bounce").save()
    collect_email_data(pe)
    assert pe.bounces

    # test a click.
    NotificationRecipientEvent(email=email, action="click").save()
    collect_email_data(pe)
    assert not pe.bounces and pe.responds

    # try a couple unreleated events, make sure they work
    NotificationRecipientEvent(email=email, action="spamreport").save()
    NotificationRecipientEvent(email=email, action="unsubscribe").save()
    collect_email_data(pe)
    assert pe.reported_spam
    assert pe.unsubscribed

    # resubscribe
    NotificationRecipientEvent(email=email, action="group_resubscribe").save()
    collect_email_data(pe)
    assert not pe.unsubscribed
Esempio n. 12
0
        def on_resume(data, url):
            previously_scraped = ProfileResume.objects.filter(
                url=url).order_by('-date_created').first()

            # Always create a new ProfileResume to preserve precious data
            profile_resume = ProfileResume(url=url,
                                           source=scraper_job.source,
                                           parser_output=data)

            # Copy over the profile from the old resume, if it exists
            if previously_scraped and previously_scraped.profile:
                profile_resume.profile = previously_scraped.profile

            # Ensure the ProfileResume has an attached profile.
            if not profile_resume.profile:
                p = Profile()
                p.save()
                profile_resume.profile = p

            profile_resume.save()

            # Ensure that the attached profile is mapped to at least one job.
            if not ProfileJobMapping.objects.filter(
                    profile_id=profile_resume.profile_id,
                    job_id=scraper_job.job_id).exists():
                ProfileJobMapping(profile_id=profile_resume.profile_id,
                                  job_id=scraper_job.job_id).save()
                self.logger.info("Mapped Profile id {} to Job id {}.".format(
                    profile_resume.profile_id, scraper_job.job_id))

            self.logger.info("Created ProfileResume id {}{}.".format(
                profile_resume.id,
                " (previously scraped)" if previously_scraped else ""))

            scraper_job.refresh_from_db()
            if previously_scraped: scraper_job.resumes_rescraped += 1
            else: scraper_job.new_resumes_scraped += 1
            scraper_job.save()

            print("scraper_job saved--------------")

            print("Starting build profile service now----------")
            print("profile_resume.profile.id : ", profile_resume.profile.id)
            print("profile_resume.id : ", profile_resume.id)

            QueueConnection.quick_publish(queue_name=QueueNames.build_profile,
                                          body=json.dumps({
                                              'profile_id':
                                              profile_resume.profile.id,
                                              'profile_resume_id':
                                              profile_resume.id
                                          }))
            return True
def test_profile_deletion():
    consumer = Consumer.__new__(Consumer)
    profile = Profile(id=9)
    profile.save()
    assert Profile.objects.count() == 1

    msg = {"profile_id": 9}
    consumer.handle_message(json.dumps(msg))
    assert Profile.objects.count() == 1

    profile.queued_for_deletion = True
    profile.save()
    consumer.handle_message(json.dumps(msg))
    assert Profile.objects.count() == 0
Esempio n. 14
0
def test_metric_for_profile_with_certification_error():
    now = timezone.now()

    profile = Profile()
    profile.save()

    skill = Skill(skill_name='whatever')
    skill.save()

    profile_skill = ProfileSkill(profile=profile,
                                 skill=skill,
                                 skill_name=skill.skill_name,
                                 experience_months=6,
                                 last_used_date=now)
    profile_skill.save()

    metric = calculate_completeness_metric_and_hints(profile)
    assert metric['metric'] == 33
    assert set(metric['hints']['add'].keys()) == {'education', 'experience'}
    assert set(metric['hints']['detail'].keys()) == set()
    assert set(metric['hints']['error'].keys()) == set()

    cert = Certification(certification_name="Registered Nurse")
    cert.save()

    profile_certification = ProfileCertification(
        profile=profile,
        certification=cert,
        certification_name=cert.certification_name,
        issued_date=None)
    profile_certification.save()

    metric = calculate_completeness_metric_and_hints(profile)
    assert metric['metric'] == 23
    assert set(metric['hints']['add'].keys()) == {'education', 'experience'}
    assert set(metric['hints']['detail'].keys()) == set()
    assert set(metric['hints']['error'].keys()) == {'certification'}

    profile_certification.certification_name = 'Test Cert'
    profile_certification.issued_date = now
    profile_certification.save()

    metric = calculate_completeness_metric_and_hints(profile)
    assert metric['metric'] == 33
    assert set(metric['hints']['add'].keys()) == {'education', 'experience'}
    assert set(metric['hints']['detail'].keys()) == set()
    assert set(metric['hints']['error'].keys()) == set()
def test_ensure_recipient_verified():
    name_verified = Profile(name_verification_completed=True)
    name_verified.save()

    not_name_verified = Profile(name_verification_completed=False)
    not_name_verified.save()

    noti_a = Notification(type="email", recipient_profile=name_verified)
    noti_a.save()

    noti_b = Notification(type="email", recipient_profile=not_name_verified)
    noti_b.save()

    ensure_recipient_verified(noti_a)  # should not raise

    with pytest.raises(UnverifiedNameException):
        ensure_recipient_verified(noti_b)
def test_add_contact():
    p = Profile()
    p.save()

    # Test input existentiality invariants

    assert add_contact(ProfileEmail, "", p.id) is None
    assert add_contact(ProfileEmail, "", p.id, is_correct_person = True) is None
    assert add_contact(ProfileEmail, "*****@*****.**", None) is None
    assert add_contact(ProfileEmail, "*****@*****.**", None, is_correct_person = True) is None

    # Test add_contact() when the email already exists.

    a = ProfileEmail(value="*****@*****.**", profile=p)
    b = ProfileEmail(value="*****@*****.**", profile=p)

    for email in [a,b]:
        email.save()
    
    ap = add_contact(ProfileEmail, a.value, p.id)
    bp = add_contact(ProfileEmail, b.value, p.id)

    assert ap and ap.id is a.id and ap.value == a.value and ap.is_correct_person == a.is_correct_person
    assert bp and bp.id is b.id and bp.value == b.value and bp.is_correct_person == b.is_correct_person

    # Test add_contact() for a new email.

    c = add_contact(ProfileEmail, "*****@*****.**", p.id)
    assert c and c.id and c.value == "*****@*****.**" and c.id not in [a.id, b.id]

    # Test add_contact() is_correct_person parameter

    d = ProfileEmail(value="*****@*****.**", profile=p)
    e = ProfileEmail(value="*****@*****.**", profile=p, is_correct_person = True)
    f = ProfileEmail(value="*****@*****.**", profile=p, is_correct_person = True)

    for email in [d,e]:
        email.save()

    dp = add_contact(ProfileEmail, d.value, p.id, is_correct_person = True)
    ep = add_contact(ProfileEmail, e.value, p.id, is_correct_person = False)
    fp = add_contact(ProfileEmail, f.value, p.id, is_correct_person = True)

    assert dp.is_correct_person is not d.is_correct_person
    assert ep.is_correct_person is not e.is_correct_person
    assert fp.is_correct_person is f.is_correct_person
def test_email_to_reach_with_valid_is_correct_person():
    """Test to make sure ProfileEmail.to_reach returns `is_correct_person = True` first."""
    p = Profile()
    p.save()

    invalid = ProfileEmail(value="*****@*****.**", profile=p, bounces=True)
    valid = ProfileEmail(value="*****@*****.**", profile=p)
    correct_person = ProfileEmail(value="*****@*****.**", profile=p, is_correct_person=True)

    for email in [invalid, valid, correct_person]:
        email.save()

    test = ProfileEmail.to_reach(p.id)
    assert test.value == correct_person.value

    test_two = ProfileEmail.to_reach(p.id, strict=True)
    assert test_two.value == correct_person.value
Esempio n. 18
0
def make_test_profile():
    state = LookupState(state_code='PA', state_name='Pennsylvania')
    state.save()

    profile = Profile(id=1)
    profile.save()

    for duration in (60, 180, 400, 700, 2000, 7000):
        experience = ProfileExperience(profile=profile)
        experience.company_name = None
        experience.position_title = None
        experience.position_description = None
        experience.end_date = timezone.now()
        experience.start_date = timezone.now() - timedelta(days=duration)
        experience.city = 'Philadelphia'
        experience.state = state
        experience.save()
def test_email_to_reach_valid_before_invalid():
    """Test to make sure ProfileEmail.to_reach only returns sane emails."""
    p = Profile()
    p.save()

    a = ProfileEmail(value="*****@*****.**", profile=p, bounces=True, unsubscribed=False, reported_spam=False)
    b = ProfileEmail(value="*****@*****.**", profile=p, bounces=True, is_correct_person=True)
    valid = ProfileEmail(value="*****@*****.**", profile=p)    

    for email in [a, b, valid]:
        email.save()

    dubious = ProfileEmail.to_reach(p.id)

    assert dubious is not None
    assert dubious.value == valid.value

    assert ProfileEmail.to_reach(p.id, strict=True) is None
def test_no_valid_emails():
    p = Profile()
    p.save()
    INVALID_EMAIL = "*****@*****.**"

    # Invalid emails
    a = ProfileEmail(value=INVALID_EMAIL, profile=p, bounces=True, unsubscribed=False, reported_spam=False)
    b = ProfileEmail(value=INVALID_EMAIL, profile=p, bounces=False, unsubscribed=True, reported_spam=False)
    c = ProfileEmail(value=INVALID_EMAIL, profile=p, bounces=False, unsubscribed=False, reported_spam=True)
    d = ProfileEmail(value=INVALID_EMAIL, profile=p, bounces=True, unsubscribed=True, reported_spam=False)
    e = ProfileEmail(value=INVALID_EMAIL, profile=p, bounces=False, unsubscribed=True, reported_spam=True)
    f = ProfileEmail(value=INVALID_EMAIL, profile=p, bounces=True, unsubscribed=True, reported_spam=True)
    g = ProfileEmail(value=INVALID_EMAIL, profile=p, bounces=True, is_correct_person=True)

    for email in [a,b,c,d,e,f,g]:
        email.save()

    assert ProfileEmail.to_reach(p.id) is None
Esempio n. 21
0
def test_required_field_message():
    now = timezone.now()

    state = LookupState(state_code='PA', state_name='Pennsylvania')
    state.save()

    profile = Profile()
    profile.save()

    experience = ProfileExperience(profile=profile)
    experience.company_name = None
    experience.position_title = None
    experience.position_description = None
    experience.start_date = experience.end_date = now
    experience.city = 'Philadelphia'
    experience.state = state
    experience.save()

    metric = calculate_completeness_metric_and_hints(profile)
    assert metric['metric'] == 20
    assert set(metric['hints']['add']) == {'skill', 'education'}
    assert set(metric['hints']['detail']) == {'experience'}
    assert set(metric['hints']['error']) == {'experience'}

    experience.position_description = "This is a description."
    experience.save()

    metric = calculate_completeness_metric_and_hints(profile)
    assert metric['metric'] == 23
    assert set(metric['hints']['add']) == {'skill', 'education'}
    assert set(metric['hints']['detail']) == set()
    assert set(metric['hints']['error']) == {'experience'}

    experience.company_name = 'Company A'
    experience.position_title = 'RN'
    experience.save()

    metric = calculate_completeness_metric_and_hints(profile)
    assert metric['metric'] == 33
    assert set(metric['hints']['add']) == {'skill', 'education'}
    assert set(metric['hints']['detail']) == set()
    assert set(metric['hints']['error']) == set()
def test_verify_sane():
    p = Profile()
    p.save()

    SANE_EMAIL = "*****@*****.**"
    INSANE_EMAIL = "*****@*****.**"
    UNUSED_EMAIL = "*****@*****.**"

    a = ProfileEmail(value=SANE_EMAIL, profile=p)
    b = ProfileEmail(value=SANE_EMAIL, profile=p, is_correct_person=True)
    c = ProfileEmail(value=INSANE_EMAIL, profile=p, bounces=True)
    d = ProfileEmail(value=INSANE_EMAIL, profile=p, bounces=True, is_correct_person=True)

    for email in [a,b,c,d]:
        email.save()

    assert verify_sane(ProfileEmail, SANE_EMAIL)
    assert not verify_sane(ProfileEmail, INSANE_EMAIL)
    assert verify_sane(ProfileEmail, UNUSED_EMAIL, assume_sane=True)
    assert not verify_sane(ProfileEmail, UNUSED_EMAIL, assume_sane=False)
Esempio n. 23
0
def test_metric_for_complete_profile():
    now = timezone.now()

    state = LookupState(state_code='PA', state_name='Pennsylvania')
    state.save()

    profile = Profile()
    profile.save()

    skill = Skill(skill_name='underwater basket weaving')
    skill.save()

    ProfileSkill(profile=profile,
                 skill=skill,
                 skill_name=skill.skill_name,
                 experience_months=6,
                 last_used_date=now).save()

    education = ProfileEducation(profile=profile)
    education.school_name = 'Collegiate University'
    education.degree_date = now
    education.degree_major = make_new_row(LookupDegreeMajor)
    education.degree_name = make_new_row(LookupDegreeName)
    education.degree_type = make_new_row(LookupDegreeType)
    education.save()

    experience = ProfileExperience(profile=profile)
    experience.company_name = 'Bakround'
    experience.position_title = 'Automated Tester'
    experience.position_description = 'I test things'
    experience.start_date = experience.end_date = now
    experience.city = 'City'
    experience.state = state
    experience.save()

    metric = calculate_completeness_metric_and_hints(profile)
    assert metric['metric'] == 100
    assert set(metric['hints']['add'].keys()) == set()
    assert set(metric['hints']['detail'].keys()) == set()
    assert set(metric['hints']['error'].keys()) == set()
Esempio n. 24
0
def test_email_events():
    notification = Notification(type='email', sent=True)
    notification.save()

    events = json.loads(
        open(
            os.path.join(str(settings.APPS_DIR),
                         "webhooks/tests/sendgrid_webhooks.json"), 'r').read())

    for event in events:
        event['bkrnd_nid'] = notification.id
        notification_recipient = NotificationRecipient(
            notification=notification,
            recipient_email=event['email'],
            sent=True)
        notification_recipient.save()
        p = Profile()
        p.save()
        pe = add_contact(ProfileEmail, event["email"], p.id)

        handle_email_event(event, save_events=True)

        saved_item = NotificationRecipientEvent.objects.filter(
            action=event['event']).first()
        assert saved_item
        assert saved_item.sg_event_id == event['sg_event_id']
        assert saved_item.notification_recipient is not None
        assert saved_item.notification_recipient.notification_id == notification.id

        pe = ProfileEmail.objects.filter(id=pe.id).first()
        assert pe

        if event['event'] == 'bounce':
            assert pe.bounces

        if event['event'] == 'bounce':
            assert len(
                ProfileEmail.objects.filter(value=event['email'],
                                            bounces=True)) > 0
def _make_notification(set_recipient_email=False, set_recipient_profile=False):
    n = Notification(type="email")
    if set_recipient_email:
        # This profile won't be used. It's a means of appeasing
        # the DB schema.
        p = Profile()
        p.save()
        pe = ProfileEmail(value="*****@*****.**", profile=p)
        pe.save()
        n.recipient_email = pe.value
    if set_recipient_profile:
        p = Profile()
        p.save()
        n.recipient_profile = p
        for addr in [
                "*****@*****.**", "*****@*****.**", "*****@*****.**"
        ]:
            pe = ProfileEmail(value=addr, profile=p)
            pe.save()
    n.save()

    return n
def test_generic_lookup_broker():
    # The only part of the generic class that merits testing is the _load_data function.
    p = Profile()
    p.save()

    # Test the case where we don't have a reverse lookup at all
    broker = GenericLookupBroker(profile=p)
    broker.preload()

    assert broker.reverse_lookup is not None
    assert broker._phones == broker.phones == []
    assert broker._emails == broker.emails == []
    assert broker._addresses == broker.addresses == []

    # Test the case where we have a new-ish reverse lookup

    d = ProfileReverseLookup(profile=p, output={}, provider=GenericLookupBroker.provider)
    d.save()

    broker = GenericLookupBroker(profile=p)
    broker.preload()

    assert broker.reverse_lookup.id == d.id

    # Test the case where we have a reverse lookup, but it's too old

    d = ProfileReverseLookup(profile=p, output={}, provider=GenericLookupBroker.provider)
    d.save()
    # Move the created date back a year
    d.date_created = timezone.now() - timedelta(weeks=52)
    d.save()

    print(timezone.now())
    print(d.date_created)

    broker = GenericLookupBroker(profile=p)
    broker.preload()

    assert broker.reverse_lookup.id != d.id
def test_collect_contact_info_for_profile():
    p = Profile(email="*****@*****.**", phone="phonenumber")
    p.save()

    ProfileExternalData(emails=["*****@*****.**"], phones=["ring"], output={"foo": "foo"}, provider="pipl", profile=p).save()
    ProfileExternalData(emails=["*****@*****.**"], phones=["rang"], output={"foo": "bar"}, provider="whitepages", profile=p).save()

    collect_contact_info_for_profile(p)

    p = Profile.objects.get(id=p.id)

    assert ProfileEmail.objects.filter(value="*****@*****.**", profile=p, is_correct_person=True).first()
    assert ProfilePhoneNumber.objects.filter(value="phonenumber", profile=p, is_correct_person=True).first()
    assert ProfileEmail.objects.filter(value="*****@*****.**", profile=p).first()
    assert ProfileEmail.objects.filter(value="*****@*****.**", profile=p).first()
    assert not p.email
    assert not p.phone

    rlookup_one = ProfileReverseLookup.objects.filter(provider="pipl").first()
    rlookup_two = ProfileReverseLookup.objects.filter(provider="whitepages").first()

    assert rlookup_one and rlookup_one.output["foo"] == "foo"
    assert rlookup_two and rlookup_two.output["foo"] == "bar"
Esempio n. 28
0
        def on_resume(data, url):
            job_name = data["icims_job"][0]["value"]

            job_data = list(Job.objects.filter(job_name=job_name))
            if len(job_data) > 0:
                job_id = job_data[0].id
            else:
                job_data = list(
                    Job.objects.filter(
                        job_name__icontains=job_name).order_by('job_name'))
                if len(job_data) > 0:
                    job_id = job_data[0].id
                else:
                    job_id = 1

            ranking_job_id = IcimsJobData.objects.get(job_title=job_name)
            previously_scraped = ProfileResume.objects.filter(
                url=url).order_by('-date_created').first()

            # Always create a new ProfileResume to preserve precious data
            profile_resume = ProfileResume(url=url,
                                           source=ranking_job.source,
                                           parser_output=data)

            # Copy over the profile from the old resume, if it exists
            if previously_scraped and previously_scraped.profile:
                profile_resume.profile = previously_scraped.profile

            # Ensure the ProfileResume has an attached profile.
            if not profile_resume.profile:
                p = Profile()
                p.save()
                profile_resume.profile = p

            profile_resume.save()
            ranking_job.job_id = job_id

            # Ensure that the attached profile is mapped to at least one icims job.
            if not IcimsProfileJobMapping.objects.filter(
                    profile_id=profile_resume.profile_id,
                    job_id=ranking_job.job_id,
                    icims_job_id=ranking_job_id).exists():
                IcimsProfileJobMapping(profile_id=profile_resume.profile_id,
                                       job_id=ranking_job.job_id,
                                       icims_job_id=ranking_job_id).save()
                self.logger.info(
                    "Mapped Icims Profile id {} to icims Job id {}.".format(
                        profile_resume.profile_id, ranking_job_id))

            self.logger.info("Created ProfileResume id {}{}.".format(
                profile_resume.id,
                " (previously scraped)" if previously_scraped else ""))

            ranking_job.refresh_from_db()

            # Ensure that the attached profile is mapped to at least one job.
            if not ProfileJobMapping.objects.filter(
                    profile_id=profile_resume.profile_id,
                    job_id=ranking_job.job_id).exists():
                ProfileJobMapping(profile_id=profile_resume.profile_id,
                                  job_id=ranking_job.job_id).save()
                self.logger.info("Mapped Profile id {} to Job id {}.".format(
                    profile_resume.profile_id, ranking_job.job_id))

            self.logger.info("Created ProfileResume id {}{}.".format(
                profile_resume.id,
                " (previously scraped)" if previously_scraped else ""))

            ranking_job.refresh_from_db()
            if previously_scraped: ranking_job.resumes_rescraped += 1
            else: ranking_job.new_resumes_scraped += 1
            ranking_job.save()

            QueueConnection.quick_publish(queue_name=QueueNames.build_profile,
                                          body=json.dumps({
                                              'profile_id':
                                              profile_resume.profile.id,
                                              'profile_resume_id':
                                              profile_resume.id,
                                              'source':
                                              ranking_job.source
                                          }))
            return True
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_candidate_queue(is_bakround_employee):
    set_up_test(is_bakround_employee)
    create_search_view()

    assert EmployerCandidateQueue.objects.count() == 0

    add_candidates_to_queue()
    assert EmployerCandidateQueue.objects.count() == 0

    employer = Employer.objects.first()
    employer.candidate_queue_enabled = True
    employer.save()

    add_candidates_to_queue()
    # the profiles have no scores yet
    assert EmployerCandidateQueue.objects.count() == 0

    add_score_for_every_profile(350)
    # the profiles are scored too low
    add_candidates_to_queue()
    assert EmployerCandidateQueue.objects.count() == 0

    add_score_for_every_profile(700)
    # the profiles are scored high enough now
    add_candidates_to_queue()
    assert EmployerCandidateQueue.objects.count() == 0  # the job does not have the queue or auto-contact enabled

    EmployerJob.objects.update(candidate_queue_enabled=True,
                               auto_contact_enabled=True)
    add_candidates_to_queue()
    assert EmployerCandidateQueue.objects.count() == 5

    add_candidates_to_queue()
    assert EmployerCandidateQueue.objects.count() == 5

    profile = Profile.objects.order_by('id').first()
    profile.last_updated_date = timezone.now()
    profile.save()

    refresh_view()
    add_candidates_to_queue()
    assert EmployerCandidateQueue.objects.count() == 5
    # print(EmployerCandidateQueue.objects.values_list("profile_id", "profile__first_name"))
    assert EmployerCandidateQueue.objects.values("profile_id").distinct().count() == 5


    # now test the auto-contact feature

    assert EmployerCandidate.objects.count() == 0

    employer = Employer.objects.first()
    employer.auto_contact_enabled = True
    employer.save()

    # add a recently contacted candidate for one of the queued profiles
    employer_job = EmployerJob.objects.first()
    EmployerCandidate(profile=profile,
                      employer_job=employer_job,
                      contacted=True,
                      contacted_date=timezone.now()).save()

    assert EmployerCandidate.objects.count() == 1

    auto_contact_candidates(send_email=False)
    assert EmployerCandidate.objects.count() == 1  # because the user does not have auto-contact enabled

    employer_user = EmployerUser.objects.get()
    employer_user.auto_contact_enabled = True
    employer_user.save()
    auto_contact_candidates(send_email=False)
    assert EmployerCandidate.objects.count() == 5


    # test deletion

    new_profiles = []
    job = Job.objects.first()
    saved_search = EmployerSavedSearch.objects.first()

    for _ in range(2000):
        profile = Profile(job=job)
        profile.save()

        record = EmployerCandidateQueue(employer_job=employer_job,
                                        profile=profile,
                                        employer_saved_search=saved_search,
                                        employer_user=employer_user)
        record.save()

        new_profiles.append(profile)

    assert EmployerCandidateQueue.objects.count() == 2005

    remove_old_records_from_queue_for_employer_job(employer_job)
    assert EmployerCandidateQueue.objects.count() == 2000

    for _ in range(80):
        auto_contact_candidates(send_email=False)  # 25 at a time

    remove_old_records_from_queue_for_employer_job(employer_job)
    assert EmployerCandidateQueue.objects.count() == 1900