def test_interpretation_01():
    """
    Action : Test mocking interpretation.
    Expected Results : No difference from normal application usage.
    Returns: N/A.
    """
    yaml_parser = LoadAndParseYaml()
    yaml_parser.data = {"services": [{"title": "Security Access", "id": "27"}]}
    assert yaml_parser.return_signal_by_title("27") == "Security Access"
示例#2
0
def fixture_loadandparse_yaml_instance(fixture_yaml_file):
    """
    Action : LoadAndParse class instance.
    Expected Correct LoadAndParse class instance returned.
    Returns: LoadAndParse class instance.
    """
    load_and_parser = LoadAndParseYaml()
    load_and_parser.data = fixture_yaml_file
    load_and_parser.title = None
    return load_and_parser
def test_open_file():
    """
    Action : Test mocking yaml file open.
    Expected Results : No difference from normal application usage.
    Returns: N/A.
    """
    with patch("builtins.open", mock_open(read_data=RAW_YAML_DATA)):
        yaml_parser = LoadAndParseYaml()
        yaml_parser.load_file("file/path")
        assert yaml_parser.data == PROCESSED_YAML_DATA
def test_load_file(fixture_yaml_file_path):
    """
    Action : Test the server correct file load.
    Expected Results : Test finished with status "Passed".
    Returns: N/A.
    """
    load_and_parser_yaml = LoadAndParseYaml()
    returned_data = load_and_parser_yaml.load_file(fixture_yaml_file_path)
    assert returned_data['services'][0]['title'] == 'ECU Reset'
    assert returned_data['services'][1]['id'] == '27'
    with pytest.raises(ParserErrorFileNotFoundError):
        load_and_parser_yaml.load_file('fixtures/wrong_file_path.yaml')
def test_file_load():
    """
    Action : Test mocking yaml file loading.
    Expected Results : No difference from normal application usage.
    Returns: N/A.
    """
    with patch(
            "builtins.open", mock_open(read_data=RAW_YAML_DATA))\
            as mock_file_object:
        with patch.object(
                yaml, "load", return_value=PROCESSED_YAML_DATA)\
                as mock_yaml_load:
            yaml_parser = LoadAndParseYaml()
            yaml_parser.load_file("path/to/yaml/file")
            mock_yaml_load.assert_called_with(mock_file_object.return_value,
                                              Loader=yaml.FullLoader)
            assert yaml_parser.data == PROCESSED_YAML_DATA
def test_return_service_01(fixture_yaml_file_path, fixture_yaml_file):
    """
    Action : Test the server correct service return.
    Expected Results : Test finished with status "Passed".
    Returns: N/A.
    """
    load_and_parser_yaml = LoadAndParseYaml()
    load_and_parser_yaml.load_file(fixture_yaml_file_path)
    returned_service = load_and_parser_yaml.return_signal_by_title(
        fixture_yaml_file['services'][0]['id'])
    assert returned_service == 'ECU Reset'
    returned_service = load_and_parser_yaml.return_signal_by_title(
        fixture_yaml_file['services'][1]['id'])
    assert returned_service == 'Security Access'
    returned_service = load_and_parser_yaml.return_signal_by_title('XXXXX')
    assert returned_service == 'Service not suported!'