Ejemplo n.º 1
0
 def preprint_three(self, user, project_three, provider_three, subject_one, subject_two):
     preprint_three = PreprintFactory(creator=user, project=project_three, filename='darn_reason.txt', provider=provider_three, subjects=[[subject_one._id], [subject_two._id]])
     preprint_three.date_created = '2013-12-11 10:09:08.070605+00:00'
     preprint_three.date_published = '2013-12-11 10:09:08.070605+00:00'
     preprint_three.is_published = False
     preprint_three.save()
     return preprint_three
Ejemplo n.º 2
0
 def preprint_two(self, user, project_two, provider_two, subject_two):
     preprint_two = PreprintFactory(creator=user, project=project_two, filename='howto_reason.txt', provider=provider_two, subjects=[[subject_two._id]])
     preprint_two.created = '2013-12-11 10:09:08.070605+00:00'
     preprint_two.date_published = '2013-12-11 10:09:08.070605+00:00'
     preprint_two.original_publication_date = '2013-12-11 10:09:08.070605+00:00'
     preprint_two.save()
     return preprint_two
Ejemplo n.º 3
0
 def preprint_two(self, user, project_two, provider_two, subject_two):
     preprint_two = PreprintFactory(
         creator=user,
         project=project_two,
         filename='howto_reason.txt',
         provider=provider_two,
         subjects=[[subject_two._id]])
     preprint_two.created = '2013-12-11 10:09:08.070605+00:00'
     preprint_two.date_published = '2013-12-11 10:09:08.070605+00:00'
     preprint_two.original_publication_date = '2013-12-11 10:09:08.070605+00:00'
     preprint_two.save()
     return preprint_two
Ejemplo n.º 4
0
    def test_filter_withdrawn_preprint(self, app, url, user, project_one,
                                       provider_one, provider_two):
        preprint_one = PreprintFactory(is_published=False,
                                       creator=user,
                                       project=project_one,
                                       provider=provider_one)
        preprint_one.date_withdrawn = timezone.now()
        preprint_one.is_public = True
        preprint_one.is_published = True
        preprint_one.date_published = timezone.now()
        preprint_one.machine_state = 'accepted'
        assert preprint_one.ever_public is False
        # Putting this preprint in a weird state, is verified_publishable, but has been
        # withdrawn and ever_public is False.  This is to isolate withdrawal portion of query
        preprint_one.save()

        preprint_two = PreprintFactory(creator=user,
                                       project=project_one,
                                       provider=provider_two)
        preprint_two.date_withdrawn = timezone.now()
        preprint_two.ever_public = True
        preprint_two.save()

        # Unauthenticated can only see withdrawn preprints that have been public
        expected = [preprint_two._id]
        res = app.get(url)
        actual = [preprint['id'] for preprint in res.json['data']]
        assert set(expected) == set(actual)

        # Noncontribs can only see withdrawn preprints that have been public
        user2 = AuthUserFactory()
        expected = [preprint_two._id]
        res = app.get(url, auth=user2.auth)
        actual = [preprint['id'] for preprint in res.json['data']]
        assert set(expected) == set(actual)

        # contribs can only see withdrawn preprints that have been public
        user2 = AuthUserFactory()
        preprint_one.add_contributor(user2, 'read')
        preprint_two.add_contributor(user2, 'read')
        expected = [preprint_two._id]
        res = app.get(url, auth=user2.auth)
        actual = [preprint['id'] for preprint in res.json['data']]
        assert set(expected) == set(actual)

        expected = [preprint_two._id]
        # Admins can only see withdrawn preprints that have been public
        res = app.get(url, auth=user.auth)
        actual = [preprint['id'] for preprint in res.json['data']]
        assert set(expected) == set(actual)
Ejemplo n.º 5
0
    def stuck_preprint(self):
        preprint = PreprintFactory(set_doi=False)
        preprint.date_published = preprint.date_published - timedelta(
            days=settings.DAYS_CROSSREF_DOIS_MUST_BE_STUCK_BEFORE_EMAIL + 1)
        # match guid to the fixture crossref_works_response.json
        guid = preprint.guids.first()
        provider = preprint.provider
        provider.doi_prefix = '10.31236'
        provider.save()
        guid._id = 'guid0'
        guid.save()

        preprint.save()
        return preprint
Ejemplo n.º 6
0
 def preprint_three(
         self, user, project_three, provider_three,
         subject_one, subject_two):
     preprint_three = PreprintFactory(
         creator=user,
         project=project_three,
         filename='darn_reason.txt',
         provider=provider_three,
         subjects=[[subject_one._id], [subject_two._id]])
     preprint_three.created = '2013-12-11 10:09:08.070605+00:00'
     preprint_three.date_published = '2013-12-11 10:09:08.070605+00:00'
     preprint_three.original_publication_date = '2013-12-11 10:09:08.070605+00:00'
     preprint_three.is_published = False
     preprint_three.save()
     return preprint_three
    def test_filter_withdrawn_preprint(self, app, url, user):
        preprint_one = PreprintFactory(is_published=False, creator=user)
        preprint_one.date_withdrawn = timezone.now()
        preprint_one.is_public = True
        preprint_one.is_published = True
        preprint_one.date_published = timezone.now()
        preprint_one.machine_state = 'accepted'
        assert preprint_one.ever_public is False
        # Putting this preprint in a weird state, is verified_publishable, but has been
        # withdrawn and ever_public is False.  This is to isolate withdrawal portion of query
        preprint_one.save()

        preprint_two = PreprintFactory(creator=user)
        preprint_two.date_withdrawn = timezone.now()
        preprint_two.ever_public = True
        preprint_two.save()

        # Unauthenticated users cannot see users/me/preprints
        url = '/{}users/me/preprints/?version=2.2&'.format(API_BASE)
        expected = [preprint_two._id]
        res = app.get(url, expect_errors=True)
        assert res.status_code == 401

        # Noncontribs cannot see withdrawn preprints
        user2 = AuthUserFactory()
        url = '/{}users/{}/preprints/?version=2.2&'.format(API_BASE, user2._id)
        expected = []
        res = app.get(url, auth=user2.auth)
        actual = [preprint['id'] for preprint in res.json['data']]
        assert set(expected) == set(actual)

        # Read contribs - contrib=False on UserPreprints filter so read contribs can only see
        # withdrawn preprints that were once public
        user2 = AuthUserFactory()
        preprint_one.add_contributor(user2, 'read', save=True)
        preprint_two.add_contributor(user2, 'read', save=True)
        url = '/{}users/{}/preprints/?version=2.2&'.format(API_BASE, user2._id)
        expected = [preprint_two._id]
        res = app.get(url, auth=user2.auth)
        actual = [preprint['id'] for preprint in res.json['data']]
        assert set(expected) == set(actual)

        expected = [preprint_two._id]
        # Admin contribs can only see withdrawn preprints that were once public
        res = app.get(url, auth=user.auth)
        actual = [preprint['id'] for preprint in res.json['data']]
        assert set(expected) == set(actual)
    def test_filter_withdrawn_preprint(self, app, url, user):
        preprint_one = PreprintFactory(is_published=False, creator=user)
        preprint_one.date_withdrawn = timezone.now()
        preprint_one.is_public = True
        preprint_one.is_published = True
        preprint_one.date_published = timezone.now()
        preprint_one.machine_state = 'accepted'
        assert preprint_one.ever_public is False
        # Putting this preprint in a weird state, is verified_publishable, but has been
        # withdrawn and ever_public is False.  This is to isolate withdrawal portion of query
        preprint_one.save()

        preprint_two = PreprintFactory(creator=user)
        preprint_two.date_withdrawn = timezone.now()
        preprint_two.ever_public = True
        preprint_two.save()

        # Unauthenticated users cannot see users/me/preprints
        url = '/{}users/me/preprints/?version=2.2&'.format(API_BASE)
        expected = [preprint_two._id]
        res = app.get(url, expect_errors=True)
        assert res.status_code == 401

        # Noncontribs cannot see withdrawn preprints
        user2 = AuthUserFactory()
        url = '/{}users/{}/preprints/?version=2.2&'.format(API_BASE, user2._id)
        expected = []
        res = app.get(url, auth=user2.auth)
        actual = [preprint['id'] for preprint in res.json['data']]
        assert set(expected) == set(actual)

        # Read contribs - contrib=False on UserPreprints filter so read contribs can only see
        # withdrawn preprints that were once public
        user2 = AuthUserFactory()
        preprint_one.add_contributor(user2, permissions.READ, save=True)
        preprint_two.add_contributor(user2, permissions.READ, save=True)
        url = '/{}users/{}/preprints/?version=2.2&'.format(API_BASE, user2._id)
        expected = [preprint_two._id]
        res = app.get(url, auth=user2.auth)
        actual = [preprint['id'] for preprint in res.json['data']]
        assert set(expected) == set(actual)

        expected = [preprint_two._id]
        # Admin contribs can only see withdrawn preprints that were once public
        res = app.get(url, auth=user.auth)
        actual = [preprint['id'] for preprint in res.json['data']]
        assert set(expected) == set(actual)
    def test_filter_withdrawn_preprint(self, app, url, user, project_one, provider_one, provider_two):
        preprint_one = PreprintFactory(is_published=False, creator=user, project=project_one, provider=provider_one)
        preprint_one.date_withdrawn = timezone.now()
        preprint_one.is_public = True
        preprint_one.is_published = True
        preprint_one.date_published = timezone.now()
        preprint_one.machine_state = 'accepted'
        assert preprint_one.ever_public is False
        # Putting this preprint in a weird state, is verified_publishable, but has been
        # withdrawn and ever_public is False.  This is to isolate withdrawal portion of query
        preprint_one.save()

        preprint_two = PreprintFactory(creator=user, project=project_one, provider=provider_two)
        preprint_two.date_withdrawn = timezone.now()
        preprint_two.ever_public = True
        preprint_two.save()

        # Unauthenticated can only see withdrawn preprints that have been public
        expected = [preprint_two._id]
        res = app.get(url)
        actual = [preprint['id'] for preprint in res.json['data']]
        assert set(expected) == set(actual)

        # Noncontribs can only see withdrawn preprints that have been public
        user2 = AuthUserFactory()
        expected = [preprint_two._id]
        res = app.get(url, auth=user2.auth)
        actual = [preprint['id'] for preprint in res.json['data']]
        assert set(expected) == set(actual)

        # contribs can only see withdrawn preprints that have been public
        user2 = AuthUserFactory()
        preprint_one.add_contributor(user2, 'read')
        preprint_two.add_contributor(user2, 'read')
        expected = [preprint_two._id]
        res = app.get(url, auth=user2.auth)
        actual = [preprint['id'] for preprint in res.json['data']]
        assert set(expected) == set(actual)

        expected = [preprint_two._id]
        # Admins can only see withdrawn preprints that have been public
        res = app.get(url, auth=user.auth)
        actual = [preprint['id'] for preprint in res.json['data']]
        assert set(expected) == set(actual)