def test_modified_is_false(self, mocked_get_now, mocked_prepare_revision, mocked_lot_revisions, mocked_logger, mocked_context_unpack): with mock.patch.object(self.lot, 'store', autospec=True) as mocked_store: with mock.patch.object(self.lot, 'revisions') as revisions_mock: self.lot.modified = False self.lot.dateModified = self.old_date mocked_context_unpack.side_effect = iter([ self.unpacked_context ]) mocked_get_now.side_effect = iter([ self.new_date ]) mocked_store.side_effect = iter([ None ]) mocked_lot_revisions.model_class.side_effect = iter([self.new_rev]) mocked_prepare_revision.side_effect = iter([self.rev_data]) assert store_lot(self.lot, self.patch, self.mocked_request) is True assert mocked_prepare_revision.call_count == 1 mocked_prepare_revision.assert_called_with( self.lot, self.patch, self.mocked_request.authenticated_userid ) assert mocked_get_now.call_count == 0 assert mocked_lot_revisions.model_class.call_count == 1 mocked_lot_revisions.model_class.assert_called_with(self.rev_data) assert revisions_mock.append.call_count == 1 revisions_mock.append.assert_called_with(self.new_rev) assert mocked_store.call_count == 1 mocked_store.assert_called_with(self.mocked_request.registry.db) assert mocked_logger.info.call_count == 1 mocked_logger.info.assert_called_with( 'Saved lot {lot_id}: dateModified {old_dateModified} -> {new_dateModified}'.format( lot_id=self.lot.id, old_dateModified=self.old_date.isoformat(), new_dateModified=self.old_date.isoformat()), extra=self.unpacked_context )
def test_model_validation_error(self, mocked_get_now, mocked_prepare_revision, mocked_lot_revisions, mocked_logger, mocked_context_unpack): with mock.patch.object(self.lot, 'store', autospec=True) as mocked_store: with mock.patch.object(self.lot, 'revisions') as revisions_mock: self.lot.dateModified = self.old_date mocked_get_now.side_effect = iter([self.new_date]) mocked_lot_revisions.model_class.side_effect = iter( [self.new_rev]) mocked_prepare_revision.side_effect = iter([self.rev_data]) error_key = 'error' error_message = 'Some error' mocked_store.side_effect = iter( [ModelValidationError({error_key: error_message})]) assert store_lot(self.lot, self.patch, self.mocked_request) is None mocked_prepare_revision.assert_called_with( self.lot, self.patch, self.mocked_request.authenticated_userid) assert mocked_get_now.call_count == 1 assert mocked_lot_revisions.model_class.call_count == 1 mocked_lot_revisions.model_class.assert_called_with( self.rev_data) assert revisions_mock.append.call_count == 1 revisions_mock.append.assert_called_with(self.new_rev) assert mocked_store.call_count == 1 mocked_store.assert_called_with( self.mocked_request.registry.db) assert self.mocked_request.errors.add.call_count == 1 assert self.mocked_request.errors.status == 422 self.mocked_request.errors.add.assert_called_with( 'body', error_key, error_message) assert mocked_logger.info.call_count == 0