コード例 #1
0
    def test_triggers_the_sending_of_a_notification_email(self):
        # Setup
        AuthorizationFactory.create(
            content_type=ContentType.objects.get_for_model(self.journal),
            object_id=self.journal.id,
            user=self.user,
            authorization_codename=AC.can_manage_individual_subscription.
            codename)

        plan = JournalManagementPlanFactory.create(max_accounts=10)
        JournalManagementSubscriptionFactory.create(journal=self.journal,
                                                    plan=plan)

        post_data = {
            'email': faker.email(),
            'first_name': faker.first_name(),
            'last_name': faker.last_name(),
        }

        self.client.login(username='******', password='******')
        url = reverse('userspace:journal:subscription:create',
                      kwargs={'journal_pk': self.journal.pk})

        # Run
        response = self.client.post(url, post_data, follow=False)

        # Check
        self.assertEqual(response.status_code, 302)
        self.assertEqual(len(mail.outbox), 1)
        self.assertEqual(mail.outbox[0].to[0], post_data['email'])
コード例 #2
0
    def test_can_properly_delete_a_subscription(self):
        # Setup
        AuthorizationFactory.create(
            content_type=ContentType.objects.get_for_model(self.journal),
            object_id=self.journal.id,
            user=self.user,
            authorization_codename=AC.can_manage_individual_subscription.
            codename)

        plan = JournalManagementPlanFactory.create(max_accounts=10)
        JournalManagementSubscriptionFactory.create(journal=self.journal,
                                                    plan=plan)

        subscription = JournalAccessSubscriptionFactory.create(
            user=self.user, journal=self.journal)

        self.client.login(username='******', password='******')
        url = reverse('userspace:journal:subscription:delete',
                      kwargs={
                          'journal_pk': self.journal.pk,
                          'pk': subscription.pk,
                      })

        # Run
        response = self.client.post(url, follow=False)

        # Check
        self.assertEqual(response.status_code, 302)
        self.assertFalse(JournalAccessSubscription.objects.exists())
コード例 #3
0
ファイル: test_views.py プロジェクト: erudit/eruditorg
    def test_shows_the_individual_subscription_authorization_section_with_management(self):
        # Setup
        journal = JournalFactory(collection=self.collection)
        journal.members.add(self.user_granted)
        journal.save()

        ct = ContentType.objects.get(app_label="erudit", model="journal")
        Authorization.objects.create(
            content_type=ct,
            user=self.user_granted,
            object_id=journal.id,
            authorization_codename=AC.can_manage_authorizations.codename)

        plan = JournalManagementPlanFactory.create(max_accounts=10)
        JournalManagementSubscriptionFactory.create(journal=journal, plan=plan)

        self.client.login(username=self.user_granted.username,
                          password="******")

        url = reverse('userspace:journal:authorization:list', args=(journal.pk, ))

        # Run
        response = self.client.get(url, {'codename': AC.can_manage_authorizations.codename})

        # Check
        self.assertEqual(response.status_code, 200)
        self.assertTrue(
            AC.can_manage_individual_subscription.codename
            in response.context['authorizations'])
コード例 #4
0
    def test_shows_the_individual_subscription_authorization_section_with_management(
            self):
        # Setup
        journal = JournalFactory(collection=self.collection)
        journal.members.add(self.user_granted)
        journal.save()

        ct = ContentType.objects.get(app_label="erudit", model="journal")
        Authorization.objects.create(
            content_type=ct,
            user=self.user_granted,
            object_id=journal.id,
            authorization_codename=AC.can_manage_authorizations.codename)

        plan = JournalManagementPlanFactory.create(max_accounts=10)
        JournalManagementSubscriptionFactory.create(journal=journal, plan=plan)

        self.client.login(username=self.user_granted.username, password="******")

        url = reverse('userspace:journal:authorization:list',
                      args=(journal.pk, ))

        # Run
        response = self.client.get(
            url, {'codename': AC.can_manage_authorizations.codename})

        # Check
        self.assertEqual(response.status_code, 200)
        self.assertTrue(AC.can_manage_individual_subscription.codename in
                        response.context['authorizations'])
コード例 #5
0
ファイル: test_views.py プロジェクト: erudit/eruditorg
    def test_provides_only_subscriptions_associated_with_the_current_journal(self):
        # Setup
        AuthorizationFactory.create(
            content_type=ContentType.objects.get_for_model(self.journal),
            object_id=self.journal.id,
            user=self.user,
            authorization_codename=AC.can_manage_individual_subscription.codename,
        )

        plan = JournalManagementPlanFactory.create(max_accounts=10)
        JournalManagementSubscriptionFactory.create(journal=self.journal, plan=plan)

        other_journal = JournalFactory.create(collection=self.collection)
        subscription_1 = JournalAccessSubscriptionFactory.create(user=self.user, journal=self.journal)
        JournalAccessSubscriptionFactory.create(user=self.user, journal=other_journal)

        self.client.login(username="******", password="******")
        url = reverse("userspace:journal:subscription:list", kwargs={"journal_pk": self.journal.pk})

        # Run
        response = self.client.get(url)

        # Check
        self.assertEqual(response.status_code, 200)
        self.assertEqual(list(response.context["subscriptions"]), [subscription_1])
コード例 #6
0
ファイル: test_views.py プロジェクト: erudit/eruditorg
    def test_can_create_an_account_action_for_the_subscription(self):
        # Setup
        AuthorizationFactory.create(
            content_type=ContentType.objects.get_for_model(self.journal),
            object_id=self.journal.id,
            user=self.user,
            authorization_codename=AC.can_manage_individual_subscription.codename,
        )

        plan = JournalManagementPlanFactory.create(max_accounts=10)
        JournalManagementSubscriptionFactory.create(journal=self.journal, plan=plan)

        post_data = {"email": faker.email(), "first_name": faker.first_name(), "last_name": faker.last_name()}

        self.client.login(username="******", password="******")
        url = reverse("userspace:journal:subscription:create", kwargs={"journal_pk": self.journal.pk})

        # Run
        response = self.client.post(url, post_data, follow=False)

        # Check
        self.assertEqual(response.status_code, 302)
        tokens = AccountActionToken.objects.all()
        self.assertEqual(tokens.count(), 1)
        stoken = tokens.first()
        self.assertEqual(stoken.content_object, self.journal)
        self.assertEqual(stoken.email, post_data["email"])
        self.assertEqual(stoken.first_name, post_data["first_name"])
        self.assertEqual(stoken.last_name, post_data["last_name"])
コード例 #7
0
    def test_can_cancel_an_action_token(self):
        # Setup
        AuthorizationFactory.create(
            content_type=ContentType.objects.get_for_model(self.journal),
            object_id=self.journal.id,
            user=self.user,
            authorization_codename=AC.can_manage_individual_subscription.
            codename)

        plan = JournalManagementPlanFactory.create(max_accounts=10)
        JournalManagementSubscriptionFactory.create(journal=self.journal,
                                                    plan=plan)

        token = AccountActionTokenFactory.create(content_object=self.journal)

        self.client.login(username='******', password='******')
        url = reverse('userspace:journal:subscription:cancel',
                      kwargs={
                          'journal_pk': self.journal.pk,
                          'pk': token.pk,
                      })

        # Run
        response = self.client.post(url, follow=False)

        # Check
        self.assertEqual(response.status_code, 302)
        token.refresh_from_db()
        self.assertFalse(token.active)
コード例 #8
0
ファイル: test_views.py プロジェクト: erudit/eruditorg
    def test_can_properly_delete_a_subscription(self):
        # Setup
        AuthorizationFactory.create(
            content_type=ContentType.objects.get_for_model(self.journal),
            object_id=self.journal.id,
            user=self.user,
            authorization_codename=AC.can_manage_individual_subscription.codename,
        )

        plan = JournalManagementPlanFactory.create(max_accounts=10)
        JournalManagementSubscriptionFactory.create(journal=self.journal, plan=plan)

        subscription = JournalAccessSubscriptionFactory.create(user=self.user, journal=self.journal)

        self.client.login(username="******", password="******")
        url = reverse(
            "userspace:journal:subscription:delete", kwargs={"journal_pk": self.journal.pk, "pk": subscription.pk}
        )

        # Run
        response = self.client.post(url, follow=False)

        # Check
        self.assertEqual(response.status_code, 302)
        self.assertFalse(JournalAccessSubscription.objects.exists())
コード例 #9
0
    def test_provides_only_subscriptions_associated_with_the_current_journal(
            self):
        # Setup
        AuthorizationFactory.create(
            content_type=ContentType.objects.get_for_model(self.journal),
            object_id=self.journal.id,
            user=self.user,
            authorization_codename=AC.can_manage_individual_subscription.
            codename)

        plan = JournalManagementPlanFactory.create(max_accounts=10)
        JournalManagementSubscriptionFactory.create(journal=self.journal,
                                                    plan=plan)

        other_journal = JournalFactory.create(collection=self.collection)
        subscription_1 = JournalAccessSubscriptionFactory.create(
            user=self.user, journal=self.journal)
        JournalAccessSubscriptionFactory.create(user=self.user,
                                                journal=other_journal)

        self.client.login(username='******', password='******')
        url = reverse('userspace:journal:subscription:list',
                      kwargs={
                          'journal_pk': self.journal.pk,
                      })

        # Run
        response = self.client.get(url)

        # Check
        self.assertEqual(response.status_code, 200)
        self.assertEqual(list(response.context['subscriptions']), [
            subscription_1,
        ])
コード例 #10
0
    def test_cannot_allow_the_creation_of_subscription_if_the_plan_limit_has_been_reached(
            self):
        # Setup
        plan = JournalManagementPlanFactory.create(code='test', max_accounts=3)
        JournalManagementSubscriptionFactory.create(journal=self.journal,
                                                    plan=plan)
        JournalAccessSubscriptionFactory.create(user=self.user,
                                                journal=self.journal)
        token_1 = AccountActionTokenFactory.create(content_object=self.journal)
        token_2 = AccountActionTokenFactory.create(
            content_object=self.journal)  # noqa
        token_1.consume(self.user)

        AuthorizationFactory.create(
            content_type=ContentType.objects.get_for_model(self.journal),
            object_id=self.journal.id,
            user=self.user,
            authorization_codename=AC.can_manage_individual_subscription.
            codename)

        self.client.login(username='******', password='******')
        url = reverse('userspace:journal:subscription:create',
                      kwargs={'journal_pk': self.journal.pk})

        # Run
        response = self.client.get(url)

        # Check
        self.assertEqual(response.status_code, 302)
コード例 #11
0
    def test_can_create_an_account_action_for_the_subscription(self):
        # Setup
        AuthorizationFactory.create(
            content_type=ContentType.objects.get_for_model(self.journal),
            object_id=self.journal.id,
            user=self.user,
            authorization_codename=AC.can_manage_individual_subscription.
            codename)

        plan = JournalManagementPlanFactory.create(max_accounts=10)
        JournalManagementSubscriptionFactory.create(journal=self.journal,
                                                    plan=plan)

        post_data = {
            'email': faker.email(),
            'first_name': faker.first_name(),
            'last_name': faker.last_name(),
        }

        self.client.login(username='******', password='******')
        url = reverse('userspace:journal:subscription:create',
                      kwargs={'journal_pk': self.journal.pk})

        # Run
        response = self.client.post(url, post_data, follow=False)

        # Check
        self.assertEqual(response.status_code, 302)
        tokens = AccountActionToken.objects.all()
        self.assertEqual(tokens.count(), 1)
        stoken = tokens.first()
        self.assertEqual(stoken.content_object, self.journal)
        self.assertEqual(stoken.email, post_data['email'])
        self.assertEqual(stoken.first_name, post_data['first_name'])
        self.assertEqual(stoken.last_name, post_data['last_name'])
コード例 #12
0
ファイル: test_rules.py プロジェクト: erudit/eruditorg
 def test_knows_if_a_simple_user_can_manage_individual_subscriptions(self):
     # Setup
     AuthorizationFactory.create(
         content_type=ContentType.objects.get_for_model(self.journal), object_id=self.journal.id,
         user=self.user, authorization_codename=AC.can_manage_individual_subscription.codename)
     plan = JournalManagementPlanFactory.create(max_accounts=10)
     JournalManagementSubscriptionFactory.create(journal=self.journal, plan=plan)
     # Run & check
     self.assertTrue(
         self.user.has_perm('subscription.manage_individual_subscription', self.journal))
コード例 #13
0
 def test_knows_if_a_simple_user_can_manage_individual_subscriptions(self):
     # Setup
     AuthorizationFactory.create(
         content_type=ContentType.objects.get_for_model(self.journal),
         object_id=self.journal.id,
         user=self.user,
         authorization_codename=AC.can_manage_individual_subscription.
         codename)
     plan = JournalManagementPlanFactory.create(max_accounts=10)
     JournalManagementSubscriptionFactory.create(journal=self.journal,
                                                 plan=plan)
     # Run & check
     self.assertTrue(
         self.user.has_perm('subscription.manage_individual_subscription',
                            self.journal))
コード例 #14
0
 def test_knows_if_it_is_ongoing_or_not(self):
     # Setup
     now_dt = dt.datetime.now()
     plan = JournalManagementPlanFactory.create(max_accounts=10)
     subscription_1 = JournalManagementSubscriptionFactory.create(
         journal=self.journal, plan=plan)
     subscription_2 = JournalManagementSubscriptionFactory.create(
         journal=self.journal, plan=plan)
     JournalManagementSubscriptionPeriodFactory.create(
         subscription=subscription_1,
         start=now_dt - dt.timedelta(days=10),
         end=now_dt + dt.timedelta(days=8))
     JournalManagementSubscriptionPeriodFactory.create(
         subscription=subscription_2,
         start=now_dt + dt.timedelta(days=10),
         end=now_dt + dt.timedelta(days=8))
     # Run & check
     assert subscription_1.is_ongoing
     assert not subscription_2.is_ongoing
コード例 #15
0
ファイル: test_models.py プロジェクト: erudit/eruditorg
 def test_knows_if_it_is_ongoing_or_not(self):
     # Setup
     now_dt = dt.datetime.now()
     plan = JournalManagementPlanFactory.create(max_accounts=10)
     subscription_1 = JournalManagementSubscriptionFactory.create(
         journal=self.journal, plan=plan)
     subscription_2 = JournalManagementSubscriptionFactory.create(
         journal=self.journal, plan=plan)
     JournalManagementSubscriptionPeriodFactory.create(
         subscription=subscription_1,
         start=now_dt - dt.timedelta(days=10),
         end=now_dt + dt.timedelta(days=8))
     JournalManagementSubscriptionPeriodFactory.create(
         subscription=subscription_2,
         start=now_dt + dt.timedelta(days=10),
         end=now_dt + dt.timedelta(days=8))
     # Run & check
     assert subscription_1.is_ongoing
     assert not subscription_2.is_ongoing
コード例 #16
0
ファイル: test_views.py プロジェクト: erudit/eruditorg
    def test_triggers_the_sending_of_a_notification_email(self):
        # Setup
        AuthorizationFactory.create(
            content_type=ContentType.objects.get_for_model(self.journal),
            object_id=self.journal.id,
            user=self.user,
            authorization_codename=AC.can_manage_individual_subscription.codename,
        )

        plan = JournalManagementPlanFactory.create(max_accounts=10)
        JournalManagementSubscriptionFactory.create(journal=self.journal, plan=plan)

        post_data = {"email": faker.email(), "first_name": faker.first_name(), "last_name": faker.last_name()}

        self.client.login(username="******", password="******")
        url = reverse("userspace:journal:subscription:create", kwargs={"journal_pk": self.journal.pk})

        # Run
        response = self.client.post(url, post_data, follow=False)

        # Check
        self.assertEqual(response.status_code, 302)
        self.assertEqual(len(mail.outbox), 1)
        self.assertEqual(mail.outbox[0].to[0], post_data["email"])
コード例 #17
0
ファイル: test_views.py プロジェクト: erudit/eruditorg
    def test_can_cancel_an_action_token(self):
        # Setup
        AuthorizationFactory.create(
            content_type=ContentType.objects.get_for_model(self.journal),
            object_id=self.journal.id,
            user=self.user,
            authorization_codename=AC.can_manage_individual_subscription.codename,
        )

        plan = JournalManagementPlanFactory.create(max_accounts=10)
        JournalManagementSubscriptionFactory.create(journal=self.journal, plan=plan)

        token = AccountActionTokenFactory.create(content_object=self.journal)

        self.client.login(username="******", password="******")
        url = reverse("userspace:journal:subscription:cancel", kwargs={"journal_pk": self.journal.pk, "pk": token.pk})

        # Run
        response = self.client.post(url, follow=False)

        # Check
        self.assertEqual(response.status_code, 302)
        token.refresh_from_db()
        self.assertFalse(token.active)
コード例 #18
0
ファイル: test_views.py プロジェクト: erudit/eruditorg
    def test_cannot_allow_the_creation_of_subscription_if_the_plan_limit_has_been_reached(self):
        # Setup
        plan = JournalManagementPlanFactory.create(code="test", max_accounts=3)
        JournalManagementSubscriptionFactory.create(journal=self.journal, plan=plan)
        JournalAccessSubscriptionFactory.create(user=self.user, journal=self.journal)
        token_1 = AccountActionTokenFactory.create(content_object=self.journal)
        token_2 = AccountActionTokenFactory.create(content_object=self.journal)  # noqa
        token_1.consume(self.user)

        AuthorizationFactory.create(
            content_type=ContentType.objects.get_for_model(self.journal),
            object_id=self.journal.id,
            user=self.user,
            authorization_codename=AC.can_manage_individual_subscription.codename,
        )

        self.client.login(username="******", password="******")
        url = reverse("userspace:journal:subscription:create", kwargs={"journal_pk": self.journal.pk})

        # Run
        response = self.client.get(url)

        # Check
        self.assertEqual(response.status_code, 302)