Fixed permission assign test unit

This commit is contained in:
eeintech 2020-10-05 10:52:47 -05:00
parent c910307ce5
commit d980da7247
3 changed files with 6 additions and 2 deletions

View File

@ -101,6 +101,7 @@ class RoleGroupAdmin(admin.ModelAdmin):
def save_formset(self, request, form, formset, change):
formset.save() # this will save the children
# update_fields is required to trigger permissions update
form.instance.save(update_fields=['name']) # form.instance is the parent

View File

@ -335,6 +335,7 @@ def create_missing_rule_sets(sender, instance, **kwargs):
group permissions.
"""
created = kwargs.get('created', False)
# To trigger the group permissions update: update_fields should not be None
update_fields = kwargs.get('update_fields', None)
if created or update_fields:

View File

@ -137,7 +137,8 @@ class RuleSetModelTest(TestCase):
rule.save()
group.save()
# update_fields is required to trigger permissions update
group.save(update_fields=['name'])
# There should now be three permissions for each rule set
self.assertEqual(group.permissions.count(), 3 * len(permission_set))
@ -151,7 +152,8 @@ class RuleSetModelTest(TestCase):
rule.save()
group.save()
# update_fields is required to trigger permissions update
group.save(update_fields=['name'])
# There should now not be any permissions assigned to this group
self.assertEqual(group.permissions.count(), 0)