66 lines
1.5 KiB
Python
66 lines
1.5 KiB
Python
import sys
|
|
import shutil
|
|
import tempfile
|
|
|
|
from quixote import cleanup
|
|
from wcs import publisher
|
|
from wcs.qommon.http_request import HTTPRequest
|
|
from wcs import fields
|
|
|
|
def setup_module(module):
|
|
cleanup()
|
|
|
|
global pub
|
|
|
|
publisher.WcsPublisher.APP_DIR = tempfile.mkdtemp()
|
|
pub = publisher.WcsPublisher.create_publisher()
|
|
|
|
req = HTTPRequest(None, {})
|
|
pub._set_request(req)
|
|
|
|
user = pub.user_class(name='user')
|
|
user.id = 'user'
|
|
user.email = 'test@example.net'
|
|
|
|
req._user = user
|
|
|
|
|
|
def teardown_module(module):
|
|
shutil.rmtree(pub.APP_DIR)
|
|
|
|
|
|
def test_prefill_string():
|
|
field = fields.Field()
|
|
field.prefill = {'type': 'string', 'value': 'test'}
|
|
|
|
assert field.get_prefill_value() == 'test'
|
|
|
|
|
|
def test_prefill_user():
|
|
field = fields.Field()
|
|
field.prefill = {'type': 'user', 'value': 'email'}
|
|
|
|
assert field.get_prefill_value() == 'test@example.net'
|
|
|
|
|
|
def test_prefill_formula():
|
|
field = fields.Field()
|
|
field.prefill = {'type': 'formula', 'value': 'str(2+5)'}
|
|
|
|
assert field.get_prefill_value() == '7'
|
|
|
|
|
|
def test_prefill_formula_with_error():
|
|
field = fields.Field()
|
|
field.prefill = {'type': 'formula', 'value': 'foobar'}
|
|
|
|
assert field.get_prefill_value() is None
|
|
|
|
|
|
def test_prefill_formula_substition_variable():
|
|
pub.substitutions.get_context_variables = lambda: {'test': 'value'}
|
|
field = fields.Field()
|
|
field.prefill = {'type': 'formula', 'value': 'test'}
|
|
|
|
assert field.get_prefill_value() == 'value'
|