wcs/tests/test_texts.py

55 lines
1.8 KiB
Python

import sys
import shutil
from quixote import cleanup
from wcs.qommon.http_request import HTTPRequest
from wcs.qommon.admin.texts import TextsDirectory
from utilities import create_temporary_pub, MockSubstitutionVariables
def setup_module(module):
cleanup()
global pub
pub = create_temporary_pub()
req = HTTPRequest(None, {})
pub._set_request(req)
# create an user otherwise the backoffice is open and a button to edit the
# text gets automatically added.
user = pub.user_class(name='foo')
user.store()
def teardown_module(module):
shutil.rmtree(pub.APP_DIR)
def test_get_html_text_unset():
TextsDirectory.register('foo', 'Foo')
assert TextsDirectory.get_html_text('foo') == ''
def test_get_html_text_default():
TextsDirectory.register('foo2', 'Foo', default='Foo...')
assert TextsDirectory.get_html_text('foo2') == 'Foo...'
def test_get_html_text_set():
TextsDirectory.register('foo3', 'Foo', default='Foo...')
pub.cfg['texts'] = {'text-foo3': None}
pub.write_cfg()
assert TextsDirectory.get_html_text('foo3') == 'Foo...'
pub.cfg['texts'] = {'text-foo3': 'Bar...'}
pub.write_cfg()
assert TextsDirectory.get_html_text('foo3') == '<p>Bar...</p>'
pub.cfg['texts'] = {'text-foo3': '<div>Bar...</div>'}
pub.write_cfg()
assert TextsDirectory.get_html_text('foo3') == '<div>Bar...</div>'
def test_get_html_subst():
# test for variable substitution
TextsDirectory.register('foo4', 'Foo', default='Foo...')
pub.substitutions.feed(MockSubstitutionVariables())
pub.cfg['texts'] = {'text-foo4': '[bar]'}
pub.write_cfg()
assert TextsDirectory.get_html_text('foo4') == '<p>Foobar</p>'
pub.cfg['texts'] = {'text-foo4': '[foo]'}
pub.write_cfg()
assert TextsDirectory.get_html_text('foo4') == '<p>1 &lt; 3</p>'