def test_Blog(env, mocker): from wals3.blog import Blog vs = ValueSet.first() class wp(object): def __init__(self, cats=False): if cats: self.cats = [ dict(id=1, name='Languages'), dict(id=2, name='Chapters'), dict(id=3, name=vs.parameter.chapter.area.name), ] else: self.cats = [] def Client(self, *args, **kw): return mocker.Mock(get_categories=lambda: self.cats, set_categories=lambda c: dict(n=1), get_post_id_from_path=lambda p: None) mocker.patch('wals3.blog.wordpress', wp()) blog = Blog(defaultdict(lambda: '')) blog.post_url(vs, env['request'], create=True) mocker.patch('wals3.blog.wordpress', wp(cats=True)) blog = Blog(defaultdict(lambda: '')) blog.post_url(vs, env['request'], create=True)
def test_Blog(self): from wals3.blog import Blog vs = ValueSet.first() class wp(object): def __init__(self, cats=False): if cats: self.cats = [ dict(id=1, name='Languages'), dict(id=2, name='Chapters'), dict(id=3, name=vs.parameter.chapter.area.name), ] else: self.cats = [] def Client(self, *args, **kw): return Mock( get_categories=lambda: self.cats, set_categories=lambda c: dict(n=1), get_post_id_from_path=lambda p: None) with patch('wals3.blog.wordpress', wp()): blog = Blog(defaultdict(lambda: '')) blog.post_url(vs, self.env['request'], create=True) with patch('wals3.blog.wordpress', wp(cats=True)): blog = Blog(defaultdict(lambda: '')) blog.post_url(vs, self.env['request'], create=True)
def main(global_config, **settings): """return a Pyramid WSGI application.""" settings['route_patterns'] = { 'languages': '/languoid', 'language': '/languoid/lect/wals_code_{id:[^/\.]+}', 'source': '/refdb/record/{id:[^/\.]+}', 'sources': '/refdb', 'familys': '/languoid/family', 'family': '/languoid/family/{id:[^/\.]+}', 'genus': '/languoid/genus/{id:[^/\.]+}', 'parameters': '/feature', 'parameter': '/feature/{id:[^/\.]+}', 'sentences': '/example', 'sentence': '/example/{id:[^/\.]+}', 'contributions': '/chapter', 'contribution': '/chapter/{id:[^/\.]+}', 'countrys': '/country', 'country': '/country/{id:[^/\.]+}', 'contributors': '/author', 'contributor': '/author/{id:[^/\.]+}', 'legal': '/about/legal', 'olac': '/languoid/oai', 'credits': '/about/credits', } filename_pattern = re.compile('(?P<spec>(c|d|s|f|t)[0-9a-f]{3})\.png') icons = [] for p in sorted(Path(__file__).parent.joinpath('static', 'icons').iterdir(), key=lambda p: p.name): m = filename_pattern.match(p.name) if m: icons.append(WalsIcon(m.group('spec'))) config = Configurator(**dict(settings=settings)) config.include('clldmpg') for utility, interface in [ (WalsCtxFactoryQuery(), ICtxFactoryQuery), (map_marker, IMapMarker), (Blog(settings), IBlog), (icons, IIconList), ]: config.registry.registerUtility(utility, interface) config.register_resource('family', Family, IFamily, with_index=True) config.register_resource('genus', Genus, IGenus, with_index=True) config.register_resource('country', Country, ICountry) config.add_route('sample_alt', '/languoid/samples/{count}.{ext}', factory=sample_factory) config.add_route('sample', '/languoid/samples/{count}', factory=sample_factory) for spec in [ dict(template='parameter/detail_tab.mako', mimetype='application/vnd.clld.tab', send_mimetype="text/plain", extension='tab', name='tab-separated values'), dict(template='parameter/detail_xml.mako', mimetype='application/vnd.clld.xml', send_mimetype="application/xml", extension='xml', name='WALS XML', __doc__="Custom XML format."), dict(template='parameter/detail_georss.mako', mimetype='application/vnd.clld.georss+xml', send_mimetype="application/rdf+xml", extension='georss', name="GeoRSS", __doc__="RSS with location information " "(http://en.wikipedia.org/wiki/GeoRSS)."), dict(template='parameter/detail_kml.mako', mimetype='application/vnd.google-earth.kml+xml', send_mimetype="application/xml", extension='kml', name='KML', __doc__="Keyhole Markup Language"), ]: config.register_adapter(spec, IParameter) config.add_route('feature_info', '/feature-info/{id}') config.add_route('genealogy', '/languoid/genealogy') config.add_301('/index', lambda req: req.route_url('dataset')) config.add_301( '/.{ext}', lambda req: req.route_url('dataset_alt', ext=req.matchdict['ext'])) config.add_301( '/example/{fid}/all', lambda req: req.route_url('parameter', id=req.matchdict['fid'])) config.add_301( '/example/all/wals_code_{lid}', lambda req: req.route_url('sentences', _query=dict(language=req.matchdict['lid']))) # we redirect legacy urls for datapoints because they could not be expressed # with a single id. def datapoint(req): data = {k: v for k, v in req.matchdict.items()} if data['fid'][-1] not in ascii_uppercase: data['fid'] += 'A' return req.route_url('valueset', id='%(fid)s-%(lid)s' % data, _query=req.query_params) config.add_301('/datapoint/{fid}/wals_code_{lid}', datapoint, name='datapoint') # we redirect legacy urls for feature combinations because they could not be expressed # with a single id. def combined(req): return req.route_url('combination', id='%(id1)s_%(id2)s' % req.matchdict, _query=req.query_params) config.add_301('/feature/combined/{id1}/{id2}', combined, name='combined') config.add_301( "/feature/description/{id:[0-9]+}", lambda req: req.route_url('contribution', id=req.matchdict['id'])) config.add_301( "/languoid/by_geography", lambda req: req.route_url('country', id=req.params.get('country'))) config.add_301( "/wals-2011-{fid}", lambda req: req.route_url('parameter', id=req.matchdict.get('fid'))) config.add_301('/languoid/lect', lambda req: req.route_url('languages')) config.add_301('/languoid/family', lambda req: req.route_url('languages')) config.add_301('/languoid/genus', lambda req: req.route_url('languages')) config.add_301('/supplement/1', lambda req: req.route_url('contribution', id='s1')) config.add_301('/supplement/3', lambda req: req.route_url('contribution', id='s1')) config.add_301('/supplement/5', lambda req: req.route_url('contribution', id='s5')) config.add_301('/supplement/6', lambda req: req.route_url('contribution', id='s6')) config.add_301('/supplement/7', lambda req: req.route_url('contribution', id='s7')) config.add_301('/supplement/8', lambda req: req.route_url('contribution', id='s8')) config.add_301('/supplement/9', lambda req: req.route_url('contribution', id='s9')) for pattern in [ '/refdb/', '/refdb/record', '/refdb/record/', '/refdb/search' ]: config.add_301(pattern, lambda req: req.route_url('sources')) config.add_410('/languoid/osd.{ext}') config.add_410("/experimental/{id}") config.add_route('olac.source', '/refdb_oai') config.add_route('languoids', '/languoids') config.add_route('blog_feed', '/blog') config.register_download( Matrix(Language, 'wals3', description="Feature values CSV")) config.register_download( Download(Source, 'wals3', ext='bib', description="Sources as BibTeX")) return config.make_wsgi_app()