def test_default_datetime_extension_serialization(self):
     SIGNAL = create_simple_signal({"birthday": datetime})
     bridge = AvroAttrsBridge(SIGNAL)
     birthday = datetime(year=1989, month=9, day=6)
     test_data = {"birthday": birthday}
     data_dict = bridge.to_dict(test_data)
     assert data_dict == {"birthday": birthday.isoformat()}
 def test_default_coursekey_extension_serialization(self):
     SIGNAL = create_simple_signal({"course": CourseKey})
     bridge = AvroAttrsBridge(SIGNAL)
     course_key = CourseKey.from_string("course-v1:edX+DemoX.1+2014")
     test_data = {"course": course_key}
     data_dict = bridge.to_dict(test_data)
     assert data_dict == {"course": str(course_key)}
    def test_convert_event_data_to_dict(self):
        """
        Tests that an event with complex attrs objects can be converted to dict and back
        """

        SIGNAL = create_simple_signal({"test_data": TestData})
        bridge = AvroAttrsBridge(SIGNAL)
        # A test record that we can try to serialize to avro.
        test_data = TestData(
            "foo",
            "bar.course",
            SubTestData0("a.sub.name", "a.nother.course"),
            SubTestData1("b.uber.sub.name", "b.uber.another.course"),
        )

        data_dict = bridge.to_dict({"test_data": test_data})
        expected_dict = {
            "test_data": {
                "course_id": "bar.course",
                "sub_name": "foo",
                "sub_test_0": {
                    "course_id": "a.nother.course",
                    "sub_name": "a.sub.name"
                },
                "sub_test_1": {
                    "course_id": "b.uber.another.course",
                    "sub_name": "b.uber.sub.name",
                },
            }
        }
        self.assertDictEqual(data_dict, expected_dict)