-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added possibility of excluding fields from moderation change list. Cl…
…oses #23
- Loading branch information
Showing
12 changed files
with
196 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
''' | ||
Package contains acceptance tests for django-moderation | ||
''' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
from django.contrib.auth.models import User | ||
from django.core.urlresolvers import reverse | ||
|
||
from moderation import ModerationManager, GenericModerator | ||
from moderation.tests.test_app.models import UserProfile | ||
from moderation.tests.utils.testsettingsmanager import SettingsTestCase | ||
from moderation.tests.utils import setup_moderation, teardown_moderation | ||
from moderation.diff import get_changes_between_models | ||
|
||
|
||
|
||
class ExcludeAcceptanceTestCase(SettingsTestCase): | ||
''' | ||
As developer i want to have way to ignore/exclude model fields from | ||
moderation | ||
''' | ||
fixtures = ['test_users.json', 'test_moderation.json'] | ||
test_settings = 'moderation.tests.settings.generic' | ||
urls = 'moderation.tests.test_urls' | ||
|
||
def setUp(self): | ||
self.moderation, self.old_moderation = setup_moderation() | ||
|
||
self.client.login(username='admin', password='aaaa') | ||
|
||
class UserProfileModerator(GenericModerator): | ||
fields_exclude = ['url'] | ||
|
||
self.moderation.register(UserProfile, UserProfileModerator) | ||
|
||
def tearDown(self): | ||
teardown_moderation(self.moderation, self.old_moderation, | ||
[UserProfile]) | ||
|
||
def test_excluded_field_shoud_not_be_moderated_when_object_is_edited(self): | ||
''' | ||
Change field that is excluded from moderation, | ||
go to moderation admin | ||
''' | ||
profile = UserProfile.objects.get(user__username='moderator') | ||
|
||
profile.url = 'http://dominno.pl' | ||
|
||
profile.save() | ||
|
||
url = reverse('admin:moderation_moderatedobject_change', | ||
args=(profile.moderated_object.pk,)) | ||
|
||
response = self.client.get(url, {}) | ||
|
||
changes = response.context['changes'] | ||
|
||
self.assertEqual(len(changes), 1) | ||
self.assertEqual(changes[0].change, ('Old description', | ||
'Old description')) | ||
|
||
def test_non_excluded_field_shoud_be_moderated_when_object_is_edited(self): | ||
''' | ||
Change field that is not excluded from moderation, | ||
go to moderation admin | ||
''' | ||
profile = UserProfile.objects.get(user__username='moderator') | ||
|
||
profile.description = 'New description' | ||
|
||
profile.save() | ||
|
||
url = reverse('admin:moderation_moderatedobject_change', | ||
args=(profile.moderated_object.pk,)) | ||
|
||
|
||
response = self.client.get(url, {}) | ||
|
||
changes = response.context['changes'] | ||
|
||
self.assertEqual(len(changes), 1) | ||
self.assertEqual(changes[0].change, ('Old description', | ||
'New description')) | ||
|
||
def test_excluded_field_shoud_not_be_moderated_when_object_is_created(self): | ||
''' | ||
Create new object, only non excluded fields are used by moderation system | ||
''' | ||
profile = UserProfile(description='Profile for new user', | ||
url='http://www.dominno.com', | ||
user=User.objects.get(username='user1')) | ||
profile.save() | ||
|
||
url = reverse('admin:moderation_moderatedobject_change', | ||
args=(profile.moderated_object.pk,)) | ||
|
||
|
||
response = self.client.get(url, {}) | ||
|
||
changes = response.context['changes'] | ||
|
||
self.assertEqual(len(changes), 1) | ||
self.assertEqual(changes[0].change, ('Profile for new user', | ||
'Profile for new user')) | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters