本文整理汇总了Python中skosprovider.registry.Registry类的典型用法代码示例。如果您正苦于以下问题:Python Registry类的具体用法?Python Registry怎么用?Python Registry使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Registry类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestConceptSchemeView
class TestConceptSchemeView(unittest.TestCase):
def setUp(self):
self.config = testing.setUp()
self.regis = Registry()
self.regis.register_provider(trees)
self.request = testing.DummyRequest()
self.request.db = db(self.request)
self.request.skos_registry = self.regis
def tearDown(self):
testing.tearDown()
def test_conceptschemes_view(self):
atramhasisview = AtramhasisView(self.request)
res = atramhasisview.conceptschemes_view()
self.assertEqual({'conceptschemes': [{'id': u'TREES', 'uri': 'urn:test:test'}]}, res)
def test_conceptscheme_view(self):
self.request.matchdict['scheme_id'] = 'TREES'
atramhasisview = AtramhasisView(self.request)
res = atramhasisview.conceptscheme_view()
self.assertIsNotNone(res)
self.assertIsNotNone(res['conceptscheme'])
self.assertEqual(res['conceptscheme']['title'], 'TREES')
self.assertEqual(res['conceptscheme']['scheme_id'], 'TREES')
self.assertEqual(res['conceptscheme']['uri'], 'urn:x-skosprovider:trees')
self.assertIsNotNone(res['conceptscheme']['labels'])
self.assertIsNotNone(res['conceptscheme']['notes'])
self.assertIsNotNone(res['conceptscheme']['top_concepts'])
示例2: TestConceptSchemeView
class TestConceptSchemeView(unittest.TestCase):
def setUp(self):
self.config = testing.setUp()
self.regis = Registry()
self.regis.register_provider(trees)
self.request = testing.DummyRequest()
self.request.accept = ['text/html']
self.request.data_managers = data_managers(self.request)
self.request.skos_registry = self.regis
def tearDown(self):
testing.tearDown()
def test_conceptschemes_view(self):
atramhasisview = AtramhasisView(self.request)
res = atramhasisview.conceptschemes_view()
self.assertIn('conceptschemes', res)
self.assertEqual(len(res['conceptschemes']), 1)
cs = res['conceptschemes'][0]
self.assertIn('id', cs)
self.assertIn('conceptscheme', cs)
def test_conceptscheme_view(self):
self.request.matchdict['scheme_id'] = 'TREES'
atramhasisview = AtramhasisView(self.request)
res = atramhasisview.conceptscheme_view()
self.assertIsNotNone(res)
self.assertIsNotNone(res['conceptscheme'])
self.assertEqual(res['conceptscheme']['title'], 'TREES')
self.assertEqual(res['conceptscheme']['scheme_id'], 'TREES')
self.assertEqual(res['conceptscheme']['uri'], 'urn:x-skosprovider:trees')
self.assertIsNotNone(res['conceptscheme']['labels'])
self.assertIsNotNone(res['conceptscheme']['notes'])
self.assertIsNotNone(res['conceptscheme']['top_concepts'])
示例3: TestAdminView
class TestAdminView(unittest.TestCase):
def setUp(self):
self.config = testing.setUp()
self.regis = Registry()
self.regis.register_provider(trees)
def tearDown(self):
testing.tearDown()
def test_no_registry(self):
error_raised = False
request = testing.DummyRequest()
try:
AtramhasisAdminView(request)
except SkosRegistryNotFoundException as e:
error_raised = True
self.assertIsNotNone(e.__str__())
self.assertTrue(error_raised)
def test_passing_view(self):
request = testing.DummyRequest()
request.skos_registry = self.regis
atramhasisAdminview = AtramhasisAdminView(request)
info = atramhasisAdminview.admin_view()
self.assertIsNotNone(info)
self.assertTrue('admin' in info)
def test_invalidate_scheme_tree(self):
request = testing.DummyRequest()
request.matchdict['scheme_id'] = 'TREES'
request.skos_registry = self.regis
atramhasisAdminview = AtramhasisAdminView(request)
info = atramhasisAdminview.invalidate_scheme_tree()
self.assertIsNotNone(info)
示例4: TestLocaleView
class TestLocaleView(unittest.TestCase):
def setUp(self):
self.config = testing.setUp()
self.regis = Registry()
self.regis.register_provider(trees)
config = testing.setUp()
config.add_route('home', 'foo')
config.add_settings(settings)
self.request = testing.DummyRequest()
self.request.data_managers = {'skos_manager': None, 'conceptscheme_manager': None, 'audit_manager': None}
def tearDown(self):
testing.tearDown()
def test_default_locale(self):
config_default_lang = settings.get('pyramid.default_locale_name')
self.request.referer = None
self.request.skos_registry = self.regis
atramhasisview = AtramhasisView(self.request)
res = atramhasisview.set_locale_cookie()
self.assertTrue((res.headers.get('Set-Cookie')).startswith('_LOCALE_=' + config_default_lang))
def test_unsupported_lang(self):
config_default_lang = settings.get('pyramid.default_locale_name')
self.request.GET['language'] = 'XX'
self.request.referer = None
self.request.skos_registry = self.regis
atramhasisview = AtramhasisView(self.request)
res = atramhasisview.set_locale_cookie()
self.assertTrue((res.headers.get('Set-Cookie')).startswith('_LOCALE_=' + config_default_lang))
def test_locale(self):
testlang = 'it'
self.request.GET['language'] = testlang
self.request.referer = None
self.request.skos_registry = self.regis
atramhasisview = AtramhasisView(self.request)
res = atramhasisview.set_locale_cookie()
self.assertTrue((res.headers.get('Set-Cookie')).startswith('_LOCALE_=' + testlang))
def test_locale_uppercase(self):
testlang = 'it'
self.request.GET['language'] = testlang.upper()
self.request.referer = None
self.request.skos_registry = self.regis
atramhasisview = AtramhasisView(self.request)
res = atramhasisview.set_locale_cookie()
self.assertTrue((res.headers.get('Set-Cookie')).startswith('_LOCALE_=' + testlang))
def test_referer(self):
testlang = 'it'
testurl = 'http://www.foo.bar'
self.request.GET['language'] = testlang.upper()
self.request.referer = testurl
self.request.skos_registry = self.regis
atramhasisview = AtramhasisView(self.request)
res = atramhasisview.set_locale_cookie()
self.assertEqual(res.status, '302 Found')
self.assertEqual(res.location, testurl)
示例5: TestSearchResultView
class TestSearchResultView(unittest.TestCase):
def setUp(self):
self.config = testing.setUp()
self.regis = Registry()
self.regis.register_provider(trees)
def tearDown(self):
testing.tearDown()
def test_find_by_label(self):
request = testing.DummyRequest()
request.matchdict['scheme_id'] = 'TREES'
request.params = MultiDict()
request.params.add('label', 'De Paardekastanje')
request.params.add('_LOCALE_', 'nl')
request.skos_registry = self.regis
atramhasisview = AtramhasisView(request)
info = atramhasisview.search_result()
self.assertIsNotNone(info['concepts'])
concept = info['concepts'][0]
self.assertIsNotNone(concept)
self.assertEqual(concept['label'], 'De Paardekastanje')
self.assertEqual(info['scheme_id'], 'TREES')
def test_find_by_concept(self):
request = testing.DummyRequest()
request.matchdict['scheme_id'] = 'TREES'
request.params = MultiDict()
request.params.add('ctype', 'concept')
request.params.add('_LOCALE_', 'nl')
request.skos_registry = self.regis
atramhasisview = AtramhasisView(request)
info = atramhasisview.search_result()
self.assertIsNotNone(info['concepts'])
concept = info['concepts'][0]
self.assertIsNotNone(concept)
self.assertEqual(info['scheme_id'], 'TREES')
def test_no_querystring(self):
request = testing.DummyRequest()
request.matchdict['scheme_id'] = 'TREES'
request.params = MultiDict()
request.skos_registry = self.regis
atramhasisview = AtramhasisView(request)
info = atramhasisview.search_result()
self.assertIsNotNone(info['concepts'])
self.assertEqual(len(info['concepts']), 3)
def test_no_schema(self):
request = testing.DummyRequest()
request.matchdict['scheme_id'] = 'GG'
request.params = MultiDict()
request.skos_registry = self.regis
atramhasisview = AtramhasisView(request)
info = atramhasisview.search_result()
self.assertEqual(info.status_int, 404)
示例6: TestAdminView
class TestAdminView(unittest.TestCase):
def setUp(self):
self.config = testing.setUp()
self.regis = Registry()
self.regis.register_provider(trees)
def tearDown(self):
testing.tearDown()
def test_no_registry(self):
error_raised = False
request = testing.DummyRequest()
try:
AtramhasisAdminView(request)
except SkosRegistryNotFoundException as e:
error_raised = True
self.assertIsNotNone(e.__str__())
self.assertTrue(error_raised)
def test_passing_view(self):
request = testing.DummyRequest()
request.skos_registry = self.regis
atramhasisAdminview = AtramhasisAdminView(request)
info = atramhasisAdminview.admin_view()
self.assertIsNotNone(info)
self.assertTrue('admin' in info)
def test_invalidate_scheme_tree(self):
tree_cache_dictionary['foo |TREES nl'] = []
tree_cache_dictionary['foo |TREES fr'] = []
tree_cache_dictionary['bar |MATERIALS fr'] = []
request = testing.DummyRequest()
request.matchdict['scheme_id'] = 'TREES'
request.skos_registry = self.regis
atramhasisAdminview = AtramhasisAdminView(request)
response = atramhasisAdminview.invalidate_scheme_tree()
self.assertEqual(response.status_int, 200)
self.assertIn('bar |MATERIALS fr', tree_cache_dictionary.keys())
self.assertNotIn('foo |TREES nl', tree_cache_dictionary.keys())
self.assertNotIn('foo |TREES fr', tree_cache_dictionary.keys())
def test_invalidate_tree(self):
tree_cache_dictionary['foo |TREES nl'] = []
tree_cache_dictionary['foo |TREES fr'] = []
tree_cache_dictionary['bar |MATERIALS fr'] = []
request = testing.DummyRequest()
request.skos_registry = self.regis
atramhasisAdminview = AtramhasisAdminView(request)
response = atramhasisAdminview.invalidate_tree()
self.assertEqual(response.status_int, 200)
self.assertEqual(len(tree_cache_dictionary), 0)
示例7: setUp
def setUp(self):
self.config = testing.setUp()
self.regis = Registry()
self.regis.register_provider(trees)
self.regis.register_provider(hidden_provider(2))
self.request = testing.DummyRequest()
self.request.data_managers = {'skos_manager': None, 'conceptscheme_manager': None, 'audit_manager': None}
示例8: setUp
def setUp(self):
self.config = testing.setUp()
self.request = testing.DummyRequest()
self.regis = Registry()
self.regis.register_provider(provider(1))
self.request.skos_registry = self.regis
self.request.db = db(self.request)
示例9: TestHomeView
class TestHomeView(unittest.TestCase):
def setUp(self):
self.config = testing.setUp()
self.regis = Registry()
self.regis.register_provider(trees)
def tearDown(self):
testing.tearDown()
def test_passing_view(self):
request = testing.DummyRequest()
request.skos_registry = self.regis
atramhasisview = AtramhasisView(request)
info = atramhasisview.home_view()
self.assertIsNotNone(info['conceptschemes'][0])
self.assertEqual(info['conceptschemes'][0]['id'], 'TREES')
示例10: TestFavicoView
class TestFavicoView(unittest.TestCase):
def setUp(self):
self.config = testing.setUp()
self.regis = Registry()
self.regis.register_provider(trees)
def tearDown(self):
testing.tearDown()
def test_passing_view(self):
request = testing.DummyRequest()
request.skos_registry = self.regis
atramhasisview = AtramhasisView(request)
response = atramhasisview.favicon_view()
self.assertEqual(response.status_int, 200)
self.assertIn('image/x-icon', response.headers['Content-Type'])
self.assertIsNotNone(response.body)
示例11: TestHtmlTreeView
class TestHtmlTreeView(unittest.TestCase):
def setUp(self):
self.config = testing.setUp()
self.regis = Registry()
self.regis.register_provider(trees)
def tearDown(self):
testing.tearDown()
def test_passing_view(self):
request = testing.DummyRequest()
request.skos_registry = self.regis
request.matchdict['scheme_id'] = 'TREES'
atramhasisview = AtramhasisView(request)
response = atramhasisview.results_tree_html()
self.assertEqual(response['conceptType'], None)
self.assertEqual(response['concept'], None)
self.assertEqual(response['scheme_id'], 'TREES')
示例12: TestCsvView
class TestCsvView(unittest.TestCase):
def setUp(self):
self.config = testing.setUp()
self.request = testing.DummyRequest()
self.request.accept = '*/*'
self.regis = Registry()
self.regis.register_provider(provider(1))
self.request.skos_registry = self.regis
self.request.data_managers = data_managers(self.request)
def tearDown(self):
testing.tearDown()
def test_csv(self):
self.request.matchdict['scheme_id'] = 'TREES'
self.request.params = MultiDict()
atramhasisview = AtramhasisView(self.request)
res = atramhasisview.results_csv()
self.assertEqual(res['filename'], 'atramhasis_export')
self.assertIsInstance(res['header'], list)
self.assertIsInstance(res['rows'], list)
self.assertEqual(2, len(res['rows']))
def test_csv_label(self):
self.request.matchdict['scheme_id'] = 'TREES'
self.request.params = MultiDict()
self.request.params.add('label', 'De Paardekastanje')
atramhasisview = AtramhasisView(self.request)
res = atramhasisview.results_csv()
self.assertEqual(res['filename'], 'atramhasis_export')
self.assertIsInstance(res['header'], list)
self.assertIsInstance(res['rows'], list)
self.assertEqual(2, len(res['rows']))
def test_csv_ctype(self):
self.request.matchdict['scheme_id'] = 'TREES'
self.request.params = MultiDict()
self.request.params.add('ctype', 'concept')
atramhasisview = AtramhasisView(self.request)
res = atramhasisview.results_csv()
self.assertEqual(res['filename'], 'atramhasis_export')
self.assertIsInstance(res['header'], list)
self.assertIsInstance(res['rows'], list)
self.assertEqual(2, len(res['rows']))
示例13: TestHomeView
class TestHomeView(unittest.TestCase):
def setUp(self):
self.config = testing.setUp()
self.regis = Registry()
self.regis.register_provider(trees)
self.regis.register_provider(hidden_provider(2))
self.request = testing.DummyRequest()
self.request.data_managers = {'skos_manager': None, 'conceptscheme_manager': None, 'audit_manager': None}
def tearDown(self):
testing.tearDown()
def test_passing_view(self):
self.request.skos_registry = self.regis
atramhasisview = AtramhasisView(self.request)
info = atramhasisview.home_view()
self.assertIsNotNone(info['conceptschemes'][0])
self.assertEqual(info['conceptschemes'][0]['id'], 'TREES')
self.assertEqual(1, len(info['conceptschemes']))
示例14: setUp
def setUp(self):
self.concept = Concept()
self.concept.type = 'concept'
self.concept.id = 11
self.concept.concept_id = 101
self.concept.uri = 'urn:x-atramhasis-demo:TREES:101'
self.concept.conceptscheme_id = 1
notes = []
note = Note(note='test note', notetype_id='example', language_id='en')
note2 = Note(note='note def', notetype_id='definition', language_id='en')
notes.append(note)
notes.append(note2)
self.concept.notes = notes
labels = []
label = Label(label='een label', labeltype_id='prefLabel', language_id='nl')
label2 = Label(label='other label', labeltype_id='altLabel', language_id='en')
label3 = Label(label='and some other label', labeltype_id='altLabel', language_id='en')
labels.append(label)
labels.append(label2)
labels.append(label3)
self.concept.labels = labels
sources = []
source = Source('Van Daele K. 2009')
sources.append(source)
self.concept.sources = sources
matches = []
match = Match()
match.matchtype = MatchType(name='closeMatch', description='test')
match.uri = 'urn:somethingelse:st1'
matches.append(match)
match2 = Match()
match2.matchtype = MatchType(name='closeMatch', description='test')
match2.uri = 'urn:somethingelse:st2'
matches.append(match2)
match3 = Match()
match3.matchtype = MatchType(name='exactMatch', description='test')
match3.uri = 'urn:something:thingy'
matches.append(match3)
self.concept.matches = matches
self.collection = Collection()
self.collection.type = 'collection'
self.collection.id = 12
self.collection.concept_id = 102
self.collection.uri = 'urn:x-atramhasis-demo:TREES:102'
self.collection.conceptscheme_id = 1
self.conceptscheme = ConceptScheme()
self.conceptscheme.id = 1
self.conceptscheme.labels = labels
self.conceptscheme.notes = notes
self.conceptscheme.sources = sources
self.conceptscheme.uri = None
self.regis = Registry()
self.regis.register_provider(trees)
self.request = testing.DummyRequest()
self.request.skos_registry = self.regis
self.request.matchdict = {'scheme_id': 'TREES'}
self.concept.member_of.add(self.collection)
self.collection.members.add(self.concept)
示例15: TestConceptView
class TestConceptView(unittest.TestCase):
def setUp(self):
self.config = testing.setUp()
self.config.add_route('concept', pattern='/conceptschemes/{scheme_id}/c/{c_id}', accept='text/html',
request_method="GET")
self.request = testing.DummyRequest()
self.request.accept = ['text/html']
self.regis = Registry()
self.regis.register_provider(provider(1))
self.request.data_managers = data_managers(self.request)
def tearDown(self):
testing.tearDown()
def test_passing_view(self):
request = self.request
request.matchdict['scheme_id'] = 'TREES'
request.matchdict['c_id'] = '1'
request.skos_registry = self.regis
atramhasisview = AtramhasisView(request)
info = atramhasisview.concept_view()
self.assertIsNotNone(info['concept'])
self.assertEqual(info['conceptType'], 'Concept')
self.assertEqual(info['scheme_id'], 'TREES')
def test_passing_collection_view(self):
request = self.request
request.matchdict['scheme_id'] = 'TREES'
request.matchdict['c_id'] = '3'
request.skos_registry = self.regis
atramhasisview = AtramhasisView(request)
info = atramhasisview.concept_view()
self.assertIsNotNone(info['concept'])
self.assertEqual(info['conceptType'], 'Collection')
self.assertEqual(info['scheme_id'], 'TREES')
def test_provider_not_found(self):
request = self.request
request.matchdict['scheme_id'] = 'ZZ'
request.matchdict['c_id'] = '1'
request.skos_registry = self.regis
error_raised = False
try:
atramhasisview = AtramhasisView(request)
atramhasisview.concept_view()
except ConceptSchemeNotFoundException as e:
error_raised = True
self.assertIsNotNone(e.__str__())
self.assertTrue(error_raised)
def test_not_found(self):
request = self.request
request.matchdict['scheme_id'] = 'TREES'
request.matchdict['c_id'] = '666'
request.skos_registry = self.regis
error_raised = False
try:
atramhasisview = AtramhasisView(request)
atramhasisview.concept_view()
except ConceptNotFoundException as e:
error_raised = True
self.assertIsNotNone(e.__str__())
self.assertTrue(error_raised)
def test_no_type(self):
request = self.request
request.matchdict['scheme_id'] = 'TREES'
request.matchdict['c_id'] = '555'
request.skos_registry = self.regis
atramhasisview = AtramhasisView(request)
info = atramhasisview.concept_view()
self.assertEqual(info.status_int, 500)