Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Actually, let's put this on Website itself (#91)

I want to use this in a hook, and that's not a test. I have a live
website object.
  • Loading branch information...
commit 1ad2d7fce71085b77da1ab0b08bea47a6ac124f9 1 parent 89e41ba
@whit537 whit537 authored
Showing with 38 additions and 40 deletions.
  1. +0 −40 aspen/testing/__init__.py
  2. +38 −0 aspen/website.py
View
40 aspen/testing/__init__.py
@@ -117,43 +117,3 @@ def assert_raises(Exc, call, *arg, **kw):
return exc
NoException = True
-
-
-# Website subclass for testing simplates.
-# =======================================
-
-class TestWebsite(Website):
-
- def serve_request(self, path):
- """Given an URL path, return response.
- """
- request = Request(uri=path)
- request.website = self
- response = self.handle_safely(request)
- return response
-
-
- def load_simplate(self, path, request=None, return_request_too=False):
- """Given an URL path, return a simplate (Resource) object.
- """
- if request is None:
- request = Request(uri=path)
- if not hasattr(request, 'website'):
- request.website = self
- self.run_inbound(request)
- resource = resources.get(request)
- if return_request_too:
- return resource, request
- else:
- return resource
-
-
- def exec_simplate(self, path="/", request=None, response=None):
- """Given the URL path of a simplate, exec page two and return response.
- """
- resource, request = self.load_simplate(path, request, True)
- if response is None:
- response = Response(charset=self.charset_dynamic)
- context = resource.populate_context(request, response)
- exec resource.pages[1] in context # let's let exceptions raise
- return response, context
View
38 aspen/website.py
@@ -229,3 +229,41 @@ def log_access(self, request, response):
# =======
aspen.log("%-36s %s" % (response, msg))
+
+
+ # Conveniences for testing
+ # ========================
+
+ def serve_request(self, path):
+ """Given an URL path, return response.
+ """
+ request = Request(uri=path)
+ request.website = self
+ response = self.handle_safely(request)
+ return response
+
+
+ def load_simplate(self, path, request=None, return_request_too=False):
+ """Given an URL path, return a simplate (Resource) object.
+ """
+ if request is None:
+ request = Request(uri=path)
+ if not hasattr(request, 'website'):
+ request.website = self
+ self.run_inbound(request)
+ resource = resources.get(request)
+ if return_request_too:
+ return resource, request
+ else:
+ return resource
+
+
+ def exec_simplate(self, path="/", request=None, response=None):
+ """Given the URL path of a simplate, exec page two and return response.
+ """
+ resource, request = self.load_simplate(path, request, True)
+ if response is None:
+ response = Response(charset=self.charset_dynamic)
+ context = resource.populate_context(request, response)
+ exec resource.pages[1] in context # let's let exceptions raise
+ return response, context
Please sign in to comment.
Something went wrong with that request. Please try again.