def test_should_append_answer_when_using_method_then(self): stub_configuration = StubConfiguration("any_command", ["any_arg1", "any_arg2"], "any_stdin") stub_configuration.then(Answer("Hello world!", "Hello error", 99)) actual_count_of_answers = len(stub_configuration.answers) self.assertEqual(1, actual_count_of_answers) actual_answer = stub_configuration.next_answer() self.assertEqual("Hello world!", actual_answer.stdout) self.assertEqual("Hello error", actual_answer.stderr) self.assertEqual(99, actual_answer.return_code)
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_append_answer_when_using_method_then(self): stub_configuration = StubConfiguration('any_command', ['any_arg1', 'any_arg2'], 'any_stdin') stub_configuration.then(Answer('Hello world!', 'Hello error', 99)) actual_count_of_answers = len(stub_configuration.answers) self.assertEqual(1, actual_count_of_answers) actual_answer = stub_configuration.next_answer() self.assertEqual('Hello world!', actual_answer.stdout) self.assertEqual('Hello error', actual_answer.stderr) self.assertEqual(99, actual_answer.return_code)
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_return_self_when_using_method_then(self): stub_configuration = StubConfiguration("any_command", ["any_arg1", "any_arg2"], "any_stdin") answer = Answer("Hello world!", "Hello error", 99) actual_result = stub_configuration.then(answer) self.assertTrue(actual_result is not None, "Not returning anything!") self.assertEqual(stub_configuration, actual_result)
def test_should_return_self_when_using_method_then(self): stub_configuration = StubConfiguration('any_command', ['any_arg1', 'any_arg2'], 'any_stdin') answer = Answer('Hello world!', 'Hello error', 99) actual_result = stub_configuration.then(answer) self.assertTrue(actual_result is not None, 'Not returning anything!') self.assertEqual(stub_configuration, actual_result)
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)