Adds a test for string manipulation

This commit is contained in:
Aaron Louie 2020-08-21 13:46:10 -04:00
parent 4dc98a6b6b
commit 182e375fdc
2 changed files with 14 additions and 2 deletions

View File

@ -72,7 +72,7 @@ def send_email(address):
def evaluate_python_expression(body):
"""Evaluate the given python expression, returning it's result. This is useful if the
"""Evaluate the given python expression, returning its result. This is useful if the
front end application needs to do real-time processing on task data. If for instance
there is a hide expression that is based on a previous value in the same form."""
try:

View File

@ -39,7 +39,7 @@ class TestStudyApi(BaseTest):
self.assertIsNotNone(scripts[0]['description'])
def test_eval_hide_expression(self):
"""Assures we can use python to process a hide expression fron the front end"""
"""Assures we can use python to process a hide expression from the front end"""
rv = self.app.put('/v1.0/eval',
data='{"expression": "x.y==2", "data": {"x":{"y":2}}}', follow_redirects=True,
content_type='application/json',
@ -47,3 +47,15 @@ class TestStudyApi(BaseTest):
self.assert_success(rv)
response = json.loads(rv.get_data(as_text=True))
self.assertEqual(True, response['result'])
def test_eval_expression_with_strings(self):
"""Assures we can use python to process a value expression from the front end"""
rv = self.app.put('/v1.0/eval',
data='{"expression": "\'Hello, \' + user.first_name + \' \' + user.last_name + \'!!!\'", '
'"data": {"user":{"first_name": "Trillian", "last_name": "Astra"}}}',
follow_redirects=True,
content_type='application/json',
headers=self.logged_in_headers())
self.assert_success(rv)
response = json.loads(rv.get_data(as_text=True))
self.assertEqual('Hello, Trillian Astra!!!', response['result'])