def serialize(self, event, aggregate_id): class_name = event.__class__.__name__ event_data = {} event_data["event"] = events.serialize(event) event_data["__class_name__"] = class_name event_data["__aggregate_id__"] = aggregate_id return event_data
def test_serializer(self): info = EventInfo.create_new() event = SignupNewUserAccepted(info, "A", "B") serialized_data = serialize(event) self.assertEqual("A", serialized_data["userid"]) self.assertEqual("B", serialized_data["username"]) self.assertEqual(dict, type(serialized_data["event_info"])) self.assertTrue(serialized_data["event_info"].has_key("event_date"))
def serialize_event(event): data = serialize(event) data["name"] = pascalcase_to_dash(event.__class__.__name__) json_str = json.dumps(data, default=date_handler) return json_str