Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #47 from FND/skinny_render

skinny render
  • Loading branch information...
commit d614d6389401902a37a624fad16fd5cc0debbbb8 2 parents f656853 + ef800d2
@cdent cdent authored
Showing with 31 additions and 12 deletions.
  1. +18 −3 test/test_serialize_tiddler.py
  2. +13 −9 tiddlyweb/serializations/json.py
View
21 test/test_serialize_tiddler.py
@@ -3,7 +3,7 @@
"""
import simplejson
-import py.test
+import pytest
from base64 import b64encode
@@ -59,7 +59,7 @@ def test_bad_string_raises():
foobar = Tiddler('foobar')
serializer.object = foobar
- py.test.raises(TiddlerFormatError, 'serializer.from_string(bad_string)')
+ pytest.raises(TiddlerFormatError, 'serializer.from_string(bad_string)')
def test_generated_json_string():
serializer = Serializer('json', environ={'tiddlyweb.config': config})
@@ -128,7 +128,7 @@ def test_tiddler_json_base64():
info['text'] = '..badbinary..'
string = simplejson.dumps(info)
- py.test.raises(TiddlerFormatError, 'serializer.from_string(string)')
+ pytest.raises(TiddlerFormatError, 'serializer.from_string(string)')
def test_tiddler_json_render():
serializer = Serializer('json', environ={'tiddlyweb.query': {
@@ -142,6 +142,21 @@ def test_tiddler_json_render():
output = serializer.to_string()
info = simplejson.loads(output)
assert info['render'] == '<pre>\n!Hi\n//you//</pre>\n'
+ assert info['text'] == '!Hi\n//you//'
+
+def test_tiddler_json_render_skinny():
+ serializer = Serializer('json', environ={'tiddlyweb.query': {
+ 'render': [1], 'fat': [0]}, 'tiddlyweb.config': config})
+ tiddler = Tiddler('htmltest')
+ tiddler.bag = 'snoop'
+ tiddler.text = '!Hi\n//you//'
+
+ serializer.object = tiddler
+
+ output = serializer.to_string()
+ info = simplejson.loads(output)
+ assert info['render'] == '<pre>\n!Hi\n//you//</pre>\n'
+ pytest.raises(KeyError, "info['text']")
def test_tiddler_no_text():
serializer = Serializer('text')
View
22 tiddlyweb/serializations/json.py
@@ -42,9 +42,11 @@ def list_tiddlers(self, tiddlers):
The format is a list of dicts in
the form described by self._tiddler_dict.
"""
- fat = self.environ.get('tiddlyweb.query', {}).get('fat', [False])[0]
- render = self.environ.get('tiddlyweb.query', {}).get('render',
- [False])[0]
+ query = self.environ.get('tiddlyweb.query', {})
+
+ fat = query.get('fat', [False])[0]
+ render = query.get('render', [False])[0]
+
return simplejson.dumps([self._tiddler_dict(tiddler, fat, render) for
tiddler in tiddlers])
@@ -111,9 +113,12 @@ def tiddler_as(self, tiddler):
a tiddler, as described by _tiddler_dict
plus the text of the tiddler.
"""
- render = self.environ.get('tiddlyweb.query', {}).get('render',
- [False])[0]
- tiddler_dict = self._tiddler_dict(tiddler, fat=True, render=render)
+ query = self.environ.get('tiddlyweb.query', {})
+
+ fat = query.get('fat', [True])[0]
+ render = query.get('render', [False])[0]
+
+ tiddler_dict = self._tiddler_dict(tiddler, fat=fat, render=render)
return simplejson.dumps(tiddler_dict)
def as_tiddler(self, tiddler, input_string):
@@ -158,9 +163,8 @@ def _tiddler_dict(self, tiddler, fat=False, render=False):
wanted_info['text'] = b64encode(tiddler.text)
else:
wanted_info['text'] = tiddler.text
- if render and renderable(tiddler, self.environ):
- wanted_info['render'] = render_wikitext(tiddler,
- self.environ)
+ if render and renderable(tiddler, self.environ):
+ wanted_info['render'] = render_wikitext(tiddler, self.environ)
return wanted_info
def _tiddler_permissions(self, tiddler):
Please sign in to comment.
Something went wrong with that request. Please try again.