Unverified Commit 71dbeb4c authored by Adrian Pino's avatar Adrian Pino Committed by GitHub
Browse files

Merge pull request #31 from OpenOperatorPlatform/refactor/move-i2edge-tests-to-edgecloud

Refactor/move i2edge tests to edgecloud
parents f6739e7f 4b0454dc
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -32,7 +32,7 @@ Each contribution should be made in the appropriate directory:
- **Network Adapters**`src/network/clients/`

## Unit Tests Requirement
To merge a feature branch into `main`, the adapter **must include unit tests** under the `/tests` directory.
To merge a feature branch into `main`, the adapter **must include unit tests** under the `/tests` directory. Please use `/tests/edgecloud` for edgecloud, and `/tests/network` for the 5G cores)
Ensure that your unit tests cover the main functionalities of the adapter.

## Steps to Contribute
+0 −0

Empty file added.

+0 −0

Empty file added.

+0 −0

Empty file added.

+57 −70
Original line number Diff line number Diff line
import pytest

from src.edgecloud.clients.aeros.client import EdgeApplicationManager as AerosClient
from src.edgecloud.clients.dmo.client import EdgeApplicationManager as DmoClient
from src.edgecloud.clients.i2edge.client import EdgeApplicationManager as I2EdgeClient
from src.edgecloud.clients.i2edge.client import I2EdgeError
from src.edgecloud.clients.piedge.client import EdgeApplicationManager as PiEdgeClient
from src.edgecloud.core.edgecloud_factory import EdgeCloudFactory

# Define common test cases for all tests
test_cases = [
    ("i2edge", "http://192.168.123.237:30769/"),
    # ("aeros", "http://aeros.example.com/"),
    # ("piedge", "http://piedge.example.com/"),
    # ("dmo", "http://dmo.example.com/")
i2edge_testbed = [
    ("i2edge", "http://192.168.123.237:30769/")
]


#######################################
# EDGECLOUD CLIENT'S INSTANTIATION
#######################################
@pytest.mark.parametrize("client_name, base_url", test_cases)
@pytest.mark.parametrize("client_name, base_url", i2edge_testbed)
def test_factory_edgecloud(client_name, base_url):
    """
    Test the factory pattern for the edgecloud client.
    """
    client_class_map = {
        "i2edge": I2EdgeClient,
        "aeros": AerosClient,
        "piedge": PiEdgeClient,
        "dmo": DmoClient,
    }

    expected_client_class = client_class_map[client_name]
@@ -41,7 +31,7 @@ def test_factory_edgecloud(client_name, base_url):
#######################################
# GET EDGE CLOUD ZONES
#######################################
@pytest.mark.parametrize("client_name, base_url", test_cases)
@pytest.mark.parametrize("client_name, base_url", i2edge_testbed)
def test_get_edge_cloud_zones(client_name, base_url):
    """
    Test the format of the response from get_edge_cloud_zones for each client.
@@ -63,10 +53,12 @@ def test_get_edge_cloud_zones(client_name, base_url):
#######################################
# ARTIFACT MANAGEMENT (only for i2Edge)
#######################################
artefact_id = "hello-world-from-sdk"
artefact_id = "hello-world-from-sdk-2"
artefact_name = "hello-word-2"
repo_name = "dummy-repo-2"


@pytest.mark.parametrize("client_name, base_url", test_cases)
@pytest.mark.parametrize("client_name, base_url", i2edge_testbed)
def test_create_artefact_success(client_name, base_url):
    if client_name == "i2edge":
        edgecloud_platform = EdgeCloudFactory.create_edgecloud_client(
@@ -76,8 +68,8 @@ def test_create_artefact_success(client_name, base_url):
        try:
            edgecloud_platform._create_artefact(
                artefact_id=artefact_id,
                artefact_name="hello-world",
                repo_name="dummy-repo",
                artefact_name=artefact_name,
                repo_name=repo_name,
                repo_type="PUBLICREPO",
                repo_url="https://helm.github.io/examples",
                password=None,
@@ -88,7 +80,7 @@ def test_create_artefact_success(client_name, base_url):
            pytest.fail(f"Artefact creation failed unexpectedly: {e}")


@pytest.mark.parametrize("client_name, base_url", test_cases)
@pytest.mark.parametrize("client_name, base_url", i2edge_testbed)
def test_create_artefact_failure(client_name, base_url):
    if client_name == "i2edge":
        edgecloud_platform = EdgeCloudFactory.create_edgecloud_client(
@@ -98,8 +90,8 @@ def test_create_artefact_failure(client_name, base_url):
        with pytest.raises(I2EdgeError):
            edgecloud_platform._create_artefact(
                artefact_id=artefact_id,
                artefact_name="test-artefact",
                repo_name="test-repo",
                artefact_name=artefact_name,
                repo_name=repo_name,
                repo_type="PUBLICREPO",
                repo_url="http://invalid.url",
                password=None,
@@ -108,9 +100,8 @@ def test_create_artefact_failure(client_name, base_url):
            )


@pytest.mark.parametrize("client_name, base_url", test_cases)
@pytest.mark.parametrize("client_name, base_url", i2edge_testbed)
def test_get_artefact_success(client_name, base_url):
    if client_name == "i2edge":
    edgecloud_platform = EdgeCloudFactory.create_edgecloud_client(
        client_name, base_url
    )
@@ -121,9 +112,8 @@ def test_get_artefact_success(client_name, base_url):
        pytest.fail(f"Artefact retrieval failed unexpectedly: {e}")


@pytest.mark.parametrize("client_name, base_url", test_cases)
@pytest.mark.parametrize("client_name, base_url", i2edge_testbed)
def test_get_artefact_failure(client_name, base_url):
    if client_name == "i2edge":
    edgecloud_platform = EdgeCloudFactory.create_edgecloud_client(
        client_name, base_url
    )
@@ -132,9 +122,8 @@ def test_get_artefact_failure(client_name, base_url):
        edgecloud_platform._get_artefact(artefact_id="non-existent-artefact")


@pytest.mark.parametrize("client_name, base_url", test_cases)
@pytest.mark.parametrize("client_name, base_url", i2edge_testbed)
def test_get_all_artefacts_success(client_name, base_url):
    if client_name == "i2edge":
    edgecloud_platform = EdgeCloudFactory.create_edgecloud_client(
        client_name, base_url
    )
@@ -144,9 +133,8 @@ def test_get_all_artefacts_success(client_name, base_url):
    except I2EdgeError as e:
        pytest.fail(f"Artefact retrieval failed unexpectedly: {e}")

@pytest.mark.parametrize("client_name, base_url", test_cases)
@pytest.mark.parametrize("client_name, base_url", i2edge_testbed)
def test_delete_artefact_success(client_name, base_url):
    if client_name == "i2edge":
    edgecloud_platform = EdgeCloudFactory.create_edgecloud_client(
        client_name, base_url
    )
@@ -157,9 +145,8 @@ def test_delete_artefact_success(client_name, base_url):
        pytest.fail(f"Artefact deletion failed unexpectedly: {e}")


@pytest.mark.parametrize("client_name, base_url", test_cases)
@pytest.mark.parametrize("client_name, base_url", i2edge_testbed)
def test_delete_artefact_failure(client_name, base_url):
    if client_name == "i2edge":
    edgecloud_platform = EdgeCloudFactory.create_edgecloud_client(
        client_name, base_url
    )
@@ -216,7 +203,7 @@ app_manifest = {
app_manifest.update({"artefactId": app_manifest["appId"]})


@pytest.mark.parametrize("client_name, base_url", test_cases)
@pytest.mark.parametrize("client_name, base_url", i2edge_testbed)
def test_onboard_app_success(client_name, base_url):
    edgecloud_platform = EdgeCloudFactory.create_edgecloud_client(
        client_name, base_url
@@ -228,7 +215,7 @@ def test_onboard_app_success(client_name, base_url):
        pytest.fail(f"App onboarding failed unexpectedly: {e}")


@pytest.mark.parametrize("client_name, base_url", test_cases)
@pytest.mark.parametrize("client_name, base_url", i2edge_testbed)
def test_onboard_app_failure(client_name, base_url):
    edgecloud_platform = EdgeCloudFactory.create_edgecloud_client(
        client_name, base_url
@@ -238,7 +225,7 @@ def test_onboard_app_failure(client_name, base_url):
        edgecloud_platform.onboard_app({})


@pytest.mark.parametrize("client_name, base_url", test_cases)
@pytest.mark.parametrize("client_name, base_url", i2edge_testbed)
def test_onboard_app_failure_artefact_id_missing(client_name, base_url):
    app_manifest.pop("artefactId")

@@ -250,7 +237,7 @@ def test_onboard_app_failure_artefact_id_missing(client_name, base_url):
        edgecloud_platform.onboard_app({})


@pytest.mark.parametrize("client_name, base_url", test_cases)
@pytest.mark.parametrize("client_name, base_url", i2edge_testbed)
def test_get_onboarded_app_success(client_name, base_url):
    edgecloud_platform = EdgeCloudFactory.create_edgecloud_client(
        client_name, base_url
@@ -262,7 +249,7 @@ def test_get_onboarded_app_success(client_name, base_url):
        pytest.fail(f"App onboarding failed unexpectedly: {e}")


@pytest.mark.parametrize("client_name, base_url", test_cases)
@pytest.mark.parametrize("client_name, base_url", i2edge_testbed)
def test_get_onboarded_app_failure(client_name, base_url):
    edgecloud_platform = EdgeCloudFactory.create_edgecloud_client(
        client_name, base_url
@@ -272,7 +259,7 @@ def test_get_onboarded_app_failure(client_name, base_url):
        edgecloud_platform.get_onboarded_app(app_id="non-existent-app")


@pytest.mark.parametrize("client_name, base_url", test_cases)
@pytest.mark.parametrize("client_name, base_url", i2edge_testbed)
def test_get_all_onboarded_app_success(client_name, base_url):
    edgecloud_platform = EdgeCloudFactory.create_edgecloud_client(
        client_name, base_url
@@ -284,7 +271,7 @@ def test_get_all_onboarded_app_success(client_name, base_url):
        pytest.fail(f"App onboarding failed unexpectedly: {e}")


@pytest.mark.parametrize("client_name, base_url", test_cases)
@pytest.mark.parametrize("client_name, base_url", i2edge_testbed)
def test_delete_onboarded_app_success(client_name, base_url):
    edgecloud_platform = EdgeCloudFactory.create_edgecloud_client(
        client_name, base_url
@@ -296,7 +283,7 @@ def test_delete_onboarded_app_success(client_name, base_url):
        pytest.fail(f"App onboarding deletion failed unexpectedly: {e}")


@pytest.mark.parametrize("client_name, base_url", test_cases)
@pytest.mark.parametrize("client_name, base_url", i2edge_testbed)
def test_delete_onboarded_app_failure(client_name, base_url):
    edgecloud_platform = EdgeCloudFactory.create_edgecloud_client(
        client_name, base_url
Loading