def test_interpretation_01():
    """
    Action : Test mocking interpretation.
    Expected Results : No difference from normal application usage.
    Returns: N/A.
    """
    json_parser = LoadAndParse()
    json_parser.data = {"services": [{"title": "Security Access", "id": "27"}]}
    assert json_parser.return_signal_by_title("27") == "Security Access"
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 = LoadAndParse()
        json_parser.load_file("file/path")
        assert json_parser.data == PROCESSED_JSON_DATA
Exemplo n.º 3
0
def fixture_loadandparse_instance(fixture_json_file):
    """
    Action : LoadAndParce class instance.
    Expected Correct LoadAndParce class instance returned.
    Returns: LoadAndParce class instance.
    """
    load_and_parser = LoadAndParse()
    load_and_parser.data = fixture_json_file
    load_and_parser.title = None
    return load_and_parser
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 = LoadAndParse()
            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
Exemplo n.º 5
0
"""
Module for implementing the routes
"""
from flask import Flask
from flask import request
from flask import jsonify
from signal_interpreter_server.json_parser import LoadAndParse

signal_interpreter_app = Flask(__name__)
jsonparser = LoadAndParse()


@signal_interpreter_app.route("/", methods=["POST"])
def interpret_signal():
    """
    Action : Make the received code interpretation.
    Expected Results : Proper code interpretation.
    Returns: jsonfy_data.
    """
    data = request.get_json()
    print(data)
    parsed_data = jsonparser.return_signal_by_title(data['service'])
    jsonfy_data = jsonify(parsed_data)
    return jsonfy_data