Beispiel #1
0
 def test_can_validate_a_basic_authorization(self):
     # Setup
     form_data = {
         'user': self.user.id,
     }
     form = AuthorizationForm(
         form_data, codename=AC.can_manage_issuesubmission.codename, target=self.journal)
     # Run & check
     self.assertTrue(form.is_valid())
Beispiel #2
0
 def test_can_save_a_basic_authorization(self):
     # Setup
     form_data = {
         'user': self.user.id,
     }
     form = AuthorizationForm(
         form_data, codename=AC.can_manage_issuesubmission.codename, target=self.journal)
     # Run & check
     self.assertTrue(form.is_valid())
     form.save()
     authorization = Authorization.objects.first()
     self.assertEqual(authorization.user, self.user)
     self.assertEqual(authorization.content_object, self.journal)
     self.assertEqual(
         authorization.authorization_codename, AC.can_manage_issuesubmission.codename)
Beispiel #3
0
 def test_do_not_allow_to_create_an_authorization_for_a_user_that_is_already_authorized(self):
     # Setup
     ct = ContentType.objects.get(app_label="erudit", model="journal")
     Authorization.objects.create(
         content_type=ct,
         user=self.user,
         object_id=self.journal.id,
         authorization_codename=AC.can_manage_issuesubmission.codename)
     form_data = {
         'user': self.user.id,
     }
     form = AuthorizationForm(
         form_data, codename=AC.can_manage_issuesubmission.codename, target=self.journal)
     # Run & check
     self.assertFalse(form.is_valid())
     self.assertTrue('user' in form.errors)
Beispiel #4
0
 def test_initializes_the_user_field_with_the_current_journal_members(self):
     # Run & check
     form = AuthorizationForm(
         codename=AC.can_manage_issuesubmission.codename, target=self.journal)
     self.assertEqual(list(form.fields['user'].queryset), list(self.journal.members.all()))