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()
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_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
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_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 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 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_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
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_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 make_logged_in_client(is_staff=False, is_employer=False): client = Client() # create a staff user and log them in new_username = ''.join( random.choice(string.ascii_letters) for i in range(30)) user = User.objects.create_user(username=new_username, email=new_username) user.is_staff = is_staff user.save() client.force_login(user) # create a profile for this user Job(id=1, job_name="fake").save() Profile(user=user, job_id=1).save() if is_employer: user.is_employer = True user.save() job_family = JobFamily() job_family.save() employer = Employer(company_name="Excellence Incorporated", job_family=job_family) employer.save() EmployerUser(employer=employer, user=user, is_billing_admin=True).save() return client
def set_up_users_and_profile(): User(id=1, username='******').save() User(id=2, username='******', is_staff=True).save() Job(id=1, job_name="skateboarder").save() Profile(id=1, job_id=1, user_id=1, first_name="Bob", last_name="Loblaw").save() ProfileExperience(profile_id=1, company_name="Excellence Incorporated").save() # I am adding a test for education because we had the problem where # the degree major/name/type fields were not being passed to the external view. LookupDegreeMajor(id=1, degree_major_name="Accounting").save() LookupDegreeType(id=1, degree_type_name="Bachelor's", degree_type_sovren="bachelors").save() LookupDegreeName(id=1, degree_type_id=1, degree_name="Bachelor's in Accounting").save() ProfileEducation(profile_id=1, school_name="Collegiate University", degree_major_id=1, degree_name_id=1, degree_type_id=1).save()
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_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
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_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_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
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)
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()
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 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"
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_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
def add_city_and_applicants(city, state_code, latitude, longitude, applicants): state = LookupState.objects.get(state_code=state_code, country_id=1) location = LookupPhysicalLocation( city=city, state=state, latitude=latitude, longitude=longitude) location.save() for (first_name, last_name, job_id, profile_id) in applicants: Profile(id=profile_id, first_name=first_name, last_name=last_name, job_id=job_id, city=city, state=state).save()
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