Mercurial > piecrust2
comparison piecrust/serving/server.py @ 391:3e4bb57d8506
tests: Add support for testing the Chef server.
* Make the server be functional without calling `getWsgiApp`.
* Add new type of test files that use a Werkzeug test client.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sun, 17 May 2015 10:48:41 -0700 |
parents | 3a184fbc900b |
children | 2bb5327c4c1f |
comparison
equal
deleted
inserted
replaced
390:3a184fbc900b | 391:3e4bb57d8506 |
---|---|
10 from werkzeug.exceptions import ( | 10 from werkzeug.exceptions import ( |
11 NotFound, MethodNotAllowed, InternalServerError, HTTPException) | 11 NotFound, MethodNotAllowed, InternalServerError, HTTPException) |
12 from werkzeug.wrappers import Request, Response | 12 from werkzeug.wrappers import Request, Response |
13 from werkzeug.wsgi import ClosingIterator, wrap_file | 13 from werkzeug.wsgi import ClosingIterator, wrap_file |
14 from jinja2 import FileSystemLoader, Environment | 14 from jinja2 import FileSystemLoader, Environment |
15 from piecrust import CACHE_DIR | |
15 from piecrust.app import PieCrust | 16 from piecrust.app import PieCrust |
16 from piecrust.rendering import QualifiedPage, PageRenderingContext, render_page | 17 from piecrust.rendering import QualifiedPage, PageRenderingContext, render_page |
17 from piecrust.sources.base import MODE_PARSING | 18 from piecrust.sources.base import MODE_PARSING |
18 from piecrust.uriutil import split_sub_uri | 19 from piecrust.uriutil import split_sub_uri |
19 | 20 |
60 self.debug = debug | 61 self.debug = debug |
61 self.sub_cache_dir = sub_cache_dir | 62 self.sub_cache_dir = sub_cache_dir |
62 self.enable_debug_info = enable_debug_info | 63 self.enable_debug_info = enable_debug_info |
63 self.run_sse_check = run_sse_check | 64 self.run_sse_check = run_sse_check |
64 self.static_preview = static_preview | 65 self.static_preview = static_preview |
65 self._out_dir = None | 66 self._page_record = ServeRecord() |
66 self._page_record = None | 67 self._out_dir = os.path.join(root_dir, CACHE_DIR, 'server') |
67 self._proc_loop = None | 68 self._proc_loop = None |
68 self._mimetype_map = load_mimetype_map() | 69 self._mimetype_map = load_mimetype_map() |
69 | 70 |
70 def getWsgiApp(self): | 71 def getWsgiApp(self): |
71 # Bake all the assets so we know what we have, and so we can serve | 72 # Bake all the assets so we know what we have, and so we can serve |
72 # them to the client. We need a temp app for this. | 73 # them to the client. We need a temp app for this. |
73 app = PieCrust(root_dir=self.root_dir, debug=self.debug) | 74 app = PieCrust(root_dir=self.root_dir, debug=self.debug) |
74 app._useSubCacheDir(self.sub_cache_dir) | 75 if self.sub_cache_dir: |
76 app._useSubCacheDir(self.sub_cache_dir) | |
75 self._out_dir = os.path.join(app.sub_cache_dir, 'server') | 77 self._out_dir = os.path.join(app.sub_cache_dir, 'server') |
76 self._page_record = ServeRecord() | |
77 | 78 |
78 if not self.run_sse_check or self.run_sse_check(): | 79 if not self.run_sse_check or self.run_sse_check(): |
79 # When using a server with code reloading, some implementations | 80 # When using a server with code reloading, some implementations |
80 # use process forking and we end up going here twice. We only want | 81 # use process forking and we end up going here twice. We only want |
81 # to start the pipeline loop in the inner process most of the | 82 # to start the pipeline loop in the inner process most of the |
118 if response is not None: | 119 if response is not None: |
119 return response(environ, start_response) | 120 return response(environ, start_response) |
120 | 121 |
121 # Create the app for this request. | 122 # Create the app for this request. |
122 app = PieCrust(root_dir=self.root_dir, debug=self.debug) | 123 app = PieCrust(root_dir=self.root_dir, debug=self.debug) |
123 app._useSubCacheDir(self.sub_cache_dir) | 124 if self.sub_cache_dir: |
125 app._useSubCacheDir(self.sub_cache_dir) | |
124 app.config.set('site/root', '/') | 126 app.config.set('site/root', '/') |
125 app.config.set('server/is_serving', True) | 127 app.config.set('server/is_serving', True) |
126 if (app.config.get('site/enable_debug_info') and | 128 if (app.config.get('site/enable_debug_info') and |
127 self.enable_debug_info and | 129 self.enable_debug_info and |
128 '!debug' in request.args): | 130 '!debug' in request.args): |