Esempio n. 1
0
 def test_serialize_domain_event(self):
     datetime_now = datetime.datetime(2015, 9, 8, 16, 20, 50, 577429)
     datetime_now_tzaware = datetime.datetime(2015, 9, 8, 16, 20, 50, 577429, tzinfo=utc_timezone)
     date_now = datetime.date(2015, 9, 8)
     event1 = DomainEvent(a=1, b=2, c=datetime_now, d=datetime_now_tzaware, e=date_now, entity_version=0, entity_id='entity1', domain_event_id=3)
     stored_event = serialize_domain_event(event1, json_encoder_cls=ObjectJSONEncoder)
     self.assertEqual('DomainEvent::entity1', stored_event.stored_entity_id)
     self.assertEqual('eventsourcing.domain.model.events#DomainEvent', stored_event.event_topic)
     self.assertEqual('{"a":1,"b":2,"c":{"ISO8601_datetime":"2015-09-08T16:20:50.577429"},"d":{"ISO8601_datetime":"2015-09-08T16:20:50.577429+0000"},"domain_event_id":3,"e":{"ISO8601_date":"2015-09-08"},"entity_id":"entity1","entity_version":0}',
                      stored_event.event_attrs)
Esempio n. 2
0
    def test_serialize_domain_event_with_numpy_array(self):
        try:
            import numpy
        except ImportError:
            numpy = None

        if numpy is not None:
            event1 = DomainEvent(a=numpy.array([10.123456]), entity_version=0, entity_id='entity1', domain_event_id=3)

            stored_event = serialize_domain_event(event1, json_encoder_cls=ObjectJSONEncoder)
            self.assertEqual('eventsourcing.domain.model.events#DomainEvent', stored_event.event_topic)
            self.assertEqual('{"a":{"__ndarray__":"\\"\\\\u0093NUMPY\\\\u0001\\\\u0000F\\\\u0000{\'descr\': \'<f8\', \'fortran_order\': False, \'shape\': (1,), }            \\\\nm\\\\u00fd\\\\u00f4\\\\u009f5?$@\\""},"domain_event_id":3,"entity_id":"entity1","entity_version":0}',
                             stored_event.event_attrs)
        else:
            self.skipTest("Skipped test because numpy is not installed")