class TestModelBuilder(unittest.TestCase): def setUp(self): self.model_class = Mock() self.document = Mock(Document) self.builder = ModelBuilder(self.document, self.model_class) def test_when_creating_then_validates_mapping(self): mapping = {'foo': 'bar'} self.builder.create(mapping) self.document.validate.assert_called_once_with(mapping) def test_when_creating_then_passes_mapping_to_class(self): mapping = {'foo': 'bar'} result = self.builder.create(mapping) assert_that(result, equal_to(self.model_class.return_value)) self.model_class.assert_called_once_with(foo='bar') def test_when_updating_then_validates_mapping(self): mapping = {'foo': 'bar'} model = Mock() self.builder.update(model, mapping) self.document.validate.assert_called_once_with(mapping) def test_when_updating_then_applies_mapping_to_model(self): mapping = {'foo': 'bar'} model = Mock() self.builder.update(model, mapping) assert_that(model.foo, equal_to('bar'))
def setUp(self): self.model_class = Mock() self.document = Mock(Document) self.builder = ModelBuilder(self.document, self.model_class)