def test_constructing_policy(self, policy):
     """Test that all attrs and strategies are actualy put into the policy"""
     for attr in SomePolicy.SERIALIZED_ATTRS:
         assert getattr(policy, attr) == self.policy_definition[attr]
     for role in SomePolicy.STRATEGY_CHOICES:
         strategy_name = get_func_name(getattr(policy, role))
         assert strategy_name == self.policy_definition[role]
 def to_json(self):
     """
     'Manual' serializer method which encodes strategy method *names*
     (normally, functions aren't serializable).
     """
     # names of all strategy functions under strategy role keys
     d = dict((role, get_func_name(getattr(self, role)))
              for role in self.STRATEGY_CHOICES)
     # additional attributes to serialize
     d.update((key, getattr(self, key)) for key in self.SERIALIZED_ATTRS)
     # __type__ name for jsonweb object_hook
     d['__type__'] = type(self).__name__
     return d
Пример #3
0
 def to_json(self):
     """
     'Manual' serializer method which encodes strategy method *names*
     (normally, functions aren't serializable).
     """
     # names of all strategy functions under strategy role keys
     d = dict(
         (role, get_func_name(getattr(self, role)))
         for role in self.STRATEGY_CHOICES
     )
     # additional attributes to serialize
     d.update(
         (key, getattr(self, key))
         for key in self.SERIALIZED_ATTRS
     )
     # __type__ name for jsonweb object_hook
     d['__type__'] = type(self).__name__
     return d