Commit ba152eda authored by Karagkounis Dimitris's avatar Karagkounis Dimitris
Browse files

implement and test get_apps controller

parent ea53f899
Loading
Loading
Loading
Loading
+15 −12
Original line number Diff line number Diff line
@@ -35,20 +35,23 @@ def submit_app(body: dict):


def get_apps(x_correlator=None):  # noqa: E501
    """Retrieve the information of an Application

    Ask the Edge Cloud Provider the information for a given application  # noqa: E501
    """Retrieve metadata information of all applications"""
    try:
        with MongoManager() as db:
            documents_cursor = db.find_documents("apps", {})
            response_apps = list()
            for document in documents_cursor:
                document["appId"] = document["_id"]
                del document["_id"]
                response_apps.append(document)

    :param app_id: A globally unique identifier associated with the application. Edge Cloud Provider generates this identifier when the application is submitted.
    :type app_id: dict | bytes
    :param x_correlator: Correlation id for the different services
    :type x_correlator: str
            return (jsonify(response_apps), 200)

    :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 get_app(appId, x_correlator=None):  # noqa: E501
+23 −2
Original line number Diff line number Diff line
@@ -2,7 +2,7 @@ import pytest
from unittest.mock import MagicMock, patch
from flask import Flask
from edge_cloud_management_api.app import get_app_instance
from edge_cloud_management_api.controllers.app_controllers import submit_app, get_app
from edge_cloud_management_api.controllers.app_controllers import submit_app, get_apps, get_app


@pytest.fixture
@@ -71,7 +71,7 @@ def test_submit_app(
    test_app: Flask,
):
    """
    Test the get_edge_cloud_zones controller.
    Test the submit_app controller.
    """
    with test_app.test_request_context():
        response, response_status = submit_app(body)
@@ -84,3 +84,24 @@ def test_submit_app(
            # mock_get_all_cloud_zones.assert_called_once()
        else:
            assert False


@pytest.mark.parametrize(
    "x_correlator, expected_response_status",
    [(None, 200)],
)
def test_get_apps(
    x_correlator,
    expected_response_status,
    test_app: Flask,
):
    """
    Test the get_apps controller.
    """
    with test_app.test_request_context():
        response, response_status = get_apps(x_correlator)
        assert response_status == expected_response_status
        # if expected_response_status == 200:
        #     assert "appId" in response.json
        # else:
        #     assert False