def test_get_and_set_cleaned_data(self): cleaned_data = { catalog_forms.WF_MANAGEMENT_NAME: { 'application_name': 'foobar' } } engine_factory = factory.YaqlFactory() engine = engine_factory.create() expr = engine('$') service = services.Service(cleaned_data={}, version=semantic_version.Version('2.3.0'), fqn='io.murano.Test', application=self.application) service.set_data(cleaned_data) result = service.get_data(catalog_forms.WF_MANAGEMENT_NAME, expr) expected = {'workflowManagement': {'application_name': 'foobar'}} self.assertEqual(expected, result) # Test whether passing data to get_data works. service.set_data({}) cleaned_data = cleaned_data[catalog_forms.WF_MANAGEMENT_NAME] result = service.get_data(catalog_forms.WF_MANAGEMENT_NAME, expr, data=cleaned_data) self.assertEqual(expected, result)
def _create_engine(runtime_version): engine_factory = factory.YaqlFactory() _add_operators(engine_factory=engine_factory) options = (ENGINE_10_OPTIONS if runtime_version <= constants.RUNTIME_VERSION_1_1 else ENGINE_12_OPTIONS) return engine_factory.create(options=options)
def create_engine(self): func = TestCase._default_engine if func is None: engine_factory = factory.YaqlFactory(allow_delegates=True) TestCase._default_engine = func = engine_factory.create( options=self.engine_options) return func
def _create_engine(runtime_version): engine_factory = factory.YaqlFactory() engine_factory.insert_operator( '.', True, ':', factory.OperatorType.BINARY_LEFT_ASSOCIATIVE, True) options = (ENGINE_10_OPTIONS if runtime_version < constants.RUNTIME_VERSION_2_0 else ENGINE_20_OPTIONS) return engine_factory.create(options=options)
def test_high_precedence_operator_insertion(self): # Test that insertion of high precedence operator doesn't # make turn ($.a)[0] into $.(a[0]) engine_factory = factory.YaqlFactory(allow_delegates=True) engine_factory.insert_operator( None, True, ':', factory.OperatorType.BINARY_LEFT_ASSOCIATIVE, True) engine = engine_factory.create() data = {'a': [1]} expr = engine('$.a[0]') self.assertEqual(1, expr.evaluate(context=self.context, data=data))
# (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from st2mistral.tests.unit import test_function_base as base from yaql.language import factory YAQL_ENGINE = factory.YaqlFactory().create() class JinjaVersionTestCase(base.JinjaFunctionTestCase): def test_version_compare(self): template = '{{ version_compare(_.version, "0.10.0") }}' result = self.eval_expression(template, {'version': '0.9.0'}) self.assertEqual(result, '-1') template = '{{ version_compare(_.version, "0.10.0") }}' result = self.eval_expression(template, {'version': '0.10.1'}) self.assertEqual(result, '1') template = '{{ version_compare(_.version, "0.10.0") }}' result = self.eval_expression(template, {'version': '0.10.0'})
def create_yaql_engine_class(keyword_operator, allow_delegates, engine_options): return factory.YaqlFactory( keyword_operator=keyword_operator, allow_delegates=allow_delegates).create(options=engine_options)