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)
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
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()
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)
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()
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)
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)
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')
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
def get_queryset(self): return Identifier.find(self.get_query_from_request())
def get_object(self): return Identifier.load(self.kwargs['identifier_id'])
def tearDown(self): super(TestNodeIdentifierList, self).tearDown() Identifier.remove()