def test_interpretation_01():
    """
    Action : Test mocking interpretation.
    Expected Results : No difference from normal application usage.
    Returns: N/A.
    """
    json_parser = LoadAndParseJson()
    json_parser.data = {"services": [{"title": "Security Access", "id": "27"}]}
    assert json_parser.return_signal_by_title("27") == "Security Access"
Beispiel #2
0
def fixture_loadandparse_json_instance(fixture_json_file):
    """
    Action : LoadAndParse class instance.
    Expected Correct LoadAndParse class instance returned.
    Returns: LoadAndParse class instance.
    """
    load_and_parser = LoadAndParseJson()
    load_and_parser.data = fixture_json_file
    load_and_parser.title = None
    return load_and_parser
def test_open_file():
    """
    Action : Test mocking json file open.
    Expected Results : No difference from normal application usage.
    Returns: N/A.
    """
    with patch("builtins.open", mock_open(read_data=RAW_JSON_DATA)):
        json_parser = LoadAndParseJson()
        json_parser.load_file("file/path")
        assert json_parser.data == PROCESSED_JSON_DATA
Beispiel #4
0
def test_load_file(fixture_json_file_path):
    """
    Action : Test the server correct file load.
    Expected Results : Test finished with status "Passed".
    Returns: N/A.
    """
    load_and_parser_json = LoadAndParseJson()
    returned_data = load_and_parser_json.load_file(fixture_json_file_path)
    assert returned_data['services'][0]['title'] == 'ECU Reset'
    assert returned_data['services'][1]['id'] == '27'
    with pytest.raises(ParserErrorFileNotFoundError):
        load_and_parser_json.load_file('fixtures/wrong_file_path.json')
def test_file_load():
    """
    Action : Test mocking json file loading.
    Expected Results : No difference from normal application usage.
    Returns: N/A.
    """
    with patch(
            "builtins.open", mock_open(read_data=RAW_JSON_DATA))\
            as mock_file_object:
        with patch.object(
                json, "load", return_value=PROCESSED_JSON_DATA)\
                as mock_json_load:
            json_parser = LoadAndParseJson()
            json_parser.load_file("path/to/json/file")
            mock_json_load.assert_called_with(mock_file_object.return_value)
            assert json_parser.data == PROCESSED_JSON_DATA
Beispiel #6
0
def test_return_service_01(fixture_json_file_path, fixture_json_file):
    """
    Action : Test the server correct service return.
    Expected Results : Test finished with status "Passed".
    Returns: N/A.
    """
    load_and_parser_json = LoadAndParseJson()
    load_and_parser_json.load_file(fixture_json_file_path)
    returned_service = load_and_parser_json.return_signal_by_title(
        fixture_json_file['services'][0]['id'])
    assert returned_service == 'ECU Reset'
    returned_service = load_and_parser_json.return_signal_by_title(
        fixture_json_file['services'][1]['id'])
    assert returned_service == 'Security Access'
    returned_service = load_and_parser_json.return_signal_by_title('XXXXX')
    assert returned_service == 'Service not suported!'