1 # GNU MediaGoblin -- federated, autonomous media hosting
2 # Copyright (C) 2011 MediaGoblin contributors. See AUTHORS.
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU Affero General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU Affero General Public License for more details.
14 # You should have received a copy of the GNU Affero General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 class TestingMiddleware(object):
19 Middleware for the Unit tests
21 It might make sense to perform some tests on all
22 requests/responses. Or prepare them in a special
23 manner. For example all html responses could be tested
24 for being valid html *after* being rendered.
26 This module is getting inserted at the front of the
27 middleware list, which means: requests are handed here
28 first, responses last. So this wraps up the "normal"
31 If you need to add a test, either add it directly to
32 the appropiate process_request or process_response, or
33 create a new method and call it from process_*.
36 def __init__(self
, mg_app
):
39 def process_request(self
, request
):
42 def process_response(self
, request
, response
):
43 # All following tests should be for html only!
44 if response
.content_type
!= "text/html":
48 # If the template contains a reference to
49 # /mgoblin_static/ instead of using
50 # /request.staticdirect(), error out here.
51 # This could probably be implemented as a grep on
52 # the shipped templates easier...
53 if response
.text
.find("/mgoblin_static/") >= 0:
55 "Response HTML contains reference to /mgoblin_static/ "
56 "instead of staticdirect. Request was for: "