def test_should_load_configured_stubs(self, mock_deserialize, mock_logging_info, mock_logging_error, mock_exit, mock_serialize, mock_unlock): command_input = CommandInput( 'command', ['-arg1', '-arg2', '-arg3'], 'stdin') commandstub.dispatch(command_input) self.assertEqual( call('shtub/stub-configurations'), mock_deserialize.call_args)
def test_should_exit_with_error_code_255_when_execution_not_in_stub_configuration( self, mock_deserialize, mock_logging_info, mock_logging_error, mock_exit, mock_serialize, mock_unlock): command_input = CommandInput( 'command', ['-arg1', '-arg2', '-arg3'], 'stdin') commandstub.dispatch(command_input) self.assertEqual(call(255), mock_exit.call_args)
def test_should_send_answer_when_execution_fulfills_stub_configurations(self, mock_deserialize, mock_logging_info, mock_answer, mock_record, mock_serialize, mock_unlock): answer = Answer('Hello world', 'Hello error', 15) stub_configuration = StubConfiguration( 'command', ['-arg1', '-arg2', '-arg3'], 'stdin') stub_configuration.then(answer) mock_deserialize.return_value = [stub_configuration] command_input = CommandInput( 'command', ['-arg1', '-arg2', '-arg3'], 'stdin') commandstub.dispatch(command_input) self.assertEqual(call(answer), mock_answer.call_args)
def test_should_serialize_stubs_configuration_before_sending_answer(self, mock_deserialize, mock_logging_info, mock_answer, mock_record, mock_serialize, mock_unlock): answer = Answer('Hello world', 'Hello error', 15) stub_configuration = StubConfiguration( 'command', ['-arg1', '-arg2', '-arg3'], 'stdin') stub_configuration.then(answer) stub_configurations = [stub_configuration] mock_deserialize.return_value = stub_configurations command_input = CommandInput( 'command', ['-arg1', '-arg2', '-arg3'], 'stdin') commandstub.dispatch(command_input) self.assertEqual( call('shtub/stub-configurations', stub_configurations), mock_serialize.call_args)
def test_should_wait_when_answer_fulfills_stub_configurations_and_needs_waiting(self, mock_deserialize, mock_logging_info, mock_answer, mock_record, mock_sleep, mock_serialize, mock_unlock): answer = Answer( 'Hello world', 'Hello error', 15, milliseconds_to_wait=5) stub_configuration = StubConfiguration( 'command', ['-arg1', '-arg2', '-arg3'], 'stdin') stub_configuration.then(answer) mock_deserialize.return_value = [stub_configuration] command_input = CommandInput( 'command', ['-arg1', '-arg2', '-arg3'], 'stdin') commandstub.dispatch(command_input) self.assertEqual(call(answer), mock_answer.call_args) self.assertEqual(call(5 / 1000), mock_sleep.call_args)
def test_should_mark_execution_as_expected_and_record_call_when_execution_fulfills_stub_configuration( self, mock_deserialize, mock_logging_info, mock_answer, mock_record, mock_execution_class, mock_serialize, mock_unlock): mock_execution = Mock(Execution) mock_execution_class.return_value = mock_execution answer = Answer('Hello world', 'Hello error', 15) stub_configuration = StubConfiguration( 'command', ['-arg1', '-arg2', '-arg3'], 'stdin') stub_configuration.then(answer) mock_deserialize.return_value = [stub_configuration] command_input = CommandInput( 'command', ['-arg1', '-arg2', '-arg3'], 'stdin') commandstub.dispatch(command_input) self.assertEqual( call('command', ['-arg1', '-arg2', '-arg3'], 'stdin'), mock_execution_class.call_args) self.assertEqual(call(), mock_execution.mark_as_expected.call_args) self.assertEqual(call(mock_execution), mock_record.call_args)