Example #1
0
    def test_post_save_handler_for_existing_object(self):
        from django.db.models import signals

        signals.pre_save.connect(self.moderation.pre_save_handler,
                                 sender=UserProfile)
        signals.post_save.connect(self.moderation.post_save_handler,
                                  sender=UserProfile)
        profile = UserProfile.objects.get(user__username='******')
        moderated_object = ModeratedObject(content_object=profile)
        moderated_object.save()
        moderated_object.approve(by=self.user)

        profile.description = 'New description of user profile'
        profile.save()

        moderated_object = ModeratedObject.objects.get_for_instance(profile)

        original_object = moderated_object.changed_object
        self.assertEqual(original_object.description,
                         'New description of user profile')
        self.assertEqual(UserProfile.objects.get(pk=profile.pk).description,
                         'Old description')

        signals.pre_save.disconnect(self.moderation.pre_save_handler,
                                    UserProfile)
        signals.post_save.disconnect(self.moderation.post_save_handler,
                                     UserProfile)
    def test_filter_moderated_objects_returns_object(self):
        """Test if filter_moderated_objects return object when object
        doesn't have moderated object or deserialized object is <> object"""
        moderated_object = ModeratedObject(content_object=self.profile)
        moderated_object.save()
        moderated_object.approve()

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

        self.assertEqual(str(list(UserProfile.objects.all())),
                         '[<UserProfile: moderator - http://www.google.com>]')
Example #3
0
    def test_filter_moderated_objects_returns_object(self):
        """Test if filter_moderated_objects return object when object 
        doesn't have moderated object or deserialized object is <> object"""
        moderated_object = ModeratedObject(content_object=self.profile)
        moderated_object.save()
        moderated_object.approve()

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

        self.assertEqual(unicode(UserProfile.objects.all()),
                         u'[<UserProfile: moderator - http://www.google.com>]')
Example #4
0
    def test_approve_moderated_object(self):
        """test if after object approval new data is saved."""
        self.profile.description = 'New description'

        moderated_object = ModeratedObject(content_object=self.profile)

        moderated_object.save()

        moderated_object.approve(moderated_by=self.user)

        user_profile = UserProfile.objects.get(user__username='******')

        self.assertEqual(user_profile.description, 'New description')
Example #5
0
    def test_approve_moderated_object(self):
        """test if after object approval new data is saved."""
        self.profile.description = 'New description'

        moderated_object = ModeratedObject(content_object=self.profile)

        moderated_object.save()

        moderated_object.approve(moderated_by=self.user)

        user_profile = UserProfile.objects.get(user__username='******')

        self.assertEqual(user_profile.description, 'New description')
Example #6
0
 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='******'))
     
     moderated_object = ModeratedObject(content_object=profile)
     moderated_object.save()
     
     moderated_object.approve(self.user)
     
     user_profile = UserProfile.objects.get(url='http://www.test.com')
     
     self.assertEqual(user_profile.description, 'Profile for new user')
Example #7
0
    def test_has_object_been_changed_should_be_true(self):
        self.profile.description = 'Old description'
        moderated_object = ModeratedObject(content_object=self.profile)
        moderated_object.save()
        moderated_object.approve(moderated_by=self.user)

        user_profile = self.profile.__class__.objects.get(id=self.profile.id)

        self.profile.description = 'New description'
        moderated_object = ModeratedObject(content_object=self.profile)
        moderated_object.save()

        value = moderated_object.has_object_been_changed(user_profile)

        self.assertEqual(value, True)
Example #8
0
    def test_get_of_existing_object_should_return_old_version_of_object(self):
        """Tests if after register of model class with moderation, 
            when existing object is saved, when getting of object returns 
            old version of object"""
        profile = UserProfile.objects.get(user__username='******')
        moderated_object = ModeratedObject(content_object=profile)
        moderated_object.save()
        moderated_object.approve(by=self.user)

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

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

        self.assertEqual(old_profile.description, 'Old description')
    def test_has_object_been_changed_should_be_true(self):
        self.profile.description = 'Old description'
        moderated_object = ModeratedObject(content_object=self.profile)
        moderated_object.save()
        moderated_object.approve(by=self.user)

        user_profile = self.profile.__class__.objects.get(id=self.profile.id)

        self.profile.description = 'New description'
        moderated_object = ModeratedObject(content_object=self.profile)
        moderated_object.save()

        value = moderated_object.has_object_been_changed(user_profile)

        self.assertEqual(value, True)
Example #10
0
    def test_has_object_been_changed_should_be_true(self):
        self.profile.description = 'Old description'
        moderated_object = ModeratedObject(content_object=self.profile)
        moderated_object.save()
        moderated_object.approve(moderated_by=self.user)

        user_profile = UserProfile.objects.get(user__username='******')

        self.profile.description = 'New description'
        moderated_object = ModeratedObject(content_object=self.profile)
        moderated_object.save()

        value = moderated_object.has_object_been_changed(user_profile)

        self.assertEqual(value, True)