示例#1
0
 def test_vermm_user_get_public_profile(self):
     """
     A verified mm user gets another user's public profile.
     """
     with mute_signals(post_save):
         profile = ProfileFactory.create(user=self.user2,
                                         account_privacy=Profile.PUBLIC)
         ProfileFactory.create(user=self.user1,
                               verified_micromaster_user=True)
     self.client.force_login(self.user1)
     resp = self.client.get(self.url2)
     assert resp.json() == ProfileLimitedSerializer().to_representation(
         profile)
示例#2
0
 def test_mm_user_get_public_profile(self):
     """
     An unverified mm user gets another user's public profile.
     """
     with mute_signals(post_save):
         profile = ProfileFactory.create(user=self.user2,
                                         account_privacy=Profile.PUBLIC)
         ProfileFactory.create(user=self.user1,
                               verified_micromaster_user=False)
     profile_data = ProfileLimitedSerializer(profile).data
     self.client.force_login(self.user1)
     resp = self.client.get(self.url2)
     assert resp.json() == format_image_expectation(profile_data)
 def test_limited(self):  # pylint: disable=no-self-use
     """
     Test limited serializer
     """
     profile = self.create_profile()
     assert ProfileLimitedSerializer().to_representation(profile) == {
         'username':
         get_social_username(profile.user),
         'first_name':
         profile.first_name,
         'last_name':
         profile.last_name,
         'preferred_name':
         profile.preferred_name,
         'gender':
         profile.gender,
         'account_privacy':
         profile.account_privacy,
         'has_profile_image':
         profile.has_profile_image,
         'profile_url_full':
         format_gravatar_url(profile.user.email, GravatarImgSize.FULL),
         'profile_url_large':
         format_gravatar_url(profile.user.email, GravatarImgSize.LARGE),
         'profile_url_medium':
         format_gravatar_url(profile.user.email, GravatarImgSize.MEDIUM),
         'profile_url_small':
         format_gravatar_url(profile.user.email, GravatarImgSize.SMALL),
         'country':
         profile.country,
         'state_or_territory':
         profile.state_or_territory,
         'city':
         profile.city,
         'birth_country':
         profile.birth_country,
         'preferred_language':
         profile.preferred_language,
         'edx_level_of_education':
         profile.edx_level_of_education,
         'education': [
             EducationSerializer().to_representation(education)
             for education in profile.education.all()
         ],
         'work_history': [
             EmploymentSerializer().to_representation(work_history)
             for work_history in profile.work_history.all()
         ]
     }
示例#4
0
 def test_limited(self):
     """
     Test limited serializer
     """
     profile = self.create_profile()
     data = ProfileLimitedSerializer(profile).data
     assert data == {
         'username':
         get_social_username(profile.user),
         'first_name':
         profile.first_name,
         'last_name':
         profile.last_name,
         'full_name':
         profile.full_name,
         'preferred_name':
         profile.preferred_name,
         'gender':
         profile.gender,
         'account_privacy':
         profile.account_privacy,
         'country':
         profile.country,
         'state_or_territory':
         profile.state_or_territory,
         'city':
         profile.city,
         'birth_country':
         profile.birth_country,
         'preferred_language':
         profile.preferred_language,
         'edx_level_of_education':
         profile.edx_level_of_education,
         'education':
         EducationSerializer(profile.education.all(), many=True).data,
         'work_history': (EmploymentSerializer(profile.work_history.all(),
                                               many=True).data),
         'image_medium':
         profile.image_medium.url,
         'about_me':
         profile.about_me,
         'romanized_first_name':
         profile.romanized_first_name,
         'romanized_last_name':
         profile.romanized_last_name,
     }
示例#5
0
    def test_vermm_user_get_public_to_mm_profile(self):
        """
        A verified mm user gets  user's public_to_mm profile.
        """
        with mute_signals(post_save):
            profile = ProfileFactory.create(
                user=self.user2, account_privacy=Profile.PUBLIC_TO_MM)
            ProfileFactory.create(user=self.user1,
                                  verified_micromaster_user=True)
            program = ProgramFactory.create()
            ProgramEnrollment.objects.create(
                program=program,
                user=self.user2,
            )
            ProgramEnrollment.objects.create(
                program=program,
                user=self.user1,
            )

        profile_data = ProfileLimitedSerializer(profile).data
        self.client.force_login(self.user1)
        resp = self.client.get(self.url2)
        assert resp.json() == format_image_expectation(profile_data)