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_get(self):
     context = UserContext()
     user = context.user
     with self.login(email=self.basic_user().email):
         url = reverse(UserDetailView.view_name, args=[user.id])
         response = self.client.get(url)
         assert user.first_name == response.data["first_name"]
         assert user.last_name == response.data["last_name"]
         assert user.last_login == response.data.get("last_login")
         assert user.date_joined == response.data["date_joined"]
         helper = UserHelper(user)
         assert helper.field_value("phone") == response.data["phone"]
         assert (helper.field_value("user_type") ==
                 response.data["user_type"])
 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(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 patch(self, request, pk):
     self.user = User.objects.filter(pk=pk).first()
     if not self.user:
         return Response(status=404, data=NO_USER_ERROR.format(pk))
     helper = UserHelper(self.user)
     data = request.data
     keys = set(data.keys())
     invalid_keys = keys.difference(UserHelper.INPUT_KEYS)
     if invalid_keys:
         helper.errors += [
             INVALID_KEYS_ERROR.format(invalid_keys=list(invalid_keys))]
     valid_keys = set(data.keys()).intersection(UserHelper.INPUT_KEYS)
     valid_data = {}
     for key in valid_keys:
         valid_data[key] = helper.validate(key, data[key])
     if helper.errors:
         return _error_response(helper)
     for field, value in valid_data.items():
         helper.field_setter(field, value)
     helper.save()
     return Response(status=204)
 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,
         }
         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
 def could_be_non_member(self):
     return UserHelper(self.user).profile_helper.is_non_member()
 def could_be_expert(self):
     return UserHelper(self.user).profile_helper.is_expert()