def test_make_wsgi_app_args(self): res = manager.make_wsgi_app(port='8080', documentroot=self.datadir, apiendpoint='/api-endpoint/', searchendpoint='/search-endpoint/', repos=[]) self.assertTrue(callable(res))
def setUp(self): super(WSGI,self).setUp() if self.storelocation.startswith("data/"): self.storelocation = self.storelocation.replace("data", self.datadir) if self.indexlocation.startswith("data/"): self.indexlocation = self.indexlocation.replace("data", self.datadir) self.put_files_in_place() # use self.repo (simple testcases) or self.repos (complex # testcases like AdvancedAPI)? if hasattr(self, 'repos'): repos = self.repos else: repos = [self.repo] # print("making app: %s %s" % (self.storetype, self.indextype)) config = LayeredConfig(Defaults({'datadir': self.datadir, 'apiendpoint': '/myapi/', 'searchendpoint': '/mysearch/', 'url': 'http://localhost:8000/', 'storetype': self.storetype, 'storelocation': self.storelocation, 'storerepository': self.storerepository, 'indextype': self.indextype, 'indexlocation': self.indexlocation, 'wsgiappclass': 'ferenda.WSGIApp', 'legacyapi': False, 'wsgiexceptionhandler': True})) self.app = manager.make_wsgi_app(config, repos=repos) self.builder = EnvironBuilder('/', base_url="http://localhost:8000/", headers={"Accept": DEFAULT_HTTP_ACCEPT})
def setUp(self): super(WSGI,self).setUp() if self.storelocation.startswith("data/"): self.storelocation = self.storelocation.replace("data", self.datadir) if self.indexlocation.startswith("data/"): self.indexlocation = self.indexlocation.replace("data", self.datadir) self.put_files_in_place() # use self.repo (simple testcases) or self.repos (complex # testcases like AdvancedAPI)? if hasattr(self, 'repos'): repos = self.repos else: repos = [self.repo] # print("making app: %s %s" % (self.storetype, self.indextype)) self.app = manager.make_wsgi_app(port=8000, documentroot=self.datadir, apiendpoint="/myapi/", searchendpoint="/mysearch/", url="http://localhost:8000/", repos=repos, storetype=self.storetype, storelocation=self.storelocation, storerepository=self.storerepository, indextype=self.indextype, indexlocation=self.indexlocation) self.env = {'HTTP_ACCEPT': DEFAULT_HTTP_ACCEPT, 'PATH_INFO': '/', 'SERVER_NAME': 'localhost', 'SERVER_PORT': '8000', 'QUERY_STRING': '', 'wsgi.url_scheme': 'http'}
def setUp(self): super(WSGI,self).setUp() self.app = manager.make_wsgi_app(port=8000, documentroot=self.datadir, apiendpoint="/myapi/", searchendpoint="/mysearch/", repos = [self.repo]) self.env = {'HTTP_ACCEPT': 'text/xml, application/xml, application/xhtml+xml, text/html;q=0.9, text/plain;q=0.8, image/png,*/*;q=0.5', 'PATH_INFO': '/', 'SERVER_NAME': 'localhost', 'SERVER_PORT': '8000', 'wsgi.url_scheme': 'http'} # Put files in place: parsed util.ensure_dir(self.repo.store.parsed_path("123/a")) shutil.copy2("test/files/base/parsed/123/a.xhtml", self.repo.store.parsed_path("123/a")) # distilled g = Graph() g.parse(source="test/files/base/distilled/123/a.ttl", format="turtle") with self.repo.store.open_distilled("123/a", "wb") as fp: fp.write(g.serialize(format="pretty-xml")) # generated util.ensure_dir(self.repo.store.generated_path("123/a")) shutil.copy2("test/files/base/generated/123/a.html", self.repo.store.generated_path("123/a")) # annotations util.ensure_dir(self.repo.store.annotation_path("123/a")) shutil.copy2("test/files/base/annotations/123/a.grit.xml", self.repo.store.annotation_path("123/a")) # config resources = self.datadir+os.sep+"rsrc"+os.sep+"resources.xml" util.ensure_dir(resources) shutil.copy2("test/files/base/rsrc/resources.xml", resources) # index.html index = self.datadir+os.sep+"index.html" with open(index, "wb") as fp: fp.write(b'<h1>index.html</h1>') # toc/index.html + toc/title/a.html with self.repo.store.open("index", "toc", ".html", "wb") as fp: fp.write(b'<h1>TOC for base</h1>') with self.repo.store.open("title/a", "toc", ".html", "wb") as fp: fp.write(b'<h1>Title starting with "a"</h1>') # distilled/dump.nt with self.repo.store.open("dump", "distilled", ".nt", "wb") as fp: fp.write(g.serialize(format="nt"))
def test_make_wsgi_app_ini(self): inifile = self.datadir + os.sep + "ferenda.ini" with open(inifile, "w") as fp: fp.write("""[__root__] datadir = /dev/null url = http://localhost:7777/ apiendpoint = /myapi/ searchendpoint = /mysearch/ """) res = manager.make_wsgi_app(inifile) self.assertTrue(callable(res))
def test_make_wsgi_app_ini(self): inifile = self.datadir + os.sep + "ferenda.ini" with open(inifile, "w") as fp: fp.write("""[__root__] datadir = /dev/null url = http://localhost:7777/ apiendpoint = /myapi/ searchendpoint = /mysearch/ indextype = WHOOSH indexlocation = data/whooshindex """) res = manager.make_wsgi_app(inifile) self.assertTrue(callable(res))
def setUp(self): super(WSGI, self).setUp() if self.storelocation.startswith("data/"): self.storelocation = self.storelocation.replace( "data", self.datadir) if self.indexlocation.startswith("data/"): self.indexlocation = self.indexlocation.replace( "data", self.datadir) self.put_files_in_place() # use self.repo (simple testcases) or self.repos (complex # testcases like AdvancedAPI)? if hasattr(self, 'repos'): repos = self.repos else: repos = [self.repo] # print("making app: %s %s" % (self.storetype, self.indextype)) self.app = manager.make_wsgi_app(port=8000, documentroot=self.datadir, apiendpoint="/myapi/", searchendpoint="/mysearch/", url="http://localhost:8000/", repos=repos, storetype=self.storetype, storelocation=self.storelocation, storerepository=self.storerepository, indextype=self.indextype, indexlocation=self.indexlocation) self.env = { 'HTTP_ACCEPT': DEFAULT_HTTP_ACCEPT, 'PATH_INFO': '/', 'SERVER_NAME': 'localhost', 'SERVER_PORT': '8000', 'QUERY_STRING': '', 'wsgi.url_scheme': 'http' }
#!/usr/bin/env python # -*- coding: utf-8 -*- from __future__ import unicode_literals import os import sys sys.path.append("..") try: from ferenda.manager import make_wsgi_app # FIXME: should we chdir to os.path.dirname(__file__) instead? inifile = os.path.join(os.path.dirname(__file__), "ferenda.ini") application = make_wsgi_app(inifile=inifile) except ImportError as e: exception_data = str(e) def application(environ, start_response): msg = """500 Internal Server Error: %s sys.path: %r os.getcwd(): %s""" % (exception_data, sys.path, os.getcwd()) msg = msg.encode('ascii') start_response("500 Internal Server Error", [ ("Content-Type", "text/plain"), ("Content-Length", str(len(msg))) ]) return iter([msg])
#!/usr/bin/env python # -*- coding: utf-8 -*- from __future__ import unicode_literals import os import sys sys.path.append("..") try: from ferenda.manager import make_wsgi_app, find_config_file, load_config application = make_wsgi_app(load_config(find_config_file())) except ImportError as e: exception_data = str(e) def application(environ, start_response): msg = """500 Internal Server Error: %s sys.path: %r os.getcwd(): %s""" % (exception_data, sys.path, os.getcwd()) msg = msg.encode('ascii') start_response("500 Internal Server Error", [("Content-Type", "text/plain"), ("Content-Length", str(len(msg)))]) return iter([msg])