def test_modify_apply_to(self): source_id = fixtures.random_string() data = { 'identificatie': source_id, '_hash': fixtures.random_string(), 'modifications': [{ 'key': 'identificatie', 'new_value': 'new identificatie', 'old_value': 'old identificatie', }] } event = import_events.MODIFY.create_event(source_id, source_id, data) entity = fixtures.get_entity_fixture({ 'identificatie': 'old identificatie', }) gob_event = import_events.MODIFY(event['data'], fixtures.get_metadata_fixture()) gob_event._extract_modifications = MagicMock( return_value={'identificatie': 'new identificatie'}) gob_event.apply_to(entity) self.assertEqual(entity.identificatie, 'new identificatie')
def test_GobEvent(self): event = fixtures.get_event_fixture() metadata = fixtures.get_metadata_fixture() gob_event = GobEvent(event, metadata) self.assertIsInstance(gob_event, events._get_event(event['event'])) self.assertEqual(event['data'], gob_event._data) self.assertEqual(metadata, gob_event._metadata)
def test_MessageMetaData(self): # Test creation of MessageMetaData metadata = fixtures.get_metadata_fixture() header = metadata.as_header keys = [ 'source', 'timestamp', 'entity', 'version', 'process_id', 'model', 'application' ] for key in keys: self.assertIn(key, header)
def test_ImportMessage(self): metadata = fixtures.get_metadata_fixture() header = metadata.as_header summary = 'summary' contents = 'contents' msg = ImportMessage.create_import_message(header, summary, contents) import_message = ImportMessage(msg) self.assertIsInstance(import_message.metadata, MessageMetaData) self.assertEqual(import_message.summary, 'summary') self.assertEqual(import_message.contents, 'contents')
def test_add_apply_to(self): source_id = fixtures.random_string() event = import_events.ADD.create_event(source_id, source_id, {'identificatie': source_id}) metadata = fixtures.get_metadata_fixture() entity = fixtures.get_entity_fixture(event['data']) gob_event = import_events.ADD(event['data'], metadata) gob_event.apply_to(entity) # Assert entity has the attribute with the value self.assertEqual(entity.identificatie, source_id)
def test_add_apply_to(self): tid = fixtures.random_string() event = import_events.ADD.create_event(tid, {'identificatie': tid}, '0.9') self.assertEqual(event['version'], '0.9') metadata = fixtures.get_metadata_fixture() entity = fixtures.get_entity_fixture(event['data']) gob_event = import_events.ADD("tid", event['data'], metadata) gob_event.apply_to(entity) # Assert entity has the attribute with the value self.assertEqual(entity.identificatie, tid)
def test_modify_extract_modifications(self): modifications = [{ 'key': 'a', 'new_value': 'new a', 'old_value': 'old a', }, { 'key': 'b', 'new_value': 'new b', 'old_value': 'old b', }] gob_event = import_events.MODIFY({}, fixtures.get_metadata_fixture()) self.assertEqual({ 'a': 'new a', 'b': 'new b' }, gob_event._extract_modifications({}, modifications))