当前位置: 首页>>代码示例>>Python>>正文


Python ProfileFactory.create方法代码示例

本文整理汇总了Python中profiles.factories.ProfileFactory.create方法的典型用法代码示例。如果您正苦于以下问题:Python ProfileFactory.create方法的具体用法?Python ProfileFactory.create怎么用?Python ProfileFactory.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在profiles.factories.ProfileFactory的用法示例。


在下文中一共展示了ProfileFactory.create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_patch_own_profile

# 需要导入模块: from profiles.factories import ProfileFactory [as 别名]
# 或者: from profiles.factories.ProfileFactory import create [as 别名]
    def test_patch_own_profile(self):
        """
        A user PATCHes their own profile
        """
        with mute_signals(post_save):
            ProfileFactory.create(user=self.user1, filled_out=False, agreed_to_terms_of_service=False)
        self.client.force_login(self.user1)

        with mute_signals(post_save):
            new_profile = ProfileFactory.create(filled_out=False)
        new_profile.user.social_auth.create(
            provider=EdxOrgOAuth2.name,
            uid="{}_edx".format(new_profile.user.username)
        )
        patch_data = ProfileSerializer(new_profile).data
        del patch_data['image']

        resp = self.client.patch(self.url1, content_type="application/json", data=json.dumps(patch_data))
        assert resp.status_code == 200

        old_profile = Profile.objects.get(user__username=self.user1.username)
        for key, value in patch_data.items():
            field = ProfileSerializer().fields[key]

            if isinstance(field, (ListSerializer, SerializerMethodField, ReadOnlyField)) or field.read_only is True:
                # these fields are readonly
                continue
            elif isinstance(field, DateField):
                assert getattr(old_profile, key) == parse(value).date()
            else:
                assert getattr(old_profile, key) == value
开发者ID:mitodl,项目名称:micromasters,代码行数:33,代码来源:views_test.py

示例2: setUpTestData

# 需要导入模块: from profiles.factories import ProfileFactory [as 别名]
# 或者: from profiles.factories.ProfileFactory import create [as 别名]
 def setUpTestData(cls):
     super().setUpTestData()
     with mute_signals(post_save):
         staff_profile = ProfileFactory.create(user__email='[email protected]')
         recipient_profile = ProfileFactory.create(
             user__email='[email protected]',
             email_optin=True,
         )
     cls.staff_user = staff_profile.user
     cls.recipient_user = recipient_profile.user
     cls.program = ProgramFactory.create(financial_aid_availability=False)
     ProgramEnrollmentFactory.create(
         user=cls.recipient_user,
         program=cls.program
     )
     Role.objects.create(
         user=cls.staff_user,
         program=cls.program,
         role=Staff.ROLE_ID
     )
     cls.url_name = 'learner_mail_api'
     cls.request_data = {
         'email_subject': 'email subject',
         'email_body': 'email body'
     }
开发者ID:mitodl,项目名称:micromasters,代码行数:27,代码来源:views_test.py

示例3: test_forbidden_methods

# 需要导入模块: from profiles.factories import ProfileFactory [as 别名]
# 或者: from profiles.factories.ProfileFactory import create [as 别名]
 def test_forbidden_methods(self):
     """
     POST is not implemented.
     """
     with mute_signals(post_save):
         ProfileFactory.create(user=self.user1)
     self.client.force_login(self.user1)
     assert self.client.post(self.url1).status_code == HTTP_405_METHOD_NOT_ALLOWED
开发者ID:mitodl,项目名称:micromasters,代码行数:10,代码来源:views_test.py

示例4: test_anonym_user_get_private_profile

# 需要导入模块: from profiles.factories import ProfileFactory [as 别名]
# 或者: from profiles.factories.ProfileFactory import create [as 别名]
 def test_anonym_user_get_private_profile(self):
     """
     An anonymous user gets user's private profile
     """
     with mute_signals(post_save):
         ProfileFactory.create(user=self.user2, account_privacy=Profile.PRIVATE)
     self.client.logout()
     resp = self.client.get(self.url2)
     assert resp.status_code == HTTP_404_NOT_FOUND
开发者ID:mitodl,项目名称:micromasters,代码行数:11,代码来源:views_test.py

示例5: test_weird_privacy_get_private_profile

# 需要导入模块: from profiles.factories import ProfileFactory [as 别名]
# 或者: from profiles.factories.ProfileFactory import create [as 别名]
 def test_weird_privacy_get_private_profile(self):
     """
     If a user profile has a weird profile setting, it defaults to private
     """
     with mute_signals(post_save):
         ProfileFactory.create(user=self.user2, account_privacy='weird_setting')
         ProfileFactory.create(user=self.user1, verified_micromaster_user=True)
     self.client.force_login(self.user1)
     resp = self.client.get(self.url2)
     assert resp.status_code == HTTP_404_NOT_FOUND
开发者ID:mitodl,项目名称:micromasters,代码行数:12,代码来源:views_test.py

示例6: test_mm_user_get_public_to_mm_profile

# 需要导入模块: from profiles.factories import ProfileFactory [as 别名]
# 或者: from profiles.factories.ProfileFactory import create [as 别名]
 def test_mm_user_get_public_to_mm_profile(self):
     """
     An unverified mm user gets user's public_to_mm profile.
     """
     with mute_signals(post_save):
         ProfileFactory.create(user=self.user2, account_privacy=Profile.PUBLIC_TO_MM)
         ProfileFactory.create(user=self.user1, verified_micromaster_user=False)
     self.client.force_login(self.user1)
     resp = self.client.get(self.url2)
     assert resp.status_code == HTTP_404_NOT_FOUND
开发者ID:mitodl,项目名称:micromasters,代码行数:12,代码来源:views_test.py

示例7: test_vermm_user_get_private_profile

# 需要导入模块: from profiles.factories import ProfileFactory [as 别名]
# 或者: from profiles.factories.ProfileFactory import create [as 别名]
 def test_vermm_user_get_private_profile(self):
     """
     A verified mm user gets user's private profile
     """
     with mute_signals(post_save):
         ProfileFactory.create(user=self.user2, account_privacy=Profile.PRIVATE)
         ProfileFactory.create(user=self.user1, verified_micromaster_user=True)
     self.client.force_login(self.user1)
     resp = self.client.get(self.url2)
     assert resp.status_code == HTTP_404_NOT_FOUND
开发者ID:mitodl,项目名称:micromasters,代码行数:12,代码来源:views_test.py

示例8: test_vermm_user_get_public_profile

# 需要导入模块: from profiles.factories import ProfileFactory [as 别名]
# 或者: from profiles.factories.ProfileFactory import create [as 别名]
 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)
     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)
开发者ID:mitodl,项目名称:micromasters,代码行数:13,代码来源:views_test.py

示例9: test_check_object_permissions

# 需要导入模块: from profiles.factories import ProfileFactory [as 别名]
# 或者: from profiles.factories.ProfileFactory import create [as 别名]
    def test_check_object_permissions(self):
        """
        Make sure check_object_permissions is called at some point so the permissions work correctly
        """
        with mute_signals(post_save):
            ProfileFactory.create(user=self.user1, account_privacy=Profile.PUBLIC)
        self.client.force_login(self.user1)

        with patch.object(ProfileViewSet, 'check_object_permissions', autospec=True) as check_object_permissions:
            self.client.get(self.url1)
        assert check_object_permissions.called
开发者ID:mitodl,项目名称:micromasters,代码行数:13,代码来源:views_test.py

示例10: test_index_program_enrolled_users

# 需要导入模块: from profiles.factories import ProfileFactory [as 别名]
# 或者: from profiles.factories.ProfileFactory import create [as 别名]
    def test_index_program_enrolled_users(self, mock_on_commit):
        """
        Test that index_program_enrolled_users indexes an iterable of program-enrolled users
        """
        num_enrollments = 10
        chunk_size = 4
        with mute_signals(post_save):
            program_enrollments = [
                ProgramEnrollmentFactory.create() for _ in range(num_enrollments)
            ]
            for enrollment in program_enrollments:
                ProfileFactory.create(user=enrollment.user)

        private = [serialize_program_enrolled_user(enrollment) for enrollment in program_enrollments]
        private_dicts = {serialized['id']: serialized for serialized in private}
        public = [serialize_public_enrolled_user(serialized) for serialized in private]
        public_dicts = {serialized['id']: serialized for serialized in public}

        with patch(
            'search.indexing_api._index_chunk', autospec=True, return_value=0
        ) as index_chunk, patch(
            'search.indexing_api.serialize_program_enrolled_user', autospec=True,
            side_effect=lambda x: private_dicts[x.id]
        ) as serialize_mock, patch(
            'search.indexing_api.serialize_public_enrolled_user', autospec=True,
            side_effect=lambda x: public_dicts[x['id']]
        ) as serialize_public_mock:
            index_program_enrolled_users(program_enrollments, chunk_size=chunk_size)
            assert index_chunk.call_count == 6  # 10 enrollments divided in chunks of 4, times the number of types (2)

            public_index = make_alias_name(PUBLIC_ENROLLMENT_INDEX_TYPE, is_reindexing=False)
            private_index = make_alias_name(PRIVATE_ENROLLMENT_INDEX_TYPE, is_reindexing=False)
            for offset in range(0, num_enrollments, chunk_size):
                # each enrollment should get yielded twice to account for each doctype
                index_chunk.assert_any_call(
                    public[offset:offset+4],  # ordered dicts FTW
                    index=public_index
                )
                index_chunk.assert_any_call(
                    private[offset:offset+4],
                    index=private_index
                )

            assert serialize_mock.call_count == len(program_enrollments)
            assert serialize_public_mock.call_count == len(program_enrollments)
            for enrollment in program_enrollments:
                serialize_mock.assert_any_call(enrollment)
                serialize_public_mock.assert_any_call(private_dicts[enrollment.id])
开发者ID:mitodl,项目名称:micromasters,代码行数:50,代码来源:indexing_api_test.py

示例11: test_index_context_logged_in_staff

# 需要导入模块: from profiles.factories import ProfileFactory [as 别名]
# 或者: from profiles.factories.ProfileFactory import create [as 别名]
    def test_index_context_logged_in_staff(self, role):
        """
        Assert context values when logged in as staff for a program
        """
        program = ProgramFactory.create(live=True)
        with mute_signals(post_save):
            profile = ProfileFactory.create()
        Role.objects.create(
            role=role,
            program=program,
            user=profile.user,
        )
        self.client.force_login(profile.user)

        ga_tracking_id = FuzzyText().fuzz()
        with self.settings(
            GA_TRACKING_ID=ga_tracking_id,
        ):
            response = self.client.get('/')
            assert response.context['authenticated'] is True
            assert response.context['username'] is None
            assert response.context['title'] == HomePage.objects.first().title
            assert response.context['is_public'] is True
            assert response.context['has_zendesk_widget'] is True
            assert response.context['is_staff'] is True
            assert response.context['programs'] == [
                (program, None),
            ]
            self.assertContains(response, 'Share this page')
            js_settings = json.loads(response.context['js_settings_json'])
            assert js_settings['gaTrackingID'] == ga_tracking_id
开发者ID:mitodl,项目名称:micromasters,代码行数:33,代码来源:views_test.py

示例12: test_learner_view_needs_paid_learner

# 需要导入模块: from profiles.factories import ProfileFactory [as 别名]
# 或者: from profiles.factories.ProfileFactory import create [as 别名]
    def test_learner_view_needs_paid_learner(self, mock_mailgun_client):
        """
        Test that a learner attempting to email another learner will only succeed if the sender
        has paid for a course run in a program that the recipient is enrolled in
        """
        mock_mailgun_client.send_individual_email.return_value = Mock(
            spec=Response,
            status_code=status.HTTP_200_OK,
            json=mocked_json()
        )
        with mute_signals(post_save):
            learner_profile = ProfileFactory.create(
                user__email='[email protected]',
                email_optin=True,
            )
        learner_user = learner_profile.user
        ProgramEnrollmentFactory.create(user=learner_user, program=self.program)
        CachedEnrollment.objects.filter(user=learner_user).delete()

        self.client.force_login(learner_user)
        url = reverse(self.url_name, kwargs={'student_id': self.recipient_user.profile.student_id})
        resp_post = self.client.post(url, data=self.request_data, format='json')
        assert resp_post.status_code == status.HTTP_403_FORBIDDEN
        CachedEnrollmentFactory.create(user=learner_user, course_run__course__program=self.program, verified=True)
        resp_post = self.client.post(url, data=self.request_data, format='json')
        assert resp_post.status_code == status.HTTP_200_OK
开发者ID:mitodl,项目名称:micromasters,代码行数:28,代码来源:views_test.py

示例13: setUpTestData

# 需要导入模块: from profiles.factories import ProfileFactory [as 别名]
# 或者: from profiles.factories.ProfileFactory import create [as 别名]
 def setUpTestData(cls):
     """
     Create a profile
     """
     super().setUpTestData()
     with mute_signals(post_save):
         cls.profile = ProfileFactory.create()
开发者ID:mitodl,项目名称:micromasters,代码行数:9,代码来源:utils_test.py

示例14: test_sync_user_profile_save_enabled

# 需要导入模块: from profiles.factories import ProfileFactory [as 别名]
# 或者: from profiles.factories.ProfileFactory import create [as 别名]
def test_sync_user_profile_save_enabled(mocker, patched_users_api):
    """Test that sync_user_profile calls the task if enabled on save"""
    mock_task = mocker.patch('discussions.tasks.sync_discussion_user')
    with mute_signals(post_save):
        profile = ProfileFactory.create()
    profile.save()
    mock_task.delay.assert_called_once_with(profile.user_id)
开发者ID:mitodl,项目名称:micromasters,代码行数:9,代码来源:signals_test.py

示例15: test_update_percolate_memberships

# 需要导入模块: from profiles.factories import ProfileFactory [as 别名]
# 或者: from profiles.factories.ProfileFactory import create [as 别名]
    def test_update_percolate_memberships(self, source_type, is_member, query_matches, mock_on_commit):
        """
        Tests that existing memberships are updated where appropriate
        """
        with mute_signals(post_save):
            query = PercolateQueryFactory.create(source_type=source_type)
            profile = ProfileFactory.create(filled_out=True)
            program_enrollment = ProgramEnrollmentFactory.create(user=profile.user)
        membership = PercolateQueryMembershipFactory.create(
            user=profile.user,
            query=query,
            is_member=is_member,
            needs_update=False
        )

        with patch(
            'search.api._search_percolate_queries',
            return_value=[query.id] if query_matches else []
        ) as search_percolate_queries_mock:
            update_percolate_memberships(profile.user, source_type)

        search_percolate_queries_mock.assert_called_once_with(program_enrollment)

        membership.refresh_from_db()
        assert membership.needs_update is (is_member is not query_matches)
开发者ID:mitodl,项目名称:micromasters,代码行数:27,代码来源:api_test.py


注:本文中的profiles.factories.ProfileFactory.create方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。