Esempio n. 1
0
def deserialize_stub_configurations(filename):
    """
        loads the given json file and returns a list of stub configurations.
    """
    stub_configurations = _load_json_file(filename)
    return list(
        map(lambda e: StubConfiguration.from_dictionary(e),
            stub_configurations))
Esempio n. 2
0
    def test_should_convert_dictionary_to_object(self):
        values = {
            'command_input': {
                'command': 'any_command',
                'arguments': ['any_arg1', 'any_arg2', 'any_argument3'],
                'stdin': 'any_stdin'
            },
            'current_answer':
            0,
            'answers': [{
                'stdout': 'Hello world.',
                'stderr': 'Hello error!',
                'return_code': 18,
                'milliseconds_to_wait': None
            }, {
                'stdout': 'Spam eggs.',
                'stderr': 'Error!',
                'return_code': 21,
                'milliseconds_to_wait': None
            }]
        }

        actual_stub_configuration = StubConfiguration.from_dictionary(values)

        self.assertEqual(
            CommandInput('any_command',
                         ['any_arg1', 'any_arg2', 'any_argument3'],
                         'any_stdin'), actual_stub_configuration.command_input)
        self.assertEqual(0, actual_stub_configuration.current_answer)

        actual_count_of_answers = len(actual_stub_configuration.answers)

        self.assertEqual(2, actual_count_of_answers)

        actual_first_answer = actual_stub_configuration.next_answer()

        self.assertEqual('Hello world.', actual_first_answer.stdout)
        self.assertEqual('Hello error!', actual_first_answer.stderr)
        self.assertEqual(18, actual_first_answer.return_code)

        actual_second_answer = actual_stub_configuration.next_answer()

        self.assertEqual('Spam eggs.', actual_second_answer.stdout)
        self.assertEqual('Error!', actual_second_answer.stderr)
        self.assertEqual(21, actual_second_answer.return_code)
Esempio n. 3
0
    def test_should_convert_dictionary_to_object(self):
        values = {
            "command_input": {
                "command": "any_command",
                "arguments": ["any_arg1", "any_arg2", "any_argument3"],
                "stdin": "any_stdin",
            },
            "current_answer": 0,
            "answers": [
                {"stdout": "Hello world.", "stderr": "Hello error!", "return_code": 18, "milliseconds_to_wait": None},
                {"stdout": "Spam eggs.", "stderr": "Error!", "return_code": 21, "milliseconds_to_wait": None},
            ],
        }

        actual_stub_configuration = StubConfiguration.from_dictionary(values)

        self.assertEqual(
            CommandInput("any_command", ["any_arg1", "any_arg2", "any_argument3"], "any_stdin"),
            actual_stub_configuration.command_input,
        )
        self.assertEqual(0, actual_stub_configuration.current_answer)

        actual_count_of_answers = len(actual_stub_configuration.answers)

        self.assertEqual(2, actual_count_of_answers)

        actual_first_answer = actual_stub_configuration.next_answer()

        self.assertEqual("Hello world.", actual_first_answer.stdout)
        self.assertEqual("Hello error!", actual_first_answer.stderr)
        self.assertEqual(18, actual_first_answer.return_code)

        actual_second_answer = actual_stub_configuration.next_answer()

        self.assertEqual("Spam eggs.", actual_second_answer.stdout)
        self.assertEqual("Error!", actual_second_answer.stderr)
        self.assertEqual(21, actual_second_answer.return_code)
Esempio n. 4
0
def deserialize_stub_configurations (filename):
    """
        loads the given json file and returns a list of stub configurations.
    """
    stub_configurations = _load_json_file(filename)
    return list(map(lambda e: StubConfiguration.from_dictionary(e), stub_configurations))