Exemplo n.º 1
0
    def test_can_grant_access_to_an_article_if_it_is_associated_to_an_institutional_account(self):
        # Setup
        issue = IssueFactory.create(
            journal=self.journal, date_published=dt.datetime.now(), localidentifier='test',
            open_access=False)
        article = ArticleFactory.create(issue=issue)

        organisation = OrganisationFactory.create()
        subscription = JournalAccessSubscriptionFactory.create(
            journal=self.journal, organisation=organisation)
        InstitutionIPAddressRangeFactory.create(
            subscription=subscription,
            ip_start='192.168.1.2', ip_end='192.168.1.4')

        class MyView(ArticleAccessCheckMixin):
            def get_article(self):
                return article

        request = self.factory.get('/')
        request.user = AnonymousUser()
        parameters = request.META.copy()
        parameters['HTTP_X_FORWARDED_FOR'] = '192.168.1.3'
        request.META = parameters

        view = MyView()
        view.request = request

        # Run # check
        self.assertTrue(view.has_access())
Exemplo n.º 2
0
    def test_can_grant_access_to_an_article_if_it_is_associatd_to_an_institutional_account(self):
        # Setup
        issue = IssueFactory.create(
            journal=self.journal, date_published=dt.datetime.now(), localidentifier='test',
            open_access=True)
        article = ArticleFactory.create(issue=issue)

        policy = PolicyFactory.create(max_accounts=2)
        policy.access_journal.add(self.journal)
        organisation = OrganisationFactory.create()
        institutional_account = InstitutionalAccountFactory(
            institution=organisation, policy=policy)
        InstitutionIPAddressRangeFactory.build(
            institutional_account=institutional_account,
            ip_start='192.168.1.2', ip_end='192.168.1.4')

        class MyView(ArticleAccessCheckMixin):
            def get_article(self):
                return article

        request = self.factory.get('/')
        parameters = request.META.copy()
        parameters['HTTP_X_FORWARDED_FOR'] = '192.168.1.3'
        request.META = parameters

        view = MyView()
        view.request = request

        # Run # check
        self.assertTrue(view.has_access())
Exemplo n.º 3
0
    def test_associates_the_subscription_type_to_the_request_in_case_of_institution(self):
        # Setup
        organisation = OrganisationFactory.create()
        subscription = JournalAccessSubscriptionFactory(
            organisation=organisation)
        InstitutionIPAddressRangeFactory.create(
            subscription=subscription,
            ip_start='192.168.1.2', ip_end='192.168.1.4')

        request = self.factory.get('/')
        parameters = request.META.copy()
        parameters['HTTP_X_FORWARDED_FOR'] = '192.168.1.3'
        request.META = parameters

        middleware = SubscriptionMiddleware()

        # Run
        middleware.process_request(request)

        # Check
        self.assertEqual(request.subscription_type, 'institution')
        self.assertEqual(request.subscription, subscription)
Exemplo n.º 4
0
    def test_associates_the_subscription_type_to_the_request_in_case_of_institution(self):
        # Setup
        policy = PolicyFactory.create(max_accounts=2)
        organisation = OrganisationFactory.create()
        institutional_account = InstitutionalAccountFactory(
            institution=organisation, policy=policy)
        InstitutionIPAddressRangeFactory.create(
            institutional_account=institutional_account,
            ip_start='192.168.1.2', ip_end='192.168.1.4')

        request = self.factory.get('/')
        parameters = request.META.copy()
        parameters['HTTP_X_FORWARDED_FOR'] = '192.168.1.3'
        request.META = parameters

        middleware = SubscriptionMiddleware()

        # Run
        middleware.process_request(request)

        # Check
        self.assertEqual(request.subscription_type, 'institution')
        self.assertEqual(request.institutional_account, institutional_account)
Exemplo n.º 5
0
 def setUp(self):
     self.organisation = OrganisationFactory.create()
     self.subscription = JournalAccessSubscriptionFactory(organisation=self.organisation)