def test_migrate_stream_field_page(self): """ Test that the migrate_stream_field function correctly gets old data, calls the mapper function, and stores new data based on the mapper results. """ # Mock the field mapper migration function. We'll inspect the # call to this and ensure the return value makes it to # set_stream_data. mapper = mock.Mock(return_value='new text') migrate_stream_field(self.page, 'body', 'text', mapper) mapper.assert_called_with(self.page, 'some text') self.assertEqual(self.page.body.stream_data[0]['value'], 'new text')
def test_migrate_stream_field_not_migrated(self, mock_set_stream_data): """ Test that the migrate_stream_field function correctly ignores a field that does not have the correct type and shouldn't be migrated. """ mapper = mock.Mock() migrate_stream_field(self.page, 'body', 'other_type', mapper) # The mapper should not be called mapper.assert_not_called() # set_stream_data should not be called mock_set_stream_data.assert_not_called()