Commit 15d89d8a authored by Karagkounis Dimitris's avatar Karagkounis Dimitris
Browse files

implement logic to retrieve single app by appId controller

parent ba152eda
Loading
Loading
Loading
Loading
+25 −11
Original line number Diff line number Diff line
@@ -7,6 +7,10 @@ from edge_cloud_management_api.managers.log_manager import logger
from edge_cloud_management_api.models.application_models import AppManifest


class NotFound404Exception(Exception):
    pass


def submit_app(body: dict):
    """
    Controller for submitting application metadata.
@@ -55,20 +59,30 @@ def get_apps(x_correlator=None): # noqa: E501


def get_app(appId, x_correlator=None):  # noqa: E501
    """Retrieve the information of an Application
    """Retrieve the information of an Application"""
    # if connexion.request.is_json:
    #     app_id = AppId.from_dict(connexion.request.get_json())  # noqa: E501
    try:
        with MongoManager() as db:
            document = db.find_document("apps", {"_id": appId})
            if document is None:
                raise NotFound404Exception()
            document["appId"] = document["_id"]
            del document["_id"]

    Ask the Edge Cloud Provider the information for a given application  # noqa: E501
            return (jsonify(document), 200)

    :param appId: A globally unique identifier associated with the application. Edge Cloud Provider generates this identifier when the application is submitted.
    :type appId: dict | bytes
    :param x_correlator: Correlation id for the different services
    :type x_correlator: str
    except NotFound404Exception:
        return (
            jsonify({"status": 404, "code": "NOT_FOUND", "message": "Resource does not exist"}),
            404,
        )

    :rtype: InlineResponse200
    """
    # if connexion.request.is_json:
    #     app_id = AppId.from_dict(connexion.request.get_json())  # noqa: E501
    return "do some magic!"
    except Exception as e:
        return (
            jsonify({"error": "An unexpected error occurred", "details": str(e)}),
            500,
        )


def delete_app(appId, x_correlator=None):  # noqa: E501
+21 −15
Original line number Diff line number Diff line
@@ -15,21 +15,6 @@ def test_app():
    return flask_app.app


@pytest.mark.parametrize(
    "app_id, x_correlator, expected",
    [
        (1, None, "do some magic!"),
        (2, "123", "do some magic!"),
    ],
)
def test_get_app(app_id, x_correlator, expected):
    """
    Test the get_app controller.
    """
    result = get_app(app_id, x_correlator)
    assert result == expected


@pytest.fixture
def mock_get_all_cloud_zones():
    with patch(
@@ -105,3 +90,24 @@ def test_get_apps(
        #     assert "appId" in response.json
        # else:
        #     assert False


@pytest.mark.parametrize(
    "x_correlator, app_id, expected_response_status",
    [
        (None, "e343569e-e92c-4adc-9719-468b3b00a9d3", 200),
        (None, "e343569e-192c-4adc-9719-468b3b00a9d3", 404),
    ],
)
def test_get_app(
    x_correlator,
    app_id,
    expected_response_status,
    test_app: Flask,
):
    """
    Test the get_app controller.
    """
    with test_app.test_request_context():
        response, response_status = get_app(appId=app_id, x_correlator=x_correlator)
        assert response_status == expected_response_status