def test_rule_variable_decorator_passes_context_if_supported(self): """ Make sure that the expected attributes are attached to a function by the variable decorators. """ def some_test_function_supporting_context(self, context): self.assertNotNone(context) def some_test_function_not_supporting_context(self): pass wrapper_true = rule_variable(StringType, 'Foo Name', options=['op1', 'op2'], context_options=[0]) func = wrapper_true(some_test_function_supporting_context) self.assertEqual(func.context_options, [0]) wrapper_false = rule_variable(StringType, 'Foo Name', options=['op1', 'op2'], context_options=None) func = wrapper_false(some_test_function_not_supporting_context) self.assertIsNone(func.context_options)
def test_rule_variable_decorator_internals(self): """ Make sure that the expected attributes are attached to a function by the variable decorators. """ def some_test_function(self): pass wrapper = rule_variable(StringType, 'Foo Name', options=['op1', 'op2']) func = wrapper(some_test_function) self.assertTrue(func.is_rule_variable) self.assertEqual(func.label, 'Foo Name') self.assertEqual(func.field_type, StringType) self.assertEqual(func.options, ['op1', 'op2'])
def test_rule_variable_decorator_internals(self): """ Make sure that the expected attributes are attached to a function by the variable decorators. """ def some_test_function(self, param1): pass params = [{'field_type': FIELD_NUMERIC, 'name': 'param1', 'label': 'Param1'}] wrapper = rule_variable(StringType, 'Foo Name', options=['op1', 'op2'], params=params) func = wrapper(some_test_function) self.assertTrue(func.is_rule_variable) self.assertEqual(func.label, 'Foo Name') self.assertEqual(func.field_type, StringType) self.assertEqual(func.options, ['op1', 'op2']) self.assertEqual(func.params, params)