Permalink
Browse files

add another error check to kumascript preview code

refactor template test for new preview UI
  • Loading branch information...
groovecoder committed May 23, 2012
1 parent 1405925 commit 6ee0ad1609fe6c586c010e137b92767de0ee372e
Showing with 16 additions and 10 deletions.
  1. +5 −0 apps/wiki/__init__.py
  2. +1 −1 apps/wiki/tests/test_templates.py
  3. +10 −9 apps/wiki/views.py
View
@@ -1,3 +1,8 @@
DIFF_WRAP_COLUMN = 40
TEMPLATE_TITLE_PREFIX = 'Template:'
DOCUMENTS_PER_PAGE = 100
+KUMASCRIPT_TIMEOUT_ERROR = [
+ {"level": "error",
+ "message": "Request to Kumascript service timed out",
+ "args": ["TimeoutError"]}
+]
@@ -1342,7 +1342,7 @@ def test_preview(self):
{'content': '<h1>Test Content</h1>'})
eq_(200, response.status_code)
doc = pq(response.content)
- eq_('Test Content', doc('#doc-content h1').text())
+ eq_('Test Content', doc('div#wikiArticle h1').text())
def test_preview_locale(self):
raise SkipTest
View
@@ -43,7 +43,8 @@
from sumo.helpers import urlparams
from sumo.urlresolvers import Prefixer, reverse
from sumo.utils import paginate, smart_int
-from wiki import DOCUMENTS_PER_PAGE, TEMPLATE_TITLE_PREFIX
+from wiki import (DOCUMENTS_PER_PAGE, TEMPLATE_TITLE_PREFIX,
+ KUMASCRIPT_TIMEOUT_ERROR)
from wiki.events import (EditDocumentEvent, ReviewableRevisionInLocaleEvent,
ApproveRevisionInLocaleEvent)
from wiki.forms import DocumentForm, RevisionForm, ReviewForm
@@ -419,9 +420,13 @@ def _perform_kumascript_post(content):
}
resp = requests.post(ks_url, timeout=constance.config.KUMASCRIPT_TIMEOUT,
data=content, headers=headers)
- resp_body = _process_kumascript_body(resp)
- resp_errors = _process_kumascript_errors(resp)
- return resp_body, resp_errors
+ if resp:
+ resp_body = _process_kumascript_body(resp)
+ resp_errors = _process_kumascript_errors(resp)
+ return resp_body, resp_errors
+ else:
+ resp_errors = KUMASCRIPT_TIMEOUT_ERROR
+ return content, resp_errors
def _perform_kumascript_request(request, response_headers, document,
@@ -532,11 +537,7 @@ def _perform_kumascript_request(request, response_headers, document,
cache.set(ck_errors, resp_errors, timeout=max_age)
elif resp.status_code == None:
- resp_errors = [
- {"level": "error",
- "message": "Request to Kumascript service timed out",
- "args": ["TimeoutError"]}
- ]
+ resp_errors = KUMASCRIPT_TIMEOUT_ERROR
else:
resp_errors = [

0 comments on commit 6ee0ad1

Please sign in to comment.