aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristopher Allan Webber <cwebber@dustycloud.org>2013-05-15 11:40:28 -0500
committerChristopher Allan Webber <cwebber@dustycloud.org>2013-05-15 11:40:28 -0500
commita1099bba79077c1258e586e2e2cbfe0094f10118 (patch)
treebf813a8ab2c5cb6f0110d4ba7f15d48a31313490
parent38ebd05d1a759c3a057ab041124c313cf5724dc4 (diff)
downloadmediagoblin-a1099bba79077c1258e586e2e2cbfe0094f10118.tar.lz
mediagoblin-a1099bba79077c1258e586e2e2cbfe0094f10118.tar.xz
mediagoblin-a1099bba79077c1258e586e2e2cbfe0094f10118.zip
Testing the template_context_prerender hook
This allows for modifying any context *right before render*, including access to the variables that are passed in. This test takes advantage of that and takes one of the variables, "doubleme", and modifies it (doubles it!) In our case it turns "happy" and "joy" into "happyhappy" and "joyjoy". This commit sponsored by Mark Holmquist. Thank you!
-rw-r--r--mediagoblin/tests/test_pluginapi.py6
-rw-r--r--mediagoblin/tests/testplugins/modify_context/__init__.py8
-rw-r--r--mediagoblin/tests/testplugins/modify_context/templates/contextplugin/general.html1
-rw-r--r--mediagoblin/tests/testplugins/modify_context/templates/contextplugin/specific.html1
-rw-r--r--mediagoblin/tests/testplugins/modify_context/views.py6
5 files changed, 17 insertions, 5 deletions
diff --git a/mediagoblin/tests/test_pluginapi.py b/mediagoblin/tests/test_pluginapi.py
index 74a00ce0..73ad235e 100644
--- a/mediagoblin/tests/test_pluginapi.py
+++ b/mediagoblin/tests/test_pluginapi.py
@@ -348,11 +348,13 @@ def test_modify_context(context_modified_app):
specific thing: in yer specificpage
global thing: globally appended!
-something: orother"""
+something: orother
+doubleme: happyhappy"""
# General test, should have global context variable only
result = context_modified_app.get("/modify_context/")
assert result.body.strip() == """General page!
global thing: globally appended!
-lol: cats"""
+lol: cats
+doubleme: joyjoy"""
diff --git a/mediagoblin/tests/testplugins/modify_context/__init__.py b/mediagoblin/tests/testplugins/modify_context/__init__.py
index 6ddcd652..164e66c1 100644
--- a/mediagoblin/tests/testplugins/modify_context/__init__.py
+++ b/mediagoblin/tests/testplugins/modify_context/__init__.py
@@ -26,6 +26,11 @@ def append_to_global_context(context):
context['global_append'] = 'globally appended!'
return context
+def double_doubleme(context):
+ if 'doubleme' in context:
+ context['doubleme'] = context['doubleme'] * 2
+ return context
+
def setup_plugin():
routes = [
@@ -46,4 +51,5 @@ hooks = {
'setup': setup_plugin,
('modify_context.specific_page',
'contextplugin/specific.html'): append_to_specific_context,
- 'template_global_context': append_to_global_context}
+ 'template_global_context': append_to_global_context,
+ 'template_context_prerender': double_doubleme}
diff --git a/mediagoblin/tests/testplugins/modify_context/templates/contextplugin/general.html b/mediagoblin/tests/testplugins/modify_context/templates/contextplugin/general.html
index 7b7261c6..9cf96d3e 100644
--- a/mediagoblin/tests/testplugins/modify_context/templates/contextplugin/general.html
+++ b/mediagoblin/tests/testplugins/modify_context/templates/contextplugin/general.html
@@ -2,3 +2,4 @@ General page!
global thing: {{ global_append }}
lol: {{ lol }}
+doubleme: {{ doubleme }}
diff --git a/mediagoblin/tests/testplugins/modify_context/templates/contextplugin/specific.html b/mediagoblin/tests/testplugins/modify_context/templates/contextplugin/specific.html
index 25bea3e2..5b1b4c4a 100644
--- a/mediagoblin/tests/testplugins/modify_context/templates/contextplugin/specific.html
+++ b/mediagoblin/tests/testplugins/modify_context/templates/contextplugin/specific.html
@@ -3,3 +3,4 @@ Specific page!
specific thing: {{ specific_page_append }}
global thing: {{ global_append }}
something: {{ something }}
+doubleme: {{ doubleme }}
diff --git a/mediagoblin/tests/testplugins/modify_context/views.py b/mediagoblin/tests/testplugins/modify_context/views.py
index 025c84d6..701ec6f9 100644
--- a/mediagoblin/tests/testplugins/modify_context/views.py
+++ b/mediagoblin/tests/testplugins/modify_context/views.py
@@ -21,11 +21,13 @@ def specific(request):
return render_to_response(
request,
'contextplugin/specific.html',
- {"something": "orother"})
+ {"something": "orother",
+ "doubleme": "happy"})
def general(request):
return render_to_response(
request,
'contextplugin/general.html',
- {"lol": "cats"})
+ {"lol": "cats",
+ "doubleme": "joy"})