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


Python UserProfile.save方法代码示例

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


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

示例1: test_csrf_token

# 需要导入模块: from moderation.tests.apps.test_app1.models import UserProfile [as 别名]
# 或者: from moderation.tests.apps.test_app1.models.UserProfile import save [as 别名]
    def test_csrf_token(self):
        profile = UserProfile(description='Profile for new user',
                              url='http://www.yahoo.com',
                              user=User.objects.get(username='user1'))

        profile.save()

        self.client.login(username='admin', password='aaaa')

        url = profile.moderated_object.get_admin_moderate_url()

        if django_version == '1.1':
            from django.contrib.csrf.middleware import _make_token

            csrf_token = _make_token(self.client.session.session_key)
            post_data = {'approve': 'Approve',
                         'csrfmiddlewaretoken': csrf_token}
        else:
            post_data = {'approve': 'Approve'}

        response = self.client.post(url, post_data)

        self.assertEqual(response.status_code, 302)

        profile = UserProfile.objects.get(pk=profile.pk)

        self.assertEqual(profile.moderated_object.moderation_status,
                         MODERATION_STATUS_APPROVED)
开发者ID:EBNull,项目名称:django-moderation,代码行数:30,代码来源:__init__.py

示例2: test_if_form_is_initialized_new_object

# 需要导入模块: from moderation.tests.apps.test_app1.models import UserProfile [as 别名]
# 或者: from moderation.tests.apps.test_app1.models.UserProfile import save [as 别名]
    def test_if_form_is_initialized_new_object(self):
        profile = UserProfile(description="New description",
                    url='http://test.com',
                    user=self.user)
        profile.save()

        form = self.ModeratedObjectForm(instance=profile)
        self.assertEqual(form.initial['description'], u'New description')
开发者ID:Inkvi,项目名称:django-moderation,代码行数:10,代码来源:forms.py

示例3: test_moderated_object_is_created_when_not_loaded_from_fixture

# 需要导入模块: from moderation.tests.apps.test_app1.models import UserProfile [as 别名]
# 或者: from moderation.tests.apps.test_app1.models.UserProfile import save [as 别名]
    def test_moderated_object_is_created_when_not_loaded_from_fixture(self):
        profile = UserProfile(description='Profile for new user', 
                              url='http://www.yahoo.com',
                              user=User.objects.get(username='user1'))

        profile.save()

        moderated_objs = ModeratedObject.objects.filter(object_pk=profile.pk)
        self.assertEqual(moderated_objs.count(), 1)
开发者ID:cosi1,项目名称:django-moderation,代码行数:11,代码来源:register.py

示例4: test_form_when_obj_has_no_moderated_obj

# 需要导入模块: from moderation.tests.apps.test_app1.models import UserProfile [as 别名]
# 或者: from moderation.tests.apps.test_app1.models.UserProfile import save [as 别名]
    def test_form_when_obj_has_no_moderated_obj(self):
        self.moderation.unregister(UserProfile)
        profile = UserProfile(description="old description",
                    url='http://test.com',
                    user=self.user)
        profile.save()
        self.moderation.register(UserProfile)

        form = self.ModeratedObjectForm(instance=profile)

        self.assertEqual(form.initial['description'], u'old description')
开发者ID:Inkvi,项目名称:django-moderation,代码行数:13,代码来源:forms.py

示例5: test_approve_moderated_object_new_model_instance

# 需要导入模块: from moderation.tests.apps.test_app1.models import UserProfile [as 别名]
# 或者: from moderation.tests.apps.test_app1.models.UserProfile import save [as 别名]
    def test_approve_moderated_object_new_model_instance(self):
        profile = UserProfile(
            description="Profile for new user", url="http://www.test.com", user=User.objects.get(username="user1")
        )

        profile.save()

        profile.moderated_object.approve(self.user)

        user_profile = UserProfile.objects.get(url="http://www.test.com")

        self.assertEqual(user_profile.description, "Profile for new user")
开发者ID:nickburns2006,项目名称:django-moderation,代码行数:14,代码来源:models.py

示例6: test_send_message_when_object_has_no_moderated_object

# 需要导入模块: from moderation.tests.apps.test_app1.models import UserProfile [as 别名]
# 或者: from moderation.tests.apps.test_app1.models.UserProfile import save [as 别名]
    def test_send_message_when_object_has_no_moderated_object(self):
        profile = UserProfile(description='Profile for new user',
                    url='http://www.yahoo.com',
                    user=User.objects.get(username='user1'))

        profile.save()

        self.admin.send_message(self.request, profile.pk)

        message = self.request.user.message_set.get()
        self.assertEqual(unicode(message), u"This object is not registered "\
                                          u"with the moderation system.")
开发者ID:Inkvi,项目名称:django-moderation,代码行数:14,代码来源:admin.py

示例7: test_bypass_moderation_after_approval

# 需要导入模块: from moderation.tests.apps.test_app1.models import UserProfile [as 别名]
# 或者: from moderation.tests.apps.test_app1.models.UserProfile import save [as 别名]
    def test_bypass_moderation_after_approval(self):
        profile = UserProfile(
            description="Profile for new user", url="http://www.test.com", user=User.objects.get(username="user1")
        )
        profile.save()

        profile.moderated_object.approve(self.user)

        profile.description = "New description"
        profile.save()

        self.assertEqual(profile.moderated_object.moderation_status, MODERATION_STATUS_APPROVED)
开发者ID:Threespot,项目名称:django-moderation,代码行数:14,代码来源:moderator.py

示例8: test_approve_moderated_object_new_model_instance

# 需要导入模块: from moderation.tests.apps.test_app1.models import UserProfile [as 别名]
# 或者: from moderation.tests.apps.test_app1.models.UserProfile import save [as 别名]
    def test_approve_moderated_object_new_model_instance(self):
        profile = UserProfile(description='Profile for new user',
                              url='http://www.test.com',
                              user=User.objects.get(username='user1'))

        profile.save()

        profile.moderated_object.approve(self.user)

        user_profile = UserProfile.objects.get(url='http://www.test.com')

        self.assertEqual(user_profile.description, 'Profile for new user')
开发者ID:EBNull,项目名称:django-moderation,代码行数:14,代码来源:models.py

示例9: test_after_disconnecting_signals_moderation_object

# 需要导入模块: from moderation.tests.apps.test_app1.models import UserProfile [as 别名]
# 或者: from moderation.tests.apps.test_app1.models.UserProfile import save [as 别名]
    def test_after_disconnecting_signals_moderation_object(self):
        self.moderation._connect_signals(UserProfile)
        self.moderation._disconnect_signals(UserProfile)

        profile = UserProfile(description='Profile for new user',
                    url='http://www.yahoo.com',
                    user=User.objects.get(username='user1'))

        profile.save()

        self.assertRaises(ObjectDoesNotExist, ModeratedObject.objects.get,
                          object_pk=profile.pk)
开发者ID:cosi1,项目名称:django-moderation,代码行数:14,代码来源:register.py

示例10: test_get_of_new_object_should_raise_exception

# 需要导入模块: from moderation.tests.apps.test_app1.models import UserProfile [as 别名]
# 或者: from moderation.tests.apps.test_app1.models.UserProfile import save [as 别名]
 def test_get_of_new_object_should_raise_exception(self):
     """Tests if after register of model class with moderation, 
        when new object is created and getting of object 
        raise ObjectDoesNotExist"""
     
     profile = UserProfile(description='Profile for new user',
                 url='http://www.yahoo.com',
                 user=User.objects.get(username='user1'))
     
     profile.save()
       
     self.assertRaises(ObjectDoesNotExist, UserProfile.objects.get,
                       pk=profile.pk)
开发者ID:cosi1,项目名称:django-moderation,代码行数:15,代码来源:register.py

示例11: test_creation_of_moderated_object

# 需要导入模块: from moderation.tests.apps.test_app1.models import UserProfile [as 别名]
# 或者: from moderation.tests.apps.test_app1.models.UserProfile import save [as 别名]
    def test_creation_of_moderated_object(self):
        """
        Test if after create of new object moderated object should be created
        """
        profile = UserProfile(description='Profile for new user',
                    url='http://www.yahoo.com',
                    user=User.objects.get(username='user1'))

        profile.save()
        
        moderated_object = ModeratedObject.objects.get_for_instance(profile)
        
        self.assertEqual(unicode(moderated_object), 
                         u"user1 - http://www.yahoo.com")
开发者ID:cosi1,项目名称:django-moderation,代码行数:16,代码来源:register.py

示例12: test_serialize_of_many_objects

# 需要导入模块: from moderation.tests.apps.test_app1.models import UserProfile [as 别名]
# 或者: from moderation.tests.apps.test_app1.models.UserProfile import save [as 别名]
    def test_serialize_of_many_objects(self):
        """Test if object is propertly serialized to json"""

        profile = UserProfile(description='Profile for new user',
                    url='http://www.test.com',
                    user=User.objects.get(username='user1'))
        profile.save()
        json_field = SerializedObjectField()
        
        self.assertEqual(json_field._serialize(UserProfile.objects.all()),
                       '[{"pk": 1, "model": "test_app1.userprofile", '\
                       '"fields": {"url": "http://www.google.com",'\
                       ' "user": 1, "description": "Old description"}},'\
                       ' {"pk": 2, "model": "test_app1.userprofile", "fields":'\
                       ' {"url": "http://www.test.com", "user": 2, '\
                       '"description": "Profile for new user"}}]')
开发者ID:ixc,项目名称:django-moderation,代码行数:18,代码来源:models.py

示例13: test_pre_save_handler_for_new_object

# 需要导入模块: from moderation.tests.apps.test_app1.models import UserProfile [as 别名]
# 或者: from moderation.tests.apps.test_app1.models.UserProfile import save [as 别名]
    def test_pre_save_handler_for_new_object(self):
        from django.db.models import signals 
        
        signals.pre_save.connect(self.moderation.pre_save_handler,
                                 sender=UserProfile)
        profile = UserProfile(description='Profile for new user',
                    url='http://www.yahoo.com',
                    user=User.objects.get(username='user1'))

        profile.save()

        self.assertRaises(ObjectDoesNotExist,
                          ModeratedObject.objects.get_for_instance,
                          profile)

        signals.pre_save.disconnect(self.moderation.pre_save_handler,
                                    UserProfile)
开发者ID:cosi1,项目名称:django-moderation,代码行数:19,代码来源:register.py

示例14: test_objects_with_same_object_id

# 需要导入模块: from moderation.tests.apps.test_app1.models import UserProfile [as 别名]
# 或者: from moderation.tests.apps.test_app1.models.UserProfile import save [as 别名]
    def test_objects_with_same_object_id(self):
        model1 = ModelWithSlugField2(slug="test")
        model1.save()

        model2 = UserProfile(
            description="Profile for new user", url="http://www.yahoo.com", user=User.objects.get(username="user1")
        )

        model2.save()

        self.assertRaises(MultipleObjectsReturned, ModeratedObject.objects.get, object_pk=model2.pk)

        moderated_obj1 = ModeratedObject.objects.get_for_instance(model1)
        moderated_obj2 = ModeratedObject.objects.get_for_instance(model2)

        self.assertEqual(repr(moderated_obj1), u"<ModeratedObject: ModelWithSlugField2 object>")
        self.assertEqual(repr(moderated_obj2), u"<ModeratedObject: user1 - http://www.yahoo.com>")
开发者ID:ixc,项目名称:django-moderation,代码行数:19,代码来源:menagers.py

示例15: test_if_form_is_initialized_existing_object

# 需要导入模块: from moderation.tests.apps.test_app1.models import UserProfile [as 别名]
# 或者: from moderation.tests.apps.test_app1.models.UserProfile import save [as 别名]
    def test_if_form_is_initialized_existing_object(self):
        profile = UserProfile(description="old description",
                    url='http://test.com',
                    user=self.user)
        profile.save()

        profile.moderated_object.approve(moderated_by=self.user)

        profile.description = u"Changed description"
        profile.save()

        form = self.ModeratedObjectForm(instance=profile)

        profile = UserProfile.objects.get(id=1)

        self.assertEqual(profile.description, u"old description")
        self.assertEqual(form.initial['description'], u'Changed description')
开发者ID:Inkvi,项目名称:django-moderation,代码行数:19,代码来源:forms.py


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