def test_with_wrong_lotType(self, mocked_handler, mocked_update_logging): data = {'lotType': 'wrongLotType'} self.mocked_model.side_effect = iter(['model']) mocked_handler.side_effect = iter([DummyException]) with self.assertRaises(DummyException): lot_from_data(self.mocked_request, data) assert mocked_update_logging.call_count == 0 assert self.mocked_model.call_count == 0 assert mocked_handler.call_count == 1 mocked_handler.assert_called_with(self.mocked_request) assert self.mocked_request.errors.add.call_count == 1 self.mocked_request.errors.add.assert_called_with('body', 'lotType', 'Not implemented') assert self.mocked_request.errors.status == 415
def test_with_create_false(self, mocked_handler, mocked_update_logging): data = {'lotType': 'someLotType'} self.mocked_model.side_effect = iter(['model']) returned_value = lot_from_data(self.mocked_request, data, create=False) assert returned_value == self.mocked_model assert mocked_update_logging.call_count == 1 mocked_update_logging.assert_called_with(self.mocked_request, {'lot_type': data['lotType']}) assert self.mocked_model.call_count == 0 assert mocked_handler.call_count == 0 assert self.mocked_request.errors.add.call_count == 0 assert self.mocked_request.errors.status is None
def test_with_wrong_lotType_and_raise_false(self, mocked_handler, mocked_update_logging): data = {'lotType': 'wrongLotType'} self.mocked_model.side_effect = iter(['model']) mocked_handler.side_effect = iter([DummyException]) returned_value = lot_from_data(self.mocked_request, data, raise_error=False) assert returned_value is None assert mocked_update_logging.call_count == 1 mocked_update_logging.assert_called_with(self.mocked_request, {'lot_type': data['lotType']}) assert self.mocked_model.call_count == 0 assert mocked_handler.call_count == 0 assert self.mocked_request.errors.add.call_count == 0 assert self.mocked_request.errors.status is None