Esempio n. 1
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)
Esempio n. 2
0
 def get_object(self):
     identifier = Identifier.load(self.kwargs['identifier_id'])
     if not identifier or getattr(
             identifier.referent, 'deleted', False) or getattr(
                 identifier.referent, 'is_deleted', False):
         raise NotFound
     self.check_object_permissions(self.request, identifier)
     return identifier
Esempio n. 3
0
 def setUp(self):
     OsfTestCase.setUp(self)
     self.visible_contrib = AuthUserFactory()
     visible_contrib2 = AuthUserFactory(given_name=u'ヽ༼ ಠ益ಠ ༽ノ', family_name=u'ლ(´◉❥◉`ლ)')
     self.invisible_contrib = AuthUserFactory()
     self.node = RegistrationFactory(is_public=True)
     self.identifier = Identifier(referent=self.node, category='catid', value='cat:7')
     self.node.add_contributor(self.visible_contrib, visible=True)
     self.node.add_contributor(self.invisible_contrib, visible=False)
     self.node.add_contributor(visible_contrib2, visible=True)
     self.node.save()
Esempio n. 4
0
def get_referent_by_identifier(category, value):
    """Look up identifier by `category` and `value` and redirect to its referent
    if found.
    """
    try:
        identifier = Identifier.find_one(
            Q('category', 'eq', category) & Q('value', 'eq', value))
    except NoResultsFound:
        raise HTTPError(http.NOT_FOUND)
    if identifier.referent.url:
        return redirect(identifier.referent.url)
    raise HTTPError(http.NOT_FOUND)
Esempio n. 5
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()
Esempio n. 6
0
def get_referent_by_identifier(category, value):
    """Look up identifier by `category` and `value` and redirect to its referent
    if found.
    """
    try:
        identifier = Identifier.find_one(
            Q('category', 'eq', category) &
            Q('value', 'eq', value)
        )
    except NoResultsFound:
        raise HTTPError(http.NOT_FOUND)
    if identifier.referent.url:
        return redirect(identifier.referent.url)
    raise HTTPError(http.NOT_FOUND)
Esempio n. 7
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)
Esempio n. 8
0
 def test_fields(self):
     node = RegistrationFactory()
     identifier = Identifier(referent=node, category='catid', value='cat:7')
     assert_equal(identifier.referent, node)
     assert_equal(identifier.category, 'catid')
     assert_equal(identifier.value, 'cat:7')
Esempio n. 9
0
 def get_object(self):
     identifier = Identifier.load(self.kwargs['identifier_id'])
     if not identifier or getattr(identifier.referent, 'deleted', False) or getattr(identifier.referent, 'is_deleted', False):
         raise NotFound
     self.check_object_permissions(self.request, identifier)
     return identifier
Esempio n. 10
0
 def get_queryset(self):
     return Identifier.find(self.get_query_from_request())
Esempio n. 11
0
 def get_queryset(self):
     return Identifier.find(self.get_query_from_request())
Esempio n. 12
0
 def get_object(self):
     return Identifier.load(self.kwargs['identifier_id'])
Esempio n. 13
0
 def tearDown(self):
     super(TestNodeIdentifierList, self).tearDown()
     Identifier.remove()
Esempio n. 14
0
 def get_object(self):
     return Identifier.load(self.kwargs['identifier_id'])