Merge branch 'dev' of github.com:sartography/cr-connect-workflow into dev

This commit is contained in:
Dan 2021-06-11 17:21:47 -04:00
commit 738a984dcd
4 changed files with 20 additions and 4 deletions

2
Pipfile.lock generated
View File

@ -957,7 +957,7 @@
},
"spiffworkflow": {
"git": "https://github.com/sartography/SpiffWorkflow.git",
"ref": "ce939de158246e9d10e7e154c92230669354bc64"
"ref": "da79e8b0f66df1cb8372435bdff3b294e5f3a336"
},
"sqlalchemy": {
"hashes": [

View File

@ -1,3 +1,4 @@
import hashlib
import io
import json
@ -78,11 +79,13 @@ def send_email(subject, address, body, data=None):
def evaluate_python_expression(body):
"""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."""
there is a hide expression that is based on a previous value in the same form.
The response includes both the result, and a hash of the original query, subsequent calls
of the same hash are unnecessary. """
try:
script_engine = CustomBpmnScriptEngine()
result = script_engine.eval(body['expression'], body['data'])
return {"result": result}
return {"result": result, "expression": body['expression'], "data": body['data']}
except Exception as e:
raise ApiError("expression_error", f"Failed to evaluate the expression '%s'. %s" %
(body['expression'], str(e)),

View File

@ -288,7 +288,6 @@ class WorkflowService(object):
data_store = DataStoreModel(file_id=file_id, key=field.id, value=data[field.id])
db.session.add(data_store)
@staticmethod
def evaluate_property(property_name, field, task):
expression = field.get_property(property_name)

View File

@ -48,6 +48,20 @@ class TestStudyApi(BaseTest):
response = json.loads(rv.get_data(as_text=True))
self.assertEqual(True, response['result'])
def test_eval_returns_query(self):
"""Assures that along with the result, we get the original data and expression.
This can be useful if the calling client is caching results and needs to hash the expression and data
when it gets returned."""
data = '{"expression": "x.y==2", "data": {"x":{"y":2}}}'
rv = self.app.put('/v1.0/eval',
data=data, 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("x.y==2", response['expression'])
self.assertEqual({'x': {'y': 2}}, response['data'])
def test_eval_expression_with_strings(self):
"""Assures we can use python to process a value expression from the front end"""