def test_excluded_field_should_always_be_saved(self): ''' Ensure that excluded fields are always saved to the object. ''' profile = UserProfile(description='Profile for new user', url='http://www.dominno.com', user=User.objects.get(username='******')) profile.save() profile.moderated_object.approve() profile = UserProfile.objects.get(id=profile.id) profile.description = 'New profile' profile.save() profile.url = 'http://dominno.pl' profile.save() profile.moderated_object.approve() profile = UserProfile.objects.get(id=profile.id) self.assertEqual(profile.description, 'New profile') self.assertEqual(profile.url, 'http://dominno.pl') profile.url = 'http://www.google.com' profile.save() profile.moderated_object.approve() profile = UserProfile.objects.get(id=profile.id) self.assertEqual(profile.url, 'http://www.google.com')
def test_bypass_moderation_after_approval(self): profile = UserProfile(description='Profile for new user', url='http://www.test.com', user=User.objects.get(username='******')) profile.save() profile.moderated_object.approve(self.user) profile.description = 'New description' profile.save() self.assertEqual(profile.moderated_object.moderation_status, MODERATION_STATUS_APPROVED)
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 = "Changed description" profile.save() form = self.ModeratedObjectForm(instance=profile) profile = UserProfile.objects.get(id=1) self.assertEqual(profile.description, "old description") self.assertEqual(form.initial['description'], 'Changed description')
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(by=self.user) profile.description = 'Changed description' profile.save() form = self.ModeratedObjectForm(instance=profile) profile = UserProfile.objects.get(id=1) self.assertEqual(profile.description, 'old description') self.assertEqual(form.initial['description'], 'Changed description')