示例#1
0
 def _filter_list_of_objects(self, post_condition: PostCondition,
                             operation_context: OperationContext):
     result = []
     for item in operation_context.get_output():
         operation_context.set_input_parameter('item', item)
         if not post_condition.condition.interpret(operation_context):
             result.append(item)
     operation_context.set_output(result)
示例#2
0
 def test_apply_post_conditions_filter_list_of_objects(self):
     registry = Registry(MockLocalLoader(), RemoteBusinessContextLoader(MockRemoteLoader()))
     weaver = Weaver(registry)
     operation_context = OperationContext('product.listAll')
     operation_context.set_output([Product('Toothpaste', 123.45, False), Product('Toothbrush', 123.45, True)])
     weaver.apply_post_conditions(operation_context)
     self.assertEqual(1, len(operation_context.get_output()))
     self.assertEqual('Toothpaste', operation_context.get_output()[0].name)
     self.assertEqual(None, operation_context.get_output()[0].buying_price)
示例#3
0
 def test_apply_post_conditions_filter_object_field(self):
     registry = Registry(MockLocalLoader(), RemoteBusinessContextLoader(MockRemoteLoader()))
     weaver = Weaver(registry)
     operation_context = OperationContext('user.create')
     operation_context.set_output(User('John Doe', '*****@*****.**'))
     weaver.apply_post_conditions(operation_context)
     self.assertEqual('John Doe', operation_context.get_output().name)
     self.assertEqual(None, operation_context.get_output().email)
示例#4
0
 def _filter_list_of_objects_field(self, post_condition: PostCondition,
                                   operation_context: OperationContext):
     for item in operation_context.get_output():
         operation_context.set_input_parameter('item', item)
         if post_condition.condition.interpret(operation_context):
             setattr(item, post_condition.reference_name, None)
示例#5
0
 def _filter_object_field(self, post_condition: PostCondition,
                          operation_context: OperationContext):
     if post_condition.condition.interpret(operation_context):
         output = operation_context.get_output()
         if output is not None:
             setattr(output, post_condition.reference_name, None)
示例#6
0
 def interpret(self, context: OperationContext):
     args = []
     for arg in self.arguments:
         args.append(arg.interpret(context))
     return context.get_function(self.method_name)(*args)
示例#7
0
 def interpret(self, context: OperationContext):
     return context.get_input_parameter(self.name)
示例#8
0
 def interpret(self, context: OperationContext):
     return getattr(context.get_input_parameter(self.object_name),
                    self.property_name)
示例#9
0
 def test_evaluate_preconditions(self):
     registry = Registry(MockLocalLoader(), RemoteBusinessContextLoader(MockRemoteLoader()))
     weaver = Weaver(registry)
     operation_context = OperationContext('user.create')
     self.assertRaises(BusinessRulesCheckFailed, weaver.evaluate_preconditions, operation_context)