예제 #1
0
    def test_format_preprint_is_deleted_true_if_qatest_tag_is_added(self):
        res = format_preprint(self.preprint)
        preprint = next(v for v in res if v['@type'] == 'preprint')
        assert preprint['is_deleted'] is False

        self.preprint.node.add_tag('qatest', auth=self.auth, save=True)

        res = format_preprint(self.preprint)
        preprint = next(v for v in res if v['@type'] == 'preprint')
        assert preprint['is_deleted'] is True
예제 #2
0
    def test_format_preprint_is_deleted_true_if_qatest_tag_is_added(self):
        res = format_preprint(self.preprint)
        preprint = next(v for v in res if v['@type'] == 'preprint')
        assert preprint['is_deleted'] is False

        self.preprint.node.add_tag('qatest', auth=self.auth, save=True)

        res = format_preprint(self.preprint)
        preprint = next(v for v in res if v['@type'] == 'preprint')
        assert preprint['is_deleted'] is True
예제 #3
0
    def test_format_preprint_is_deleted(self):
        CASES = {
            'is_published': (True, False),
            'is_published': (False, True),
            'node.is_public': (True, False),
            'node.is_public': (False, True),
            'node._is_preprint_orphan': (True, True),
            'node._is_preprint_orphan': (False, False),
            'node.is_deleted': (True, True),
            'node.is_deleted': (False, False),
        }
        for key, (value, is_deleted) in CASES.items():
            target = self.preprint
            for k in key.split('.')[:-1]:
                if k:
                    target = getattr(target, k)
            orig_val = getattr(target, key.split('.')[-1])
            setattr(target, key.split('.')[-1], value)

            res = format_preprint(self.preprint)

            preprint = next(v for v in res if v['@type'] == 'preprint')
            assert preprint['is_deleted'] is is_deleted

            setattr(target, key.split('.')[-1], orig_val)
예제 #4
0
    def test_format_preprint_is_deleted(self):
        CASES = {
            'is_published': (True, False),
            'is_published': (False, True),
            'node.is_public': (True, False),
            'node.is_public': (False, True),
            'node._is_preprint_orphan': (True, True),
            'node._is_preprint_orphan': (False, False),
            'node.is_deleted': (True, True),
            'node.is_deleted': (False, False),
        }
        for key, (value, is_deleted) in CASES.items():
            target = self.preprint
            for k in key.split('.')[:-1]:
                if k:
                    target = getattr(target, k)
            orig_val = getattr(target, key.split('.')[-1])
            setattr(target, key.split('.')[-1], value)

            res = format_preprint(self.preprint,
                                  self.preprint.provider.share_publish_type)

            preprint = next(v for v in res if v['@type'] == 'preprint')
            assert preprint['is_deleted'] is is_deleted

            setattr(target, key.split('.')[-1], orig_val)
예제 #5
0
 def test_format_preprint_date_modified_node_updated(self):
     self.preprint.node.save()
     res = format_preprint(self.preprint,
                           self.preprint.provider.share_publish_type)
     nodes = dict(enumerate(res))
     preprint = nodes.pop(
         next(k for k, v in nodes.items() if v['@type'] == 'preprint'))
     assert preprint[
         'date_updated'] == self.preprint.node.modified.isoformat()
예제 #6
0
    def test_format_thesis(self):
        res = format_preprint(self.thesis, self.thesis.provider.share_publish_type)

        assert set(gn['@type'] for gn in res) == {'creator', 'contributor', 'throughsubjects', 'subject', 'throughtags', 'tag', 'workidentifier', 'agentidentifier', 'person', 'thesis', 'workrelation', 'creativework'}

        nodes = dict(enumerate(res))
        thesis = nodes.pop(next(k for k, v in nodes.items() if v['@type'] == 'thesis'))
        assert thesis['title'] == self.thesis.node.title
        assert thesis['description'] == self.thesis.node.description
예제 #7
0
    def test_format_thesis(self):
        res = format_preprint(self.thesis, self.thesis.provider.share_publish_type)

        assert set(gn['@type'] for gn in res) == {'creator', 'contributor', 'throughsubjects', 'subject', 'throughtags', 'tag', 'workidentifier', 'agentidentifier', 'person', 'thesis', 'workrelation', 'creativework'}

        nodes = dict(enumerate(res))
        thesis = nodes.pop(next(k for k, v in nodes.items() if v['@type'] == 'thesis'))
        assert thesis['title'] == self.thesis.node.title
        assert thesis['description'] == self.thesis.node.description
예제 #8
0
    def test_format_preprint(self):
        res = format_preprint(self.preprint)
        types = [gn['@type'] for gn in res]
        subject_names = [x['text'] for hier in self.preprint.get_subjects() for x in hier]
        contribs = {}
        for i, user in enumerate(self.preprint.node.contributors):
            contribs.update({i: user})

        for type_ in ['throughlinks', 'throughsubjects', 'throughidentifiers', 'preprint', 'subject', 'person', 'link', 'contributor', 'identifier', 'person']:
            assert type_ in types

        for graph_node in res:
            if graph_node['@type'] == 'throughlinks':
                assert_equal(set(graph_node.keys()), set(['@id', '@type', 'creative_work', 'link']))
            if graph_node['@type'] == 'throughsubjects':
                assert_equal(set(graph_node.keys()), set(['@id', '@type', 'creative_work', 'subject']))
            if graph_node['@type'] == 'throughidentifiers':
                assert_equal(set(graph_node.keys()), set(['@id', '@type', 'identifier', 'person']))
            if graph_node['@type'] == 'preprint':
                assert_equal(set(graph_node.keys()), set([
                    '@id', '@type', 'contributors', 'title', 'tags',
                    'date_published', 'date_updated', 'description',
                    'institutions', 'is_deleted', 'links', 'subjects',
                ]))
                assert_equal(graph_node['date_published'], self.preprint.date_published.isoformat())
                assert_equal(graph_node['date_updated'], self.preprint.date_modified.isoformat())
                assert_equal(graph_node['description'], self.preprint.node.description)
                assert_equal(graph_node['is_deleted'], self.preprint.node.is_deleted)
                assert_equal(graph_node['title'], self.preprint.node.title)
            if graph_node['@type'] == 'subject':
                assert_equal(set(graph_node.keys()), set(['@id', '@type', 'name']))
                assert_in(graph_node['name'], subject_names)
            if graph_node['@type'] == 'person':
                assert_equal(set(graph_node.keys()), set([
                    '@id', '@type', 'additional_name', 'affiliations',
                    'family_name', 'given_name', 'identifiers', 'suffix'
                ]))
            if graph_node['@type'] == 'link':
                assert_equal(set(graph_node.keys()), set(['@id', '@type', 'type', 'url']))
            if graph_node['@type'] == 'contributor':
                assert_equal(set(graph_node.keys()), set([
                    '@id', '@type',  'bibliographic', 'cited_name',
                    'creative_work', 'order_cited', 'person'
                ]))
                user = contribs[graph_node['order_cited']]
                assert_equal(graph_node['cited_name'], user.fullname)
                assert_equal(graph_node['bibliographic'], bool(user._id in self.preprint.node.visible_contributor_ids))
            if graph_node['@type'] == 'identifier':
                assert_equal(set(graph_node.keys()), set(['@id', '@type', 'base_url', 'url']))
예제 #9
0
    def test_format_preprint_nones(self):
        self.preprint.node.tags = []
        self.preprint.date_published = None
        self.preprint.node.preprint_article_doi = None
        self.preprint.set_subjects([], auth=Auth(self.preprint.node.creator))

        res = format_preprint(self.preprint,
                              self.preprint.provider.share_publish_type)

        assert self.preprint.provider != 'osf'
        assert set(gn['@type'] for gn in res) == {
            'creator', 'contributor', 'workidentifier', 'agentidentifier',
            'person', 'preprint'
        }

        nodes = dict(enumerate(res))
        preprint = nodes.pop(
            next(k for k, v in nodes.items() if v['@type'] == 'preprint'))
        assert preprint['title'] == self.preprint.node.title
        assert preprint['description'] == self.preprint.node.description
        assert preprint['is_deleted'] == (
            not self.preprint.is_published or not self.preprint.node.is_public
            or self.preprint.node.is_preprint_orphan)
        assert preprint['date_updated'] == self.preprint.modified.isoformat()
        assert preprint.get('date_published') is None

        people = sorted(
            [nodes.pop(k) for k, v in nodes.items() if v['@type'] == 'person'],
            key=lambda x: x['given_name'])
        expected_people = sorted(
            [{
                '@type': 'person',
                'given_name': u'BoJack',
                'family_name': u'Horseman',
            }, {
                '@type': 'person',
                'given_name': self.user.given_name,
                'family_name': self.user.family_name,
            }, {
                '@type': 'person',
                'given_name': self.preprint.node.creator.given_name,
                'family_name': self.preprint.node.creator.family_name,
            }],
            key=lambda x: x['given_name'])
        for i, p in enumerate(expected_people):
            expected_people[i]['@id'] = people[i]['@id']

        assert people == expected_people

        creators = sorted([
            nodes.pop(k) for k, v in nodes.items() if v['@type'] == 'creator'
        ],
                          key=lambda x: x['order_cited'])
        assert creators == [{
            '@id': creators[0]['@id'],
            '@type': 'creator',
            'order_cited': 0,
            'cited_as': self.preprint.node.creator.fullname,
            'agent': {
                '@id': [
                    p['@id'] for p in people
                    if p['given_name'] == self.preprint.node.creator.given_name
                ][0],
                '@type':
                'person'
            },
            'creative_work': {
                '@id': preprint['@id'],
                '@type': preprint['@type']
            },
        }, {
            '@id': creators[1]['@id'],
            '@type': 'creator',
            'order_cited': 1,
            'cited_as': u'BoJack Horseman',
            'agent': {
                '@id':
                [p['@id'] for p in people if p['given_name'] == u'BoJack'][0],
                '@type':
                'person'
            },
            'creative_work': {
                '@id': preprint['@id'],
                '@type': preprint['@type']
            },
        }]

        contributors = [
            nodes.pop(k) for k, v in nodes.items()
            if v['@type'] == 'contributor'
        ]
        assert contributors == [{
            '@id': contributors[0]['@id'],
            '@type': 'contributor',
            'cited_as': self.user.fullname,
            'agent': {
                '@id': [
                    p['@id'] for p in people
                    if p['given_name'] == self.user.given_name
                ][0],
                '@type':
                'person'
            },
            'creative_work': {
                '@id': preprint['@id'],
                '@type': preprint['@type']
            },
        }]

        agentidentifiers = {
            nodes.pop(k)['uri']
            for k, v in nodes.items() if v['@type'] == 'agentidentifier'
        }
        assert agentidentifiers == set([
            'mailto:' + self.user.username,
            'mailto:' + self.preprint.node.creator.username,
            self.user.profile_image_url(),
            self.preprint.node.creator.profile_image_url(),
        ]) | set(user.absolute_url for user in self.preprint.node.contributors)

        workidentifiers = {
            nodes.pop(k)['uri']
            for k, v in nodes.items() if v['@type'] == 'workidentifier'
        }
        # URLs should *always* be osf.io/guid/
        assert workidentifiers == set([
            urlparse.urljoin(settings.DOMAIN, self.preprint._id) + '/',
            'http://dx.doi.org/{}'.format(
                self.preprint.get_identifier('doi').value)
        ])

        assert nodes == {}
예제 #10
0
    def test_format_preprint(self):
        res = format_preprint(self.preprint,
                              self.preprint.provider.share_publish_type)

        assert set(gn['@type'] for gn in res) == {
            'creator', 'contributor', 'throughsubjects', 'subject',
            'throughtags', 'tag', 'workidentifier', 'agentidentifier',
            'person', 'preprint', 'workrelation', 'creativework'
        }

        nodes = dict(enumerate(res))
        preprint = nodes.pop(
            next(k for k, v in nodes.items() if v['@type'] == 'preprint'))
        assert preprint['title'] == self.preprint.node.title
        assert preprint['description'] == self.preprint.node.description
        assert preprint['is_deleted'] == (
            not self.preprint.is_published or not self.preprint.node.is_public
            or self.preprint.node.is_preprint_orphan)
        assert preprint['date_updated'] == self.preprint.modified.isoformat()
        assert preprint[
            'date_published'] == self.preprint.date_published.isoformat()

        tags = [nodes.pop(k) for k, v in nodes.items() if v['@type'] == 'tag']
        through_tags = [
            nodes.pop(k) for k, v in nodes.items()
            if v['@type'] == 'throughtags'
        ]
        assert sorted(tag['@id']
                      for tag in tags) == sorted(tt['tag']['@id']
                                                 for tt in through_tags)
        assert sorted(tag['name'] for tag in tags) == ['preprint', 'spoderman']

        subjects = [
            nodes.pop(k) for k, v in nodes.items() if v['@type'] == 'subject'
        ]
        through_subjects = [
            nodes.pop(k) for k, v in nodes.items()
            if v['@type'] == 'throughsubjects'
        ]
        s_ids = [s['@id'] for s in subjects]
        ts_ids = [ts['subject']['@id'] for ts in through_subjects]
        cs_ids = [
            i for i in set(
                s.get('central_synonym', {}).get('@id') for s in subjects) if i
        ]
        for ts in ts_ids:
            assert ts in s_ids
            assert ts not in cs_ids  # Only aliased subjects are connected to self.preprint
        for s in subjects:
            subject = Subject.objects.get(text=s['name'])
            assert s['uri'].endswith('v2/taxonomies/{}/'.format(
                subject._id))  # This cannot change
        assert set(subject['name'] for subject in subjects) == set(
            [s.text for s in self.preprint.subjects.all()] + [
                s.bepress_subject.text for s in self.preprint.subjects.filter(
                    bepress_subject__isnull=False)
            ])

        people = sorted(
            [nodes.pop(k) for k, v in nodes.items() if v['@type'] == 'person'],
            key=lambda x: x['given_name'])
        expected_people = sorted(
            [{
                '@type': 'person',
                'given_name': u'BoJack',
                'family_name': u'Horseman',
            }, {
                '@type': 'person',
                'given_name': self.user.given_name,
                'family_name': self.user.family_name,
            }, {
                '@type': 'person',
                'given_name': self.preprint.node.creator.given_name,
                'family_name': self.preprint.node.creator.family_name,
            }],
            key=lambda x: x['given_name'])
        for i, p in enumerate(expected_people):
            expected_people[i]['@id'] = people[i]['@id']

        assert people == expected_people

        creators = sorted([
            nodes.pop(k) for k, v in nodes.items() if v['@type'] == 'creator'
        ],
                          key=lambda x: x['order_cited'])
        assert creators == [{
            '@id':
            creators[0]['@id'],
            '@type':
            'creator',
            'order_cited':
            0,
            'cited_as':
            u'{}'.format(self.preprint.node.creator.fullname),
            'agent': {
                '@id': [
                    p['@id'] for p in people
                    if p['given_name'] == self.preprint.node.creator.given_name
                ][0],
                '@type':
                'person'
            },
            'creative_work': {
                '@id': preprint['@id'],
                '@type': preprint['@type']
            },
        }, {
            '@id': creators[1]['@id'],
            '@type': 'creator',
            'order_cited': 1,
            'cited_as': u'BoJack Horseman',
            'agent': {
                '@id':
                [p['@id'] for p in people if p['given_name'] == u'BoJack'][0],
                '@type':
                'person'
            },
            'creative_work': {
                '@id': preprint['@id'],
                '@type': preprint['@type']
            },
        }]

        contributors = [
            nodes.pop(k) for k, v in nodes.items()
            if v['@type'] == 'contributor'
        ]
        assert contributors == [{
            '@id': contributors[0]['@id'],
            '@type': 'contributor',
            'cited_as': u'{}'.format(self.user.fullname),
            'agent': {
                '@id': [
                    p['@id'] for p in people
                    if p['given_name'] == self.user.given_name
                ][0],
                '@type':
                'person'
            },
            'creative_work': {
                '@id': preprint['@id'],
                '@type': preprint['@type']
            },
        }]

        agentidentifiers = {
            nodes.pop(k)['uri']
            for k, v in nodes.items() if v['@type'] == 'agentidentifier'
        }
        assert agentidentifiers == set([
            'mailto:' + self.user.username,
            'mailto:' + self.preprint.node.creator.username,
            self.user.profile_image_url(),
            self.preprint.node.creator.profile_image_url(),
        ]) | set(user.absolute_url for user in self.preprint.node.contributors)

        related_work = next(
            nodes.pop(k) for k, v in nodes.items()
            if v['@type'] == 'creativework')
        assert set(related_work.keys()) == {'@id', '@type'
                                            }  # Empty except @id and @type

        osf_doi = next(
            nodes.pop(k) for k, v in nodes.items()
            if v['@type'] == 'workidentifier' and 'doi' in v['uri']
            and 'osf.io' in v['uri'])
        assert osf_doi['creative_work'] == {
            '@id': preprint['@id'],
            '@type': preprint['@type']
        }

        related_doi = next(
            nodes.pop(k) for k, v in nodes.items()
            if v['@type'] == 'workidentifier' and 'doi' in v['uri'])
        assert related_doi['creative_work'] == related_work

        workidentifiers = [
            nodes.pop(k)['uri'] for k, v in nodes.items()
            if v['@type'] == 'workidentifier'
        ]
        assert workidentifiers == [
            urlparse.urljoin(settings.DOMAIN, self.preprint._id + '/')
        ]

        relation = nodes.pop(nodes.keys()[0])
        assert relation == {
            '@id': relation['@id'],
            '@type': 'workrelation',
            'related': {
                '@id': related_work['@id'],
                '@type': related_work['@type']
            },
            'subject': {
                '@id': preprint['@id'],
                '@type': preprint['@type']
            }
        }

        assert nodes == {}
예제 #11
0
    def test_format_preprint_nones(self):
        self.preprint.node.tags = []
        self.preprint.date_published = None
        self.preprint.node.preprint_article_doi = None
        self.preprint.set_subjects([], auth=Auth(self.preprint.node.creator), save=False)

        res = format_preprint(self.preprint)

        assert self.preprint.provider != 'osf'
        assert set(gn['@type'] for gn in res) == {'creator', 'contributor', 'workidentifier', 'agentidentifier', 'person', 'preprint'}

        nodes = dict(enumerate(res))
        preprint = nodes.pop(next(k for k, v in nodes.items() if v['@type'] == 'preprint'))
        assert preprint['title'] == self.preprint.node.title
        assert preprint['description'] == self.preprint.node.description
        assert preprint['is_deleted'] == (not self.preprint.is_published or not self.preprint.node.is_public or self.preprint.node.is_preprint_orphan)
        assert preprint['date_updated'] == self.preprint.date_modified.isoformat()
        assert preprint.get('date_published') is None

        people = sorted([nodes.pop(k) for k, v in nodes.items() if v['@type'] == 'person'], key=lambda x: x['given_name'])
        expected_people = sorted([{
            '@type': 'person',
            'given_name': u'BoJack',
            'family_name': u'Horseman',
        }, {
            '@type': 'person',
            'given_name': self.user.given_name,
            'family_name': self.user.family_name,
        }, {
            '@type': 'person',
            'given_name': self.preprint.node.creator.given_name,
            'family_name': self.preprint.node.creator.family_name,
        }], key=lambda x: x['given_name'])
        for i, p in enumerate(expected_people):
            expected_people[i]['@id'] = people[i]['@id']

        assert people == expected_people

        creators = sorted([nodes.pop(k) for k, v in nodes.items() if v['@type'] == 'creator'], key=lambda x: x['order_cited'])
        assert creators == [{
            '@id': creators[0]['@id'],
            '@type': 'creator',
            'order_cited': 0,
            'cited_as': self.preprint.node.creator.fullname,
            'agent': {'@id': [p['@id'] for p in people if p['given_name'] == self.preprint.node.creator.given_name][0], '@type': 'person'},
            'creative_work': {'@id': preprint['@id'], '@type': preprint['@type']},
        }, {
            '@id': creators[1]['@id'],
            '@type': 'creator',
            'order_cited': 1,
            'cited_as': u'BoJack Horseman',
            'agent': {'@id': [p['@id'] for p in people if p['given_name'] == u'BoJack'][0], '@type': 'person'},
            'creative_work': {'@id': preprint['@id'], '@type': preprint['@type']},
        }]

        contributors = [nodes.pop(k) for k, v in nodes.items() if v['@type'] == 'contributor']
        assert contributors == [{
            '@id': contributors[0]['@id'],
            '@type': 'contributor',
            'cited_as': self.user.fullname,
            'agent': {'@id': [p['@id'] for p in people if p['given_name'] == self.user.given_name][0], '@type': 'person'},
            'creative_work': {'@id': preprint['@id'], '@type': preprint['@type']},
        }]

        agentidentifiers = {nodes.pop(k)['uri'] for k, v in nodes.items() if v['@type'] == 'agentidentifier'}
        assert agentidentifiers == set([
            'mailto:' + self.user.username,
            'mailto:' + self.preprint.node.creator.username,
            self.user.profile_image_url(),
            self.preprint.node.creator.profile_image_url(),
        ]) | set(urlparse.urljoin(settings.DOMAIN, user.profile_url) for user in self.preprint.node.contributors if user.is_registered)

        workidentifiers = {nodes.pop(k)['uri'] for k, v in nodes.items() if v['@type'] == 'workidentifier'}
        # URLs should *always* be osf.io/guid/
        assert workidentifiers == set([urlparse.urljoin(settings.DOMAIN, self.preprint._id) + '/', 'http://dx.doi.org/{}'.format(self.preprint.get_identifier('doi').value)])

        assert nodes == {}
예제 #12
0
    def test_format_preprint(self):
        res = format_preprint(self.preprint)

        assert set(gn['@type'] for gn in res) == {'creator', 'contributor', 'throughsubjects', 'subject', 'throughtags', 'tag', 'workidentifier', 'agentidentifier', 'person', 'preprint'}

        nodes = dict(enumerate(res))
        preprint = nodes.pop(next(k for k, v in nodes.items() if v['@type'] == 'preprint'))
        assert preprint['title'] == self.preprint.node.title
        assert preprint['description'] == self.preprint.node.description
        assert preprint['is_deleted'] == (not self.preprint.is_published or not self.preprint.node.is_public or self.preprint.node.is_preprint_orphan)
        assert preprint['date_updated'] == self.preprint.date_modified.isoformat()
        assert preprint['date_published'] == self.preprint.date_published.isoformat()

        tags = [nodes.pop(k) for k, v in nodes.items() if v['@type'] == 'tag']
        through_tags = [nodes.pop(k) for k, v in nodes.items() if v['@type'] == 'throughtags']
        assert sorted(tag['@id'] for tag in tags) == sorted(tt['tag']['@id'] for tt in through_tags)
        assert sorted(tag['name'] for tag in tags) == ['preprint', 'spoderman']

        subjects = [nodes.pop(k) for k, v in nodes.items() if v['@type'] == 'subject']
        through_subjects = [nodes.pop(k) for k, v in nodes.items() if v['@type'] == 'throughsubjects']
        assert sorted(subject['@id'] for subject in subjects) == sorted(tt['subject']['@id'] for tt in through_subjects)
        assert sorted(subject['name'] for subject in subjects) == ['Example Subject #1']

        people = sorted([nodes.pop(k) for k, v in nodes.items() if v['@type'] == 'person'], key=lambda x: x['given_name'])
        assert people == [{
            '@id': people[0]['@id'],
            '@type': 'person',
            'given_name': u'BoJack',
            'family_name': u'Horseman',
        }, {
            '@id': people[1]['@id'],
            '@type': 'person',
            'given_name': self.user.given_name,
            'family_name': self.user.family_name,
        }, {
            '@id': people[2]['@id'],
            '@type': 'person',
            'given_name': self.preprint.node.creator.given_name,
            'family_name': self.preprint.node.creator.family_name,
        }]

        creators = sorted([nodes.pop(k) for k, v in nodes.items() if v['@type'] == 'creator'], key=lambda x: x['order_cited'])
        assert creators == [{
            '@id': creators[0]['@id'],
            '@type': 'creator',
            'order_cited': 0,
            'cited_as': self.preprint.node.creator.fullname,
            'agent': {'@id': people[2]['@id'], '@type': 'person'},
            'creative_work': {'@id': preprint['@id'], '@type': preprint['@type']},
        }, {
            '@id': creators[1]['@id'],
            '@type': 'creator',
            'order_cited': 1,
            'cited_as': 'BoJack Horseman',
            'agent': {'@id': people[0]['@id'], '@type': 'person'},
            'creative_work': {'@id': preprint['@id'], '@type': preprint['@type']},
        }]

        contributors = [nodes.pop(k) for k, v in nodes.items() if v['@type'] == 'contributor']
        assert contributors == [{
            '@id': contributors[0]['@id'],
            '@type': 'contributor',
            'cited_as': self.user.fullname,
            'agent': {'@id': people[1]['@id'], '@type': 'person'},
            'creative_work': {'@id': preprint['@id'], '@type': preprint['@type']},
        }]

        agentidentifiers = {nodes.pop(k)['uri'] for k, v in nodes.items() if v['@type'] == 'agentidentifier'}
        assert agentidentifiers == set([
            'mailto:' + self.user.username,
            'mailto:' + self.preprint.node.creator.username,
            self.user.profile_image_url(),
            self.preprint.node.creator.profile_image_url(),
        ]) | set(urlparse.urljoin(settings.DOMAIN, user.profile_url) for user in self.preprint.node.contributors if user.is_registered)

        workidentifiers = {nodes.pop(k)['uri'] for k, v in nodes.items() if v['@type'] == 'workidentifier'}
        assert workidentifiers == set([
            'http://dx.doi.org/{}'.format(self.preprint.article_doi),
            urlparse.urljoin(settings.DOMAIN, self.preprint.url)
        ])

        assert nodes == {}
예제 #13
0
    def test_format_preprint(self):
        res = format_preprint(self.preprint)

        assert set(gn['@type'] for gn in res) == {'creator', 'contributor', 'throughsubjects', 'subject', 'throughtags', 'tag', 'workidentifier', 'agentidentifier', 'person', 'preprint', 'workrelation', 'creativework'}

        nodes = dict(enumerate(res))
        preprint = nodes.pop(next(k for k, v in nodes.items() if v['@type'] == 'preprint'))
        assert preprint['title'] == self.preprint.node.title
        assert preprint['description'] == self.preprint.node.description
        assert preprint['is_deleted'] == (not self.preprint.is_published or not self.preprint.node.is_public or self.preprint.node.is_preprint_orphan)
        assert preprint['date_updated'] == self.preprint.date_modified.isoformat()
        assert preprint['date_published'] == self.preprint.date_published.isoformat()

        tags = [nodes.pop(k) for k, v in nodes.items() if v['@type'] == 'tag']
        through_tags = [nodes.pop(k) for k, v in nodes.items() if v['@type'] == 'throughtags']
        assert sorted(tag['@id'] for tag in tags) == sorted(tt['tag']['@id'] for tt in through_tags)
        assert sorted(tag['name'] for tag in tags) == ['preprint', 'spoderman']

        subjects = [nodes.pop(k) for k, v in nodes.items() if v['@type'] == 'subject']
        through_subjects = [nodes.pop(k) for k, v in nodes.items() if v['@type'] == 'throughsubjects']
        assert sorted(subject['@id'] for subject in subjects) == sorted(tt['subject']['@id'] for tt in through_subjects)
        assert sorted(subject['name'] for subject in subjects) == [Subject.load(s).text for h in self.preprint.subjects for s in h]

        people = sorted([nodes.pop(k) for k, v in nodes.items() if v['@type'] == 'person'], key=lambda x: x['given_name'])
        expected_people = sorted([{
            '@type': 'person',
            'given_name': u'BoJack',
            'family_name': u'Horseman',
        }, {
            '@type': 'person',
            'given_name': self.user.given_name,
            'family_name': self.user.family_name,
        }, {
            '@type': 'person',
            'given_name': self.preprint.node.creator.given_name,
            'family_name': self.preprint.node.creator.family_name,
        }], key=lambda x: x['given_name'])
        for i, p in enumerate(expected_people):
            expected_people[i]['@id'] = people[i]['@id']

        assert people == expected_people

        creators = sorted([nodes.pop(k) for k, v in nodes.items() if v['@type'] == 'creator'], key=lambda x: x['order_cited'])
        assert creators == [{
            '@id': creators[0]['@id'],
            '@type': 'creator',
            'order_cited': 0,
            'cited_as': u'{}'.format(self.preprint.node.creator.fullname),
            'agent': {'@id': [p['@id'] for p in people if p['given_name'] == self.preprint.node.creator.given_name][0], '@type': 'person'},
            'creative_work': {'@id': preprint['@id'], '@type': preprint['@type']},
        }, {
            '@id': creators[1]['@id'],
            '@type': 'creator',
            'order_cited': 1,
            'cited_as': u'BoJack Horseman',
            'agent': {'@id': [p['@id'] for p in people if p['given_name'] == u'BoJack'][0], '@type': 'person'},
            'creative_work': {'@id': preprint['@id'], '@type': preprint['@type']},
        }]

        contributors = [nodes.pop(k) for k, v in nodes.items() if v['@type'] == 'contributor']
        assert contributors == [{
            '@id': contributors[0]['@id'],
            '@type': 'contributor',
            'cited_as': u'{}'.format(self.user.fullname),
            'agent': {'@id': [p['@id'] for p in people if p['given_name'] == self.user.given_name][0], '@type': 'person'},
            'creative_work': {'@id': preprint['@id'], '@type': preprint['@type']},
        }]

        agentidentifiers = {nodes.pop(k)['uri'] for k, v in nodes.items() if v['@type'] == 'agentidentifier'}
        assert agentidentifiers == set([
            'mailto:' + self.user.username,
            'mailto:' + self.preprint.node.creator.username,
            self.user.profile_image_url(),
            self.preprint.node.creator.profile_image_url(),
        ]) | set(urlparse.urljoin(settings.DOMAIN, user.profile_url) for user in self.preprint.node.contributors if user.is_registered)

        related_work = next(nodes.pop(k) for k, v in nodes.items() if v['@type'] == 'creativework')
        assert set(related_work.keys()) == {'@id', '@type'}  # Empty except @id and @type

        doi = next(nodes.pop(k) for k, v in nodes.items() if v['@type'] == 'workidentifier' and 'doi' in v['uri'])
        assert doi['creative_work'] == related_work

        workidentifiers = [nodes.pop(k)['uri'] for k, v in nodes.items() if v['@type'] == 'workidentifier']
        assert workidentifiers == [urlparse.urljoin(settings.DOMAIN, self.preprint.url)]

        relation = nodes.pop(nodes.keys()[0])
        assert relation == {'@id': relation['@id'], '@type': 'workrelation', 'related': {'@id': related_work['@id'], '@type': related_work['@type']}, 'subject': {'@id': preprint['@id'], '@type': preprint['@type']}}

        assert nodes == {}
예제 #14
0
 def test_format_preprint_date_modified_node_updated(self):
     self.preprint.node.save()
     res = format_preprint(self.preprint, self.preprint.provider.share_publish_type)
     nodes = dict(enumerate(res))
     preprint = nodes.pop(next(k for k, v in nodes.items() if v['@type'] == 'preprint'))
     assert preprint['date_updated'] == self.preprint.node.modified.isoformat()
예제 #15
0
    def test_format_preprint(self):
        res = format_preprint(self.preprint, self.preprint.provider.share_publish_type)

        assert set(gn['@type'] for gn in res) == {'creator', 'contributor', 'throughsubjects', 'subject', 'throughtags', 'tag', 'workidentifier', 'agentidentifier', 'person', 'preprint', 'workrelation', 'creativework'}

        nodes = dict(enumerate(res))
        preprint = nodes.pop(next(k for k, v in nodes.items() if v['@type'] == 'preprint'))
        assert preprint['title'] == self.preprint.node.title
        assert preprint['description'] == self.preprint.node.description
        assert preprint['is_deleted'] == (not self.preprint.is_published or not self.preprint.node.is_public or self.preprint.node.is_preprint_orphan)
        assert preprint['date_updated'] == self.preprint.modified.isoformat()
        assert preprint['date_published'] == self.preprint.date_published.isoformat()

        tags = [nodes.pop(k) for k, v in nodes.items() if v['@type'] == 'tag']
        through_tags = [nodes.pop(k) for k, v in nodes.items() if v['@type'] == 'throughtags']
        assert sorted(tag['@id'] for tag in tags) == sorted(tt['tag']['@id'] for tt in through_tags)
        assert sorted(tag['name'] for tag in tags) == ['preprint', 'spoderman']

        subjects = [nodes.pop(k) for k, v in nodes.items() if v['@type'] == 'subject']
        through_subjects = [nodes.pop(k) for k, v in nodes.items() if v['@type'] == 'throughsubjects']
        s_ids = [s['@id'] for s in subjects]
        ts_ids = [ts['subject']['@id'] for ts in through_subjects]
        cs_ids = [i for i in set(s.get('central_synonym', {}).get('@id') for s in subjects) if i]
        for ts in ts_ids:
            assert ts in s_ids
            assert ts not in cs_ids  # Only aliased subjects are connected to self.preprint
        for s in subjects:
            subject = Subject.objects.get(text=s['name'])
            assert s['uri'].endswith('v2/taxonomies/{}/'.format(subject._id))  # This cannot change
        assert set(subject['name'] for subject in subjects) == set([s.text for s in self.preprint.subjects.all()] + [s.bepress_subject.text for s in self.preprint.subjects.filter(bepress_subject__isnull=False)])

        people = sorted([nodes.pop(k) for k, v in nodes.items() if v['@type'] == 'person'], key=lambda x: x['given_name'])
        expected_people = sorted([{
            '@type': 'person',
            'given_name': u'BoJack',
            'family_name': u'Horseman',
        }, {
            '@type': 'person',
            'given_name': self.user.given_name,
            'family_name': self.user.family_name,
        }, {
            '@type': 'person',
            'given_name': self.preprint.node.creator.given_name,
            'family_name': self.preprint.node.creator.family_name,
        }], key=lambda x: x['given_name'])
        for i, p in enumerate(expected_people):
            expected_people[i]['@id'] = people[i]['@id']

        assert people == expected_people

        creators = sorted([nodes.pop(k) for k, v in nodes.items() if v['@type'] == 'creator'], key=lambda x: x['order_cited'])
        assert creators == [{
            '@id': creators[0]['@id'],
            '@type': 'creator',
            'order_cited': 0,
            'cited_as': u'{}'.format(self.preprint.node.creator.fullname),
            'agent': {'@id': [p['@id'] for p in people if p['given_name'] == self.preprint.node.creator.given_name][0], '@type': 'person'},
            'creative_work': {'@id': preprint['@id'], '@type': preprint['@type']},
        }, {
            '@id': creators[1]['@id'],
            '@type': 'creator',
            'order_cited': 1,
            'cited_as': u'BoJack Horseman',
            'agent': {'@id': [p['@id'] for p in people if p['given_name'] == u'BoJack'][0], '@type': 'person'},
            'creative_work': {'@id': preprint['@id'], '@type': preprint['@type']},
        }]

        contributors = [nodes.pop(k) for k, v in nodes.items() if v['@type'] == 'contributor']
        assert contributors == [{
            '@id': contributors[0]['@id'],
            '@type': 'contributor',
            'cited_as': u'{}'.format(self.user.fullname),
            'agent': {'@id': [p['@id'] for p in people if p['given_name'] == self.user.given_name][0], '@type': 'person'},
            'creative_work': {'@id': preprint['@id'], '@type': preprint['@type']},
        }]

        agentidentifiers = {nodes.pop(k)['uri'] for k, v in nodes.items() if v['@type'] == 'agentidentifier'}
        assert agentidentifiers == set([
            'mailto:' + self.user.username,
            'mailto:' + self.preprint.node.creator.username,
            self.user.profile_image_url(),
            self.preprint.node.creator.profile_image_url(),
        ]) | set(user.absolute_url for user in self.preprint.node.contributors)

        related_work = next(nodes.pop(k) for k, v in nodes.items() if v['@type'] == 'creativework')
        assert set(related_work.keys()) == {'@id', '@type'}  # Empty except @id and @type

        osf_doi = next(nodes.pop(k) for k, v in nodes.items() if v['@type'] == 'workidentifier' and 'doi' in v['uri'] and 'osf.io' in v['uri'])
        assert osf_doi['creative_work'] == {'@id': preprint['@id'], '@type': preprint['@type']}

        related_doi = next(nodes.pop(k) for k, v in nodes.items() if v['@type'] == 'workidentifier' and 'doi' in v['uri'])
        assert related_doi['creative_work'] == related_work

        workidentifiers = [nodes.pop(k)['uri'] for k, v in nodes.items() if v['@type'] == 'workidentifier']
        assert workidentifiers == [urlparse.urljoin(settings.DOMAIN, self.preprint._id + '/')]

        relation = nodes.pop(nodes.keys()[0])
        assert relation == {'@id': relation['@id'], '@type': 'workrelation', 'related': {'@id': related_work['@id'], '@type': related_work['@type']}, 'subject': {'@id': preprint['@id'], '@type': preprint['@type']}}

        assert nodes == {}
예제 #16
0
    def test_format_preprint(self):
        res = format_preprint(self.preprint)

        assert set(gn['@type'] for gn in res) == {'creator', 'contributor', 'throughsubjects', 'subject', 'throughtags', 'tag', 'workidentifier', 'agentidentifier', 'person', 'preprint', 'workrelation', 'creativework'}

        nodes = dict(enumerate(res))
        preprint = nodes.pop(next(k for k, v in nodes.items() if v['@type'] == 'preprint'))
        assert preprint['title'] == self.preprint.node.title
        assert preprint['description'] == self.preprint.node.description
        assert preprint['is_deleted'] == (not self.preprint.is_published or not self.preprint.node.is_public or self.preprint.node.is_preprint_orphan)
        assert preprint['date_updated'] == self.preprint.date_modified.isoformat()
        assert preprint['date_published'] == self.preprint.date_published.isoformat()

        tags = [nodes.pop(k) for k, v in nodes.items() if v['@type'] == 'tag']
        through_tags = [nodes.pop(k) for k, v in nodes.items() if v['@type'] == 'throughtags']
        assert sorted(tag['@id'] for tag in tags) == sorted(tt['tag']['@id'] for tt in through_tags)
        assert sorted(tag['name'] for tag in tags) == ['preprint', 'spoderman']

        subjects = [nodes.pop(k) for k, v in nodes.items() if v['@type'] == 'subject']
        through_subjects = [nodes.pop(k) for k, v in nodes.items() if v['@type'] == 'throughsubjects']
        assert sorted(subject['@id'] for subject in subjects) == sorted(tt['subject']['@id'] for tt in through_subjects)
        assert sorted(subject['name'] for subject in subjects) == [s.bepress_text for h in self.preprint.subject_hierarchy for s in h]

        people = sorted([nodes.pop(k) for k, v in nodes.items() if v['@type'] == 'person'], key=lambda x: x['given_name'])
        expected_people = sorted([{
            '@type': 'person',
            'given_name': u'BoJack',
            'family_name': u'Horseman',
        }, {
            '@type': 'person',
            'given_name': self.user.given_name,
            'family_name': self.user.family_name,
        }, {
            '@type': 'person',
            'given_name': self.preprint.node.creator.given_name,
            'family_name': self.preprint.node.creator.family_name,
        }], key=lambda x: x['given_name'])
        for i, p in enumerate(expected_people):
            expected_people[i]['@id'] = people[i]['@id']

        assert people == expected_people

        creators = sorted([nodes.pop(k) for k, v in nodes.items() if v['@type'] == 'creator'], key=lambda x: x['order_cited'])
        assert creators == [{
            '@id': creators[0]['@id'],
            '@type': 'creator',
            'order_cited': 0,
            'cited_as': u'{}'.format(self.preprint.node.creator.fullname),
            'agent': {'@id': [p['@id'] for p in people if p['given_name'] == self.preprint.node.creator.given_name][0], '@type': 'person'},
            'creative_work': {'@id': preprint['@id'], '@type': preprint['@type']},
        }, {
            '@id': creators[1]['@id'],
            '@type': 'creator',
            'order_cited': 1,
            'cited_as': u'BoJack Horseman',
            'agent': {'@id': [p['@id'] for p in people if p['given_name'] == u'BoJack'][0], '@type': 'person'},
            'creative_work': {'@id': preprint['@id'], '@type': preprint['@type']},
        }]

        contributors = [nodes.pop(k) for k, v in nodes.items() if v['@type'] == 'contributor']
        assert contributors == [{
            '@id': contributors[0]['@id'],
            '@type': 'contributor',
            'cited_as': u'{}'.format(self.user.fullname),
            'agent': {'@id': [p['@id'] for p in people if p['given_name'] == self.user.given_name][0], '@type': 'person'},
            'creative_work': {'@id': preprint['@id'], '@type': preprint['@type']},
        }]

        agentidentifiers = {nodes.pop(k)['uri'] for k, v in nodes.items() if v['@type'] == 'agentidentifier'}
        assert agentidentifiers == set([
            'mailto:' + self.user.username,
            'mailto:' + self.preprint.node.creator.username,
            self.user.profile_image_url(),
            self.preprint.node.creator.profile_image_url(),
        ]) | set(urlparse.urljoin(settings.DOMAIN, user.profile_url) for user in self.preprint.node.contributors if user.is_registered)

        related_work = next(nodes.pop(k) for k, v in nodes.items() if v['@type'] == 'creativework')
        assert set(related_work.keys()) == {'@id', '@type'}  # Empty except @id and @type

        osf_doi = next(nodes.pop(k) for k, v in nodes.items() if v['@type'] == 'workidentifier' and 'doi' in v['uri'] and 'osf.io' in v['uri'])
        assert osf_doi['creative_work'] == {'@id': preprint['@id'], '@type': preprint['@type']}

        related_doi = next(nodes.pop(k) for k, v in nodes.items() if v['@type'] == 'workidentifier' and 'doi' in v['uri'])
        assert related_doi['creative_work'] == related_work

        workidentifiers = [nodes.pop(k)['uri'] for k, v in nodes.items() if v['@type'] == 'workidentifier']
        assert workidentifiers == [urlparse.urljoin(settings.DOMAIN, self.preprint._id + '/')]

        relation = nodes.pop(nodes.keys()[0])
        assert relation == {'@id': relation['@id'], '@type': 'workrelation', 'related': {'@id': related_work['@id'], '@type': related_work['@type']}, 'subject': {'@id': preprint['@id'], '@type': preprint['@type']}}

        assert nodes == {}
예제 #17
0
    def test_format_preprint_nones(self):
        self.preprint.node.tags = None
        self.preprint.date_published = None
        self.preprint.set_subjects([],
                                   auth=Auth(self.preprint.node.creator),
                                   save=False)

        res = format_preprint(self.preprint)

        assert set(gn['@type'] for gn in res) == {
            'creator', 'contributor', 'workidentifier', 'agentidentifier',
            'person', 'preprint'
        }

        nodes = dict(enumerate(res))
        preprint = nodes.pop(
            next(k for k, v in nodes.items() if v['@type'] == 'preprint'))
        assert preprint['title'] == self.preprint.node.title
        assert preprint['description'] == self.preprint.node.description
        assert preprint['is_deleted'] == (
            not self.preprint.is_published or not self.preprint.node.is_public
            or self.preprint.node.is_preprint_orphan)
        assert preprint[
            'date_updated'] == self.preprint.date_modified.isoformat()
        assert preprint.get('date_published') is None

        people = sorted(
            [nodes.pop(k) for k, v in nodes.items() if v['@type'] == 'person'],
            key=lambda x: x['given_name'])
        assert people == [{
            '@id': people[0]['@id'],
            '@type': 'person',
            'given_name': u'BoJack',
            'family_name': u'Horseman',
        }, {
            '@id': people[1]['@id'],
            '@type': 'person',
            'given_name': self.user.given_name,
            'family_name': self.user.family_name,
        }, {
            '@id':
            people[2]['@id'],
            '@type':
            'person',
            'given_name':
            self.preprint.node.creator.given_name,
            'family_name':
            self.preprint.node.creator.family_name,
        }]

        creators = sorted([
            nodes.pop(k) for k, v in nodes.items() if v['@type'] == 'creator'
        ],
                          key=lambda x: x['order_cited'])
        assert creators == [{
            '@id': creators[0]['@id'],
            '@type': 'creator',
            'order_cited': 0,
            'cited_as': self.preprint.node.creator.fullname,
            'agent': {
                '@id': people[2]['@id'],
                '@type': 'person'
            },
            'creative_work': {
                '@id': preprint['@id'],
                '@type': preprint['@type']
            },
        }, {
            '@id': creators[1]['@id'],
            '@type': 'creator',
            'order_cited': 1,
            'cited_as': 'BoJack Horseman',
            'agent': {
                '@id': people[0]['@id'],
                '@type': 'person'
            },
            'creative_work': {
                '@id': preprint['@id'],
                '@type': preprint['@type']
            },
        }]

        contributors = [
            nodes.pop(k) for k, v in nodes.items()
            if v['@type'] == 'contributor'
        ]
        assert contributors == [{
            '@id': contributors[0]['@id'],
            '@type': 'contributor',
            'cited_as': self.user.fullname,
            'agent': {
                '@id': people[1]['@id'],
                '@type': 'person'
            },
            'creative_work': {
                '@id': preprint['@id'],
                '@type': preprint['@type']
            },
        }]

        agentidentifiers = {
            nodes.pop(k)['uri']
            for k, v in nodes.items() if v['@type'] == 'agentidentifier'
        }
        assert agentidentifiers == set([
            'mailto:' + self.user.username,
            'mailto:' + self.preprint.node.creator.username,
            self.user.profile_image_url(),
            self.preprint.node.creator.profile_image_url(),
        ]) | set(
            urlparse.urljoin(settings.DOMAIN, user.profile_url)
            for user in self.preprint.node.contributors if user.is_registered)

        workidentifiers = {
            nodes.pop(k)['uri']
            for k, v in nodes.items() if v['@type'] == 'workidentifier'
        }
        assert workidentifiers == set([
            'http://dx.doi.org/{}'.format(self.preprint.article_doi),
            urlparse.urljoin(settings.DOMAIN, self.preprint.url)
        ])

        assert nodes == {}