def _image_fields(user): profile = get_profile(user) image = profile and profile.image return { "photo_url": image.url if image else "", "photo_token": encrypt_image_token(image.name) if image else "", }
def test_patch_blank_twitter_handle(self): context = UserContext() user = context.user profile = get_profile(user) with self.login(email=self.basic_user().email): url = reverse(UserDetailView.view_name, args=[user.id]) empty_value = "" self.client.patch(url, {"twitter_handle": empty_value}) user.refresh_from_db() profile.refresh_from_db() helper = UserHelper(user) assert helper.field_value("twitter_handle") == empty_value
def test_patch_personal_website_url_with_email_and_password_url(self): context = UserContext(user_type=ENTREPRENEUR_USER_TYPE) user = context.user profile = get_profile(user) with self.login(email=self.basic_user().email): url = reverse(UserDetailView.view_name, args=[user.id]) website_url = "http://*****:*****@beta.lingofante.com/demo/" data = { "personal_website_url": website_url, } self.client.patch(url, data) user.refresh_from_db() profile.refresh_from_db() helper = UserHelper(user) assert helper.field_value("personal_website_url") == website_url
def test_patch_ids(self): context = UserContext(user_type=EXPERT_USER_TYPE) user = context.user profile = get_profile(user) industry = IndustryFactory() program_family = ProgramFamilyFactory() with self.login(email=self.basic_user().email): url = reverse(UserDetailView.view_name, args=[user.id]) self.client.patch(url, { "home_program_family_id": program_family.id, "primary_industry_id": industry.id, }) user.refresh_from_db() profile.refresh_from_db() helper = UserHelper(user) assert (helper.field_value("home_program_family_id") == program_family.id) assert (helper.profile_helper.subject.primary_industry_id == industry.id)
def test_patch_expert_fields(self): context = UserContext(user_type=EXPERT_USER_TYPE) user = context.user profile = get_profile(user) with self.login(email=self.basic_user().email): url = reverse(UserDetailView.view_name, args=[user.id]) company = profile.company + ", Inc." expert_category = ExpertCategoryFactory().name title = "Chief " + profile.title office_hours_topics = "Fungi" referred_by = "me" speaker_topics = "Fungi" data = { "company": company, "expert_category": expert_category, "title": title, "office_hours_interest": True, "office_hours_topics": office_hours_topics, "referred_by": referred_by, "speaker_interest": True, "speaker_topics": speaker_topics, "judge_interest": False, "mentor_interest": True, "mentor_type": "f", "judge_type": "1", } self.client.patch(url, data) user.refresh_from_db() profile.refresh_from_db() helper = UserHelper(user) assert helper.field_value("company") == company assert helper.field_value("expert_category") == expert_category assert helper.field_value("title") == title assert (helper.field_value("office_hours_interest") is True) assert (helper.field_value("office_hours_topics") == office_hours_topics) assert helper.field_value("referred_by") == referred_by assert helper.field_value("speaker_interest") is True assert helper.field_value("speaker_topics") == speaker_topics assert helper.field_value("judge_interest") is False assert helper.field_value("mentor_interest") is True assert helper.field_value("mentor_type") == "f" assert helper.field_value("judge_type") == "1"
def test_patch(self): context = UserContext() user = context.user profile = get_profile(user) with self.login(email=self.basic_user().email): url = reverse(UserDetailView.view_name, args=[user.id]) bio = profile.bio + " I'm an awesome API!" email = user.email + ".org" facebook_url = profile.facebook_url + "/awesome" first_name = "Awesome" is_active = not user.is_active linked_in_url = profile.linked_in_url + "/awesome" website_url = profile.personal_website_url + "/awesome" phone = "+1-555-555-1234" twitter_handle = "@awesome" data = { "bio": bio, "email": email, "facebook_url": facebook_url, "first_name": first_name, "gender": "Male", "is_active": is_active, "linked_in_url": linked_in_url, "personal_website_url": website_url, "phone": phone, "twitter_handle": twitter_handle, } response = self.client.patch(url, data) assert response.status_code == 204 user.refresh_from_db() profile.refresh_from_db() assert user.email == email assert user.first_name == first_name assert user.is_active == is_active helper = UserHelper(user) assert helper.field_value("bio") == bio assert helper.field_value("facebook_url") == facebook_url assert helper.field_value("gender") == "m" assert helper.field_value("linked_in_url") == linked_in_url assert helper.field_value("personal_website_url") == website_url assert helper.field_value("phone") == phone assert helper.field_value("twitter_handle") == twitter_handle
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.profile_helper = ProfileHelper(get_profile(self.subject))
def _user_for_date(date): user = UserContext().user StartupTeamMemberFactory(user=user) override_updated_at(get_profile(user), date) return user
def _image_fields(user): profile = get_profile(user) image = profile and profile.image return {"photo_url": image.url if image else ""}