diff --git a/VERSION b/VERSION index b4f4dfe..7bbe6b6 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.0.0-rc6 +1.0.0-rc7 diff --git a/kim/mapper.py b/kim/mapper.py index 470eff2..3102090 100644 --- a/kim/mapper.py +++ b/kim/mapper.py @@ -733,6 +733,7 @@ def __init__(self, mapper, **mapper_params): self.mapper = mapper self.mapper_params = mapper_params + self._changes = [] def get_mapper(self, data=None, obj=None): """return a new instance of the provided mapper. @@ -776,6 +777,14 @@ def marshal(self, data, role='__default__'): output = [] # TODO should this be user defined? for datum in data: - output.append(self.get_mapper(data=datum).marshal(role=role)) + mapper = self.get_mapper(data=datum) + output.append(mapper.marshal(role=role)) + self._changes.append(mapper.get_changes()) return output + + def get_changes(self): + """return the list of changes from each mapper + """ + + return self._changes diff --git a/tests/test_mapper.py b/tests/test_mapper.py index ed3e0a8..c9a8fff 100644 --- a/tests/test_mapper.py +++ b/tests/test_mapper.py @@ -527,6 +527,30 @@ class MapperBase(Mapper): assert (res2.name, res2.id) == ('bob', 2) +def test_mapper_marshal_many_mapper_changes(): + + class MapperBase(Mapper): + + __type__ = TestType + + id = Integer() + name = String() + + data = [{'name': 'mike', 'id': 1}, {'name': 'bob', 'id': 2}] + + mapper = MapperBase.many() + mapper.marshal(data) + + assert mapper.get_changes() == [ + { + 'id': {'old_value': None, 'new_value': 1}, + 'name': {'old_value': None, 'new_value': 'mike'}}, + { + 'id': {'old_value': None, 'new_value': 2}, + 'name': {'old_value': None, 'new_value': 'bob'}}, + ] + + def test_mapper_marshal_many_with_role(): class MapperBase(Mapper):