Esempio n. 1
0
 def test_is_editor_is_false_removes_permission_from_instance(self):
     org_owner_factory = OrganizationOwnerFactory()
     org_user = org_owner_factory.organization_user
     user = org_user.user
     org = org_user.organization
     assign(GUARDIAN_PERMISSION, user, org)
     # Confirm permission is True
     self.assertTrue(user.has_perm(GUARDIAN_PERMISSION, org))
     form = CustomOrganizationUserForm(data={'is_admin': True},
                                       instance=org_user)
     form.cleaned_data = {'is_editor': False}
     form.save()
     # Now it should be False
     self.assertFalse(user.has_perm(GUARDIAN_PERMISSION, org))
Esempio n. 2
0
 def test_is_editor_is_false_removes_permission_from_instance(self):
     org_owner_factory = OrganizationOwnerFactory()
     org_user = org_owner_factory.organization_user
     user = org_user.user
     org = org_user.organization
     assign(GUARDIAN_PERMISSION, user, org)
     # Confirm permission is True
     self.assertTrue(user.has_perm(GUARDIAN_PERMISSION, org))
     form = CustomOrganizationUserForm(data={'is_admin': True},
                                       instance=org_user)
     form.cleaned_data = {'is_editor': False}
     form.save()
     # Now it should be False
     self.assertFalse(user.has_perm(GUARDIAN_PERMISSION, org))
Esempio n. 3
0
 def test_is_editor_is_true_adds_permission_to_instance(self):
     org_owner_factory = OrganizationOwnerFactory()
     org_user = org_owner_factory.organization_user
     user = org_user.user
     org = org_user.organization
     # Check that permission is False
     self.assertFalse(user.has_perm(GUARDIAN_PERMISSION, org))
     # Need to pass {'is_admin': True} for clean_is_admin to validate
     form = CustomOrganizationUserForm(data={'is_admin': True},
                                       instance=org_user)
     form.cleaned_data = {'is_editor': True}
     form.save()
     # Now it should be True
     self.assertTrue(user.has_perm(GUARDIAN_PERMISSION, org))
Esempio n. 4
0
 def test_is_editor_is_true_adds_permission_to_instance(self):
     org_owner_factory = OrganizationOwnerFactory()
     org_user = org_owner_factory.organization_user
     user = org_user.user
     org = org_user.organization
     # Check that permission is False
     self.assertFalse(user.has_perm(GUARDIAN_PERMISSION, org))
     # Need to pass {'is_admin': True} for clean_is_admin to validate
     form = CustomOrganizationUserForm(data={'is_admin': True},
                                       instance=org_user)
     form.cleaned_data = {'is_editor': True}
     form.save()
     # Now it should be True
     self.assertTrue(user.has_perm(GUARDIAN_PERMISSION, org))
Esempio n. 5
0
 def test_user_type_field_is_present_and_boolean_type(self):
     """
     Check that the form contains a boolean for is_editor.
     """
     form = CustomOrganizationUserForm()
     self.assertIn('user_type', form.fields)
     self.assertTrue(isinstance(form.fields['user_type'], ChoiceField))
Esempio n. 6
0
 def test_user_type_editor_adds_permission_to_instance(self):
     """
     When editor is selected, the correct permission is set for that user
     for that organization.
     """
     org_owner = OrganizationOwnerFactory()
     org_user = org_owner.organization_user
     user = org_user.user
     org = org_user.organization
     # Check the user doesn't have the permission
     self.assertFalse(user.has_perm(GUARDIAN_PERMISSION, org))
     # Need to pass {'is_admin': True} for clean_is_admin to validate
     form = CustomOrganizationUserForm(instance=org_user)
     form.cleaned_data = {'user_type': 'editor'}
     form.save()
     # Now they should have the permission
     self.assertTrue(user.has_perm(GUARDIAN_PERMISSION, org))
Esempio n. 7
0
 def test_user_type_editor_adds_permission_to_instance(self):
     """
     When editor is selected, the correct permission is set for that user
     for that organization.
     """
     org_owner = OrganizationOwnerFactory()
     org_user = org_owner.organization_user
     user = org_user.user
     org = org_user.organization
     # Check the user doesn't have the permission
     self.assertFalse(user.has_perm(GUARDIAN_PERMISSION, org))
     # Need to pass {'is_admin': True} for clean_is_admin to validate
     form = CustomOrganizationUserForm(instance=org_user)
     form.cleaned_data = {'user_type': 'editor'}
     form.save()
     # Now they should have the permission
     self.assertTrue(user.has_perm(GUARDIAN_PERMISSION, org))
Esempio n. 8
0
 def test_user_type_viewer_removes_permission_from_instance(self):
     """
     When is_editor gets unticked, the permission is removed. 
     Also implicitly tests is_editor form field's required property because 
     for a BooleanField, False is empty.
     """
     org_owner = OrganizationOwnerFactory()
     org_user = org_owner.organization_user
     user = org_user.user
     org = org_user.organization
     assign_perm(GUARDIAN_PERMISSION, user, org)
     # Confirm user has the permission
     self.assertTrue(user.has_perm(GUARDIAN_PERMISSION, org))
     form = CustomOrganizationUserForm(instance=org_user)
     form.cleaned_data = {'user_type': 'viewer'}
     form.save()
     # Now they shouldn't have the permission
     self.assertFalse(user.has_perm(GUARDIAN_PERMISSION, org))
Esempio n. 9
0
 def test_user_type_viewer_removes_permission_from_instance(self):
     """
     When is_editor gets unticked, the permission is removed. 
     Also implicitly tests is_editor form field's required property because 
     for a BooleanField, False is empty.
     """
     org_owner = OrganizationOwnerFactory()
     org_user = org_owner.organization_user
     user = org_user.user
     org = org_user.organization
     assign_perm(GUARDIAN_PERMISSION, user, org)
     # Confirm user has the permission
     self.assertTrue(user.has_perm(GUARDIAN_PERMISSION, org))
     form = CustomOrganizationUserForm(instance=org_user)
     form.cleaned_data = {'user_type': 'viewer'}
     form.save()
     # Now they shouldn't have the permission
     self.assertFalse(user.has_perm(GUARDIAN_PERMISSION, org))
Esempio n. 10
0
 def test_new_is_editor_field_is_present_and_boolean_type(self):
     form = CustomOrganizationUserForm()
     self.assertTrue('is_editor' in form.fields)
     self.assertTrue(isinstance(form.fields['is_editor'], BooleanField))