Ejemplo n.º 1
0
 def test_node_not_allowed_from_registrations_endpoint(self):
     self.node = NodeFactory(creator=self.user, is_public=True)
     self.node_identifier = IdentifierFactory(referent=self.node)
     url = '/{}registrations/{}/identifiers/'.format(
         API_BASE, self.node._id)
     res = self.app.get(url, expect_errors=True)
     assert_equal(res.status_code, 404)
Ejemplo n.º 2
0
    def setUp(self):
        super(TestIdentifierDetail, self).setUp()
        self.user = AuthUserFactory()

        self.registration = RegistrationFactory(creator=self.user, is_public=True)
        self.registration_identifier = IdentifierFactory(referent=self.registration)
        self.registration_url = '/{}identifiers/{}/'.format(API_BASE, self.registration_identifier._id)

        self.node = NodeFactory(creator=self.user, is_public=True)
        self.node_identifier = IdentifierFactory(referent=self.node)
        self.node_url = '/{}identifiers/{}/'.format(API_BASE, self.node_identifier._id)

        self.registration_res = self.app.get(self.registration_url)
        self.registration_data = self.registration_res.json['data']

        self.node_res = self.app.get(self.node_url)
        self.node_data = self.node_res.json['data']
Ejemplo n.º 3
0
 def test_node_identifier_not_returned_from_registration_endpoint(self):
     self.node = NodeFactory(creator=self.user, is_public=True)
     self.node_identifier = IdentifierFactory(referent=self.node)
     res = self.app.get(self.url)
     assert_equal(res.status_code, 200)
     data = res.json['data']
     assert_equal(len(data), 1)
     assert_equal(self.identifier._id, data[0]['id'])
     assert_not_equal(self.node_identifier._id, data[0]['id'])
Ejemplo n.º 4
0
    def setUp(self):
        super(TestNodeIdentifierList, self).setUp()
        self.user = AuthUserFactory()
        self.user_two = AuthUserFactory()

        self.node = NodeFactory(creator=self.user, is_public=True)
        self.identifier = IdentifierFactory(referent=self.node)
        self.url = '/{}nodes/{}/identifiers/'.format(API_BASE, self.node._id)

        self.res = self.app.get(self.url)
        self.data = self.res.json['data']

        self.all_identifiers = Identifier.find()
Ejemplo n.º 5
0
    def test_identifier_filter_by_category(self):
        IdentifierFactory(referent=self.node, category='nopeid')
        identifiers_for_node = Identifier.find(Q('referent', 'eq', self.node))
        assert_equal(len(identifiers_for_node), 2)
        assert_items_equal(
            [identifier.category for identifier in identifiers_for_node],
            ['carpid', 'nopeid'])

        filter_url = self.url + '?filter[category]=carpid'
        new_res = self.app.get(filter_url)

        carpid_total = len(Identifier.find(Q('category', 'eq', 'carpid')))

        total = new_res.json['links']['meta']['total']
        assert_equal(total, carpid_total)
Ejemplo n.º 6
0
    def test_identifier_filter_by_category(self, app, registration, identifier_registration, url_registration_identifiers):
        IdentifierFactory(referent=registration, category='nopeid')
        identifiers_for_registration = registration.identifiers
        assert identifiers_for_registration.count() == 2
        assert_items_equal(
            list(identifiers_for_registration.values_list('category', flat=True)),
            ['carpid', 'nopeid']
        )

        filter_url = '{}?filter[category]=carpid'.format(url_registration_identifiers)
        new_res = app.get(filter_url)

        carpid_total = Identifier.objects.filter(category='carpid').count()

        total = new_res.json['links']['meta']['total']
        assert total == carpid_total
Ejemplo n.º 7
0
    def test_identifier_filter_by_category(self, app, node, identifier_node,
                                           url_node_identifiers):
        IdentifierFactory(referent=node, category='nopeid')
        identifiers_for_node = Identifier.objects.filter(object_id=node.id)

        assert identifiers_for_node.count() == 2
        assert_items_equal(
            [identifier.category for identifier in identifiers_for_node],
            ['carpid', 'nopeid'])

        filter_url = '{}?filter[category]=carpid'.format(url_node_identifiers)
        new_res = app.get(filter_url)

        carpid_total = Identifier.objects.filter(category='carpid').count()

        total = new_res.json['links']['meta']['total']
        assert total == carpid_total
Ejemplo n.º 8
0
    def test_identifier_filter_by_category(self):
        IdentifierFactory(referent=self.registration, category='nopeid')
        identifiers_for_registration = self.registration.identifiers
        assert_equal(identifiers_for_registration.count(), 2)
        assert_items_equal(
            list(
                identifiers_for_registration.values_list('category',
                                                         flat=True)),
            ['carpid', 'nopeid'])

        filter_url = self.url + '?filter[category]=carpid'
        new_res = self.app.get(filter_url)

        carpid_total = len(Identifier.find(Q('category', 'eq', 'carpid')))

        total = new_res.json['links']['meta']['total']
        assert_equal(total, carpid_total)
Ejemplo n.º 9
0
 def test_mixin_set_update(self):
     identifier = IdentifierFactory(category='dogid', value='dog:1')
     node = identifier.referent
     assert_equal(node.get_identifier_value('dogid'), 'dog:1')
     node.set_identifier_value('dogid', 'dog:2')
     assert_equal(node.get_identifier_value('dogid'), 'dog:2')
Ejemplo n.º 10
0
 def test_mixin_get_value(self):
     identifier = IdentifierFactory()
     node = identifier.referent
     assert_equal(node.get_identifier_value(identifier.category),
                  identifier.value)
Ejemplo n.º 11
0
 def test_unique_constraint(self):
     node = RegistrationFactory()
     IdentifierFactory(referent=node)
     with assert_raises(IntegrityError):
         IdentifierFactory(referent=node)
Ejemplo n.º 12
0
 def identifier_preprint(self, user, preprint):
     return IdentifierFactory(referent=preprint)
Ejemplo n.º 13
0
 def identifier_node(self, node):
     return IdentifierFactory(referent=node)
Ejemplo n.º 14
0
 def identifier_registration(self, registration):
     return IdentifierFactory(referent=registration)
Ejemplo n.º 15
0
 def registration(self, node):
     reg = RegistrationFactory(is_public=True)
     IdentifierFactory(referent=reg, category='doi')
     reg.archive_jobs.clear(
     )  # if reg.archiving is True it will skip updating SHARE
     return reg
Ejemplo n.º 16
0
 def test_get_identifier_for_doi_returns_legacy_doi(self):
     identifier = IdentifierFactory(category='legacy_doi', value='hello')
     preprint = identifier.referent
     assert preprint.get_identifier_value('doi') == 'hello'