def testDownload2(self): from clld.web.adapters.download import CsvDump, N3Dump, RdfXmlDump from clld.web.adapters.cldf import CldfDownload tmp = mktemp() class Path(MagicMock, UnicodeMixin): @property def stem(self): return 'a' @property def parent(self): return Mock(exists=Mock(return_value=False)) def open(self, mode): return open(tmp, mode) with patch.multiple( 'clld.web.adapters.cldf', ZipFile=MagicMock(), Path=MagicMock(return_value=Path()), move=Mock(), remove=Mock(), ): with patch( 'clld.web.adapters.download.Path', new=MagicMock(return_value=Path()), ): dl = CldfDownload(Dataset, 'clld') dl.create(self.env['request'], verbose=False) with patch.multiple( 'clld.web.adapters.download', ZipFile=MagicMock(), Path=MagicMock(return_value=Path()), move=Mock(), remove=Mock(), ): dl = CsvDump(Language, 'clld') dl.create(self.env['request'], verbose=False) dl.create(self.env['request'], filename='name.n3', verbose=False) dl = N3Dump(Language, 'clld') dl.create(self.env['request'], verbose=False) if os.path.exists(tmp): os.remove(tmp) else: # pragma: no cover raise ValueError dl = RdfXmlDump(Language, 'clld') dl.create(self.env['request'], verbose=False) with closing(gzip.open(tmp, 'rb')) as fp: assert et.fromstring(fp.read()) if os.path.exists(tmp): os.remove(tmp) else: # pragma: no cover raise ValueError
def main(global_config, **settings): """ This function returns a Pyramid WSGI application. """ settings['route_patterns'] = { 'walss': '/wals', 'wals': '/wals/{id:[^/\.]+}' } config = Configurator(settings=settings) config.include('clldmpg') config.registry.registerUtility(ApicsCtxFactoryQuery(), ICtxFactoryQuery) config.registry.registerUtility(ApicsMapMarker(), IMapMarker) config.registry.registerUtility(frequency_marker, IFrequencyMarker) config.registry.registerUtility(link_attrs, ILinkAttrs) config.register_menu( ('dataset', partial(menu_item, 'dataset', label='Home')), ('contributions', partial(menu_item, 'contributions')), ('parameters', partial(menu_item, 'parameters')), ('apics_wals', lambda ctx, rq: (rq.route_url('walss'), u'WALS\u2013APiCS')), ('surveys', partial(menu_item, 'surveys')), ('sentences', partial(menu_item, 'sentences')), ('sources', partial(menu_item, 'sources')), ('contributors', partial(menu_item, 'contributors')), ) config.register_adapter( { "base": Representation, "mimetype": 'application/vnd.clld.chapter+html', "send_mimetype": "text/html", "extension": 'chapter.html', "template": 'parameter/chapter_html.mako', }, IParameter, name="application/vnd.clld.chapter+html") config.register_download( CsvDump(common.Language, 'apics', description="Languages as CSV")) config.register_download( N3Dump(common.Language, 'apics', description="Languages as RDF")) config.register_download( Download(common.Source, 'apics', ext='bib', description="Sources as BibTeX")) config.register_resource('wals', Wals, IWals, with_index=True) config.register_resource('survey', Survey, ISurvey, with_index=True) config.register_adapters([ (ISurvey, Representation, 'application/vnd.clld.md+xml', 'md.html', 'md_html.mako', { 'rel': 'describedby' }) ]) return config.make_wsgi_app()
def test_config(config): class IF(Interface): pass # should have no effect, because a resource with this name is registered by # default: config.register_menu('languages', ('sources', dict(label='References'))) config.register_resource('language', None, None) config.register_resource('testresource', Language, IF, with_index=True, test=True) config.register_download(N3Dump(Language, 'clld')) config.add_301('/301pattern', 'http://example.org') config.add_410('/410pattern')
def test_get_configurator(self): from clld.web.app import get_configurator, menu_item class IF(Interface): """" """ "" config = get_configurator('clld', settings={'sqlalchemy.url': 'sqlite://'}, routes=[('languages', '/other')]) # should have no effect, because a resource with this name is registered by # default: config.register_resource('language', None, None) config.register_resource('testresource', Language, IF, with_index=True) config.register_download(N3Dump(Language, 'clld'))
def testDownload2(self): from clld.web.adapters.download import CsvDump, N3Dump, RdfXmlDump with patch.multiple( 'clld.web.adapters.download', GzipFile=MagicMock(), ZipFile=MagicMock(), path=Mock(return_value=Mock(dirname=Mock(return_value=Mock( exists=Mock(return_value=False))))), ): dl = CsvDump(Language, 'clld') dl.create(self.env['request'], verbose=False) dl.create(self.env['request'], filename='name.n3', verbose=False) dl = N3Dump(Language, 'clld') dl.create(self.env['request'], verbose=False) dl = RdfXmlDump(Language, 'clld') dl.create(self.env['request'], verbose=False)
def test_config(self): class IF(Interface): pass config = Configurator( root_package=importlib.import_module('clld.web'), settings={ 'sqlalchemy.url': 'sqlite://', 'clld.pacific_centered_maps': True}) config.include('clld.web.app') # should have no effect, because a resource with this name is registered by # default: config.register_menu('languages', ('sources', dict(label='References'))) config.register_resource('language', None, None) config.register_resource('testresource', Language, IF, with_index=True, test=True) config.register_download(N3Dump(Language, 'clld')) config.add_301('/301pattern', 'http://example.org') config.add_410('/410pattern')
def test_get_downloads(self): from clld.web.util.helpers import get_rdf_dumps, get_downloads with self.utility(N3Dump(common.Language, 'clld'), IDownload): assert list(get_rdf_dumps(self.env['request'], common.Language)) assert list(get_downloads(self.env['request']))
def main(global_config, **settings): """ This function returns a Pyramid WSGI application. """ settings.update(CFG) settings['navbar.inverse'] = True settings['route_patterns'] = { 'languages': '/glottolog/language', 'language': '/resource/languoid/id/{id:[^/\.]+}', 'source': '/resource/reference/id/{id:[^/\.]+}', 'sources': '/langdoc', #'provider': '/langdoc/langdocinformation#provider-{id}', 'providers': '/langdoc/langdocinformation', } settings['sitemaps'] = ['language', 'source'] config = Configurator(settings=settings) # # Note: The following routes must be registered before including the clld web app, # because they are special cases of a more general route pattern registered there. # config.add_route('languoid.xhtml', '/resource/languoid/id/{id:[^/\.]+}.xhtml') config.add_route('reference.xhtml', '/resource/reference/id/{id:[^/\.]+}.xhtml') config.include('clldmpg') config.add_route_and_view( 'robots', '/robots.txt', lambda req: Response('Sitemap: {0}\nUser-agent: *\nDisallow: /files/\n' .format(req.route_url('sitemapindex')), content_type='text/plain')) config.registry.registerUtility(GLCtxFactoryQuery(), ICtxFactoryQuery) config.register_menu( #('dataset', partial(menu_item, 'dataset', label='Home')), ('languages', partial(menu_item, 'languages', label='Languages')), ('families', partial(menu_item, 'glottolog.families', label='Families')), ('search', partial(menu_item, 'glottolog.languages', label='Language Search')), ('sources', partial(menu_item, 'sources', label='References')), ('query', partial(menu_item, 'langdoc.complexquery', label='Reference Search')), ('about', partial(menu_item, 'about', label='About')), ) config.register_resource('provider', models.Provider, IProvider, with_index=True) config.register_adapter( adapter_factory('provider/index_html.mako', base=Index), IProvider) config.add_view(views.redirect_languoid_xhtml, route_name='languoid.xhtml') config.add_view(views.redirect_reference_xhtml, route_name='reference.xhtml') config.add_route_and_view('news', '/news', views.news, renderer='news.mako') config.add_route_and_view('glottolog.meta', '/glottolog/glottologinformation', views.glottologmeta, renderer='glottologmeta.mako') config.add_route_and_view('glottolog.families', '/glottolog/family', views.families, renderer='families.mako') config.add_route_and_view('glottolog.iso', '/resource/languoid/iso/{id:[^/\.]+}', views.iso) config.add_route_and_view('glottolog.languages', '/glottolog', views.languages, renderer='language/search_html.mako') config.add_route_and_view('glottolog.childnodes', '/db/getchildlects', views.childnodes, renderer='json') config.add_route_and_view('langdoc.complexquery', '/langdoc/complexquery', views.langdoccomplexquery, renderer='langdoccomplexquery.mako') for name in 'credits glossary cite downloads contact'.split(): pp = '/' if name == 'credits' else '/meta/' config.add_route_and_view('home.' + name, pp + name, getattr(views, name), renderer=name + '.mako') config.register_download( adapters.LanguoidCsvDump(models.Languoid, 'glottolog3', description="Languoids as CSV")) config.register_download( adapters.LanguoidN3Dump(Language, 'glottolog3', description="Languoids as RDF")) config.register_download( Download(Source, 'glottolog3', ext='bib', description="References as BibTeX")) config.register_download( N3Dump(Source, 'glottolog3', description="References as RDF")) config.add_route('langdocstatus', '/langdoc/status') config.add_route('langdocstatus.browser', '/langdoc/status/browser') config.add_route('langdocstatus.languages', '/langdoc/status/languages-{ed:[0-9]}-{sdt:[0-9]}') config.scan('glottolog3.langdocstatus') config.register_datatable('providers', Providers) return config.make_wsgi_app()
def main(global_config, **settings): """ This function returns a Pyramid WSGI application. """ lc = path(glottolog3.__file__).dirname().joinpath('static', 'legacy_codes.json') with open(lc) as fp: settings['legacy_codes'] = load(fp) settings.update(CFG) settings['navbar.inverse'] = True settings['route_patterns'] = { 'languages': '/glottolog', 'language': '/resource/languoid/id/{id:[^/\.]+}', 'source': '/resource/reference/id/{id:[^/\.]+}', 'sources': '/langdoc', #'provider': '/langdoc/langdocinformation#provider-{id}', 'providers': '/langdoc/langdocinformation', } settings['sitemaps'] = ['language', 'source'] config = get_configurator('glottolog3', (GLCtxFactoryQuery(), ICtxFactoryQuery), settings=settings, routes=[ ('languoid.xhtml', '/resource/languoid/id/{id:[^/\.]+}.xhtml'), ('reference.xhtml', '/resource/reference/id/{id:[^/\.]+}.xhtml') ]) config.register_menu( ('dataset', partial(menu_item, 'dataset', label='Home')), ('languages', partial(menu_item, 'languages', label='Languoids')), ('sources', partial(menu_item, 'sources', label='Langdoc')), ) config.register_resource('provider', models.Provider, IProvider, with_index=True) config.register_adapter(adapters.Redirect, IProvider) config.register_adapter(adapters.Bigmap, ILanguage) config.register_adapter( adapter_factory('provider/index_html.mako', base=Index), IProvider) config.register_datatable('providers', datatables.Providers) config.add_view(views.redirect_languoid_xhtml, route_name='languoid.xhtml') config.add_view(views.redirect_reference_xhtml, route_name='reference.xhtml') config.add_route_and_view('glottolog.meta', '/glottolog/glottologinformation', views.glottologmeta, renderer='glottologmeta.mako') config.add_route_and_view('glottolog.families', '/glottolog/family', views.families, renderer='families.mako') config.add_route_and_view('glottolog.iso', '/resource/languoid/iso/{id:[^/\.]+}', views.iso) config.add_route_and_view('glottolog.languages', '/glottolog/language', views.languages, renderer='languages.mako') config.add_route_and_view('glottolog.childnodes', '/db/getchildlects', views.childnodes, renderer='json') config.add_route_and_view('langdoc.complexquery', '/langdoc/complexquery', views.langdoccomplexquery, renderer='langdoccomplexquery.mako') for name in 'credits glossary cite downloads errata contact'.split(): pp = '/' if name == 'credits' else '/meta/' config.add_route_and_view('home.' + name, pp + name, getattr(views, name), renderer=name + '.mako') config.register_map('language', maps.LanguoidMap) config.register_datatable('languages', datatables.Families) config.register_datatable('sources', datatables.Refs) config.register_download( CsvDump(Language, 'glottolog3', description="Languoids as CSV")) config.register_download( N3Dump(Language, 'glottolog3', description="Languoids as RDF")) config.register_download( Download(Source, 'glottolog3', ext='bib', description="References as BibTeX")) config.register_download( N3Dump(Source, 'glottolog3', description="References as RDF")) return config.make_wsgi_app()