Skip to content
Snippets Groups Projects
Verified Commit 35e17e93 authored by Karel van Klink's avatar Karel van Klink :smiley_cat:
Browse files

move types into their respective product blocks and types

parent af7e59b5
Branches
Tags
No related merge requests found
Pipeline #84225 failed
...@@ -5,10 +5,10 @@ import pytest ...@@ -5,10 +5,10 @@ import pytest
from orchestrator.db import SubscriptionTable from orchestrator.db import SubscriptionTable
from orchestrator.services import subscriptions from orchestrator.services import subscriptions
from gso.products.product_blocks.iptrunk import IptrunkType from gso.products.product_blocks.iptrunk import IptrunkType, PhyPortCapacity
from gso.products.product_blocks.router import RouterRole, RouterVendor from gso.products.product_blocks.router import RouterRole, RouterVendor
from gso.products.product_blocks.site import SiteTier from gso.products.product_blocks.site import SiteTier
from gso.utils.types.phy_port import PhyPortCapacity from gso.utils.helpers import iso_from_ipv4
SITE_IMPORT_ENDPOINT = "/api/v1/imports/sites" SITE_IMPORT_ENDPOINT = "/api/v1/imports/sites"
ROUTER_IMPORT_ENDPOINT = "/api/v1/imports/routers" ROUTER_IMPORT_ENDPOINT = "/api/v1/imports/routers"
...@@ -21,20 +21,20 @@ def iptrunk_data(router_subscription_factory, faker): ...@@ -21,20 +21,20 @@ def iptrunk_data(router_subscription_factory, faker):
router_side_b = router_subscription_factory() router_side_b = router_subscription_factory()
return { return {
"customer": "GÉANT", "customer": "GÉANT",
"geant_s_sid": faker.pystr(), "geant_s_sid": faker.geant_sid(),
"iptrunk_type": IptrunkType.DARK_FIBER, "iptrunk_type": IptrunkType.DARK_FIBER,
"iptrunk_description": faker.sentence(), "iptrunk_description": faker.sentence(),
"iptrunk_speed": PhyPortCapacity.HUNDRED_GIGABIT_PER_SECOND, "iptrunk_speed": PhyPortCapacity.HUNDRED_GIGABIT_PER_SECOND,
"iptrunk_minimum_links": 5, "iptrunk_minimum_links": 5,
"side_a_node_id": router_side_a, "side_a_node_id": router_side_a,
"side_a_ae_iface": faker.pystr(), "side_a_ae_iface": faker.network_interface(),
"side_a_ae_geant_a_sid": faker.pystr(), "side_a_ae_geant_a_sid": faker.geant_sid(),
"side_a_ae_members": [ "side_a_ae_members": [
{"interface_name": faker.network_interface(), "interface_description": faker.sentence()} for _ in range(5) {"interface_name": faker.network_interface(), "interface_description": faker.sentence()} for _ in range(5)
], ],
"side_b_node_id": router_side_b, "side_b_node_id": router_side_b,
"side_b_ae_iface": faker.pystr(), "side_b_ae_iface": faker.network_interface(),
"side_b_ae_geant_a_sid": faker.pystr(), "side_b_ae_geant_a_sid": faker.geant_sid(),
"side_b_ae_members": [ "side_b_ae_members": [
{"interface_name": faker.network_interface(), "interface_description": faker.sentence()} for _ in range(5) {"interface_name": faker.network_interface(), "interface_description": faker.sentence()} for _ in range(5)
], ],
...@@ -45,23 +45,23 @@ def iptrunk_data(router_subscription_factory, faker): ...@@ -45,23 +45,23 @@ def iptrunk_data(router_subscription_factory, faker):
@pytest.fixture @pytest.fixture
def mock_routers(iptrunk_data): def mock_routers(iptrunk_data):
first_call = [iptrunk_data["side_a_node_id"], iptrunk_data["side_b_node_id"], str(uuid4())]
side_effects = [
first_call,
first_call,
[
(iptrunk_data["side_a_node_id"], "side_a_node_id description"),
(iptrunk_data["side_b_node_id"], "side_b_node_id description"),
(str(uuid4()), "random description"),
],
]
with patch("gso.services.subscriptions.get_active_router_subscriptions") as mock_get_active_router_subscriptions: with patch("gso.services.subscriptions.get_active_router_subscriptions") as mock_get_active_router_subscriptions:
mock_get_active_router_subscriptions.side_effect = side_effects
def _active_router_subscriptions(*args, **kwargs):
if kwargs["fields"] == ["subscription_id", "description"]:
return [
(iptrunk_data["side_a_node_id"], "side_a_node_id description"),
(iptrunk_data["side_b_node_id"], "side_b_node_id description"),
(str(uuid4()), "random description"),
]
return [iptrunk_data["side_a_node_id"], iptrunk_data["side_b_node_id"], str(uuid4())]
mock_get_active_router_subscriptions.side_effect = _active_router_subscriptions
yield mock_get_active_router_subscriptions yield mock_get_active_router_subscriptions
@patch("gso.api.v1.imports._start_process") @patch("gso.api.v1.imports._start_process")
def test_import_iptrunk_successful_with_mocked_process(mock_start_process, test_client, iptrunk_data, mock_routers): def test_import_iptrunk_successful_with_mocked_process(mock_start_process, test_client, mock_routers, iptrunk_data):
mock_start_process.return_value = "123e4567-e89b-12d3-a456-426655440000" mock_start_process.return_value = "123e4567-e89b-12d3-a456-426655440000"
response = test_client.post(IPTRUNK_IMPORT_API_URL, json=iptrunk_data) response = test_client.post(IPTRUNK_IMPORT_API_URL, json=iptrunk_data)
...@@ -72,7 +72,7 @@ def test_import_iptrunk_successful_with_mocked_process(mock_start_process, test_ ...@@ -72,7 +72,7 @@ def test_import_iptrunk_successful_with_mocked_process(mock_start_process, test_
@pytest.fixture @pytest.fixture
def site_data(faker): def site_data(faker):
return { return {
"site_name": faker.name(), "site_name": faker.domain_word(),
"site_city": faker.city(), "site_city": faker.city(),
"site_country": faker.country(), "site_country": faker.country(),
"site_country_code": faker.country_code(), "site_country_code": faker.country_code(),
...@@ -88,6 +88,7 @@ def site_data(faker): ...@@ -88,6 +88,7 @@ def site_data(faker):
@pytest.fixture @pytest.fixture
def router_data(faker, site_data): def router_data(faker, site_data):
mock_ipv4 = faker.ipv4()
return { return {
"hostname": "127.0.0.1", "hostname": "127.0.0.1",
"router_role": RouterRole.PE, "router_role": RouterRole.PE,
...@@ -96,9 +97,9 @@ def router_data(faker, site_data): ...@@ -96,9 +97,9 @@ def router_data(faker, site_data):
"ts_port": 1234, "ts_port": 1234,
"customer": "GÉANT", "customer": "GÉANT",
"is_ias_connected": True, "is_ias_connected": True,
"router_lo_ipv4_address": faker.ipv4(), "router_lo_ipv4_address": mock_ipv4,
"router_lo_ipv6_address": faker.ipv6(), "router_lo_ipv6_address": faker.ipv6(),
"router_lo_iso_address": "TestAddress", "router_lo_iso_address": iso_from_ipv4(mock_ipv4),
} }
...@@ -169,7 +170,7 @@ def test_import_router_endpoint_with_invalid_data(test_client, site_data, router ...@@ -169,7 +170,7 @@ def test_import_router_endpoint_with_invalid_data(test_client, site_data, router
assert response["detail"][1]["msg"] == "value is not a valid IPv6 address" assert response["detail"][1]["msg"] == "value is not a valid IPv6 address"
def test_import_iptrunk_successful_with_real_process(test_client, iptrunk_data, mock_routers): def test_import_iptrunk_successful_with_real_process(test_client, mock_routers, iptrunk_data):
response = test_client.post(IPTRUNK_IMPORT_API_URL, json=iptrunk_data) response = test_client.post(IPTRUNK_IMPORT_API_URL, json=iptrunk_data)
assert response.status_code == 201 assert response.status_code == 201
...@@ -184,7 +185,7 @@ def test_import_iptrunk_successful_with_real_process(test_client, iptrunk_data, ...@@ -184,7 +185,7 @@ def test_import_iptrunk_successful_with_real_process(test_client, iptrunk_data,
@patch("gso.api.v1.imports._start_process") @patch("gso.api.v1.imports._start_process")
def test_import_iptrunk_invalid_customer(mock_start_process, test_client, iptrunk_data, mock_routers): def test_import_iptrunk_invalid_customer(mock_start_process, test_client, mock_routers, iptrunk_data):
iptrunk_data["customer"] = "not_existing_customer" iptrunk_data["customer"] = "not_existing_customer"
mock_start_process.return_value = "123e4567-e89b-12d3-a456-426655440000" mock_start_process.return_value = "123e4567-e89b-12d3-a456-426655440000"
response = test_client.post(IPTRUNK_IMPORT_API_URL, json=iptrunk_data) response = test_client.post(IPTRUNK_IMPORT_API_URL, json=iptrunk_data)
...@@ -205,32 +206,28 @@ def test_import_iptrunk_invalid_router_id_side_a_and_b(mock_start_process, test_ ...@@ -205,32 +206,28 @@ def test_import_iptrunk_invalid_router_id_side_a_and_b(mock_start_process, test_
assert response.status_code == 422 assert response.status_code == 422
assert response.json() == { assert response.json() == {
"detail": [ "detail": [
{"loc": ["body", "side_a_node_id"], "msg": "Router not found", "type": "value_error"}, {
{"loc": ["body", "side_b_node_id"], "msg": "Router not found", "type": "value_error"}, "loc": ["body", "side_a_node_id"],
"msg": f"Router {iptrunk_data['side_a_node_id']} not found",
"type": "value_error",
},
{
"loc": ["body", "side_b_node_id"],
"msg": f"Router {iptrunk_data['side_b_node_id']} not found",
"type": "value_error",
},
] ]
} }
@patch("gso.api.v1.imports._start_process") @patch("gso.api.v1.imports._start_process")
def test_import_iptrunk_non_unique_members_side_a(mock_start_process, test_client, iptrunk_data, mock_routers, faker): def test_import_iptrunk_non_unique_members_side_a(mock_start_process, test_client, mock_routers, iptrunk_data, faker):
mock_start_process.return_value = "123e4567-e89b-12d3-a456-426655440000" mock_start_process.return_value = "123e4567-e89b-12d3-a456-426655440000"
repeat_interface_a = {"interface_name": faker.network_interface(), "interface_description": faker.sentence()} repeat_interface_a = {"interface_name": faker.network_interface(), "interface_description": faker.sentence()}
repeat_interface_b = {"interface_name": faker.network_interface(), "interface_description": faker.sentence()} repeat_interface_b = {"interface_name": faker.network_interface(), "interface_description": faker.sentence()}
iptrunk_data["side_a_ae_members"] = [ iptrunk_data["side_a_ae_members"] = [repeat_interface_a for _ in range(5)]
repeat_interface_a, iptrunk_data["side_b_ae_members"] = [repeat_interface_b for _ in range(5)]
repeat_interface_a,
repeat_interface_a,
repeat_interface_a,
repeat_interface_a,
]
iptrunk_data["side_b_ae_members"] = [
repeat_interface_b,
repeat_interface_a,
repeat_interface_a,
repeat_interface_b,
repeat_interface_b,
]
response = test_client.post(IPTRUNK_IMPORT_API_URL, json=iptrunk_data) response = test_client.post(IPTRUNK_IMPORT_API_URL, json=iptrunk_data)
...@@ -250,7 +247,7 @@ def test_import_iptrunk_non_unique_members_side_a(mock_start_process, test_clien ...@@ -250,7 +247,7 @@ def test_import_iptrunk_non_unique_members_side_a(mock_start_process, test_clien
@patch("gso.api.v1.imports._start_process") @patch("gso.api.v1.imports._start_process")
def test_import_iptrunk_fails_on_side_a_member_count_mismatch( def test_import_iptrunk_fails_on_side_a_member_count_mismatch(
mock_start_process, test_client, iptrunk_data, mock_routers mock_start_process, test_client, mock_routers, iptrunk_data
): ):
mock_start_process.return_value = "123e4567-e89b-12d3-a456-426655440000" mock_start_process.return_value = "123e4567-e89b-12d3-a456-426655440000"
......
import pytest import pytest
from gso.utils.types.snmp import LatitudeCoordinate, LongitudeCoordinate from gso.products.product_blocks.site import LatitudeCoordinate, LongitudeCoordinate
@pytest.mark.parametrize( @pytest.mark.parametrize(
......
...@@ -4,10 +4,9 @@ from unittest.mock import patch ...@@ -4,10 +4,9 @@ from unittest.mock import patch
import pytest import pytest
from gso.products import Iptrunk, ProductType from gso.products import Iptrunk, ProductType
from gso.products.product_blocks.iptrunk import IptrunkType from gso.products.product_blocks.iptrunk import IptrunkType, PhyPortCapacity
from gso.services.crm import customer_selector, get_customer_by_name from gso.services.crm import customer_selector, get_customer_by_name
from gso.services.subscriptions import get_product_id_by_name from gso.services.subscriptions import get_product_id_by_name
from gso.utils.types.phy_port import PhyPortCapacity
from test.workflows import ( from test.workflows import (
assert_aborted, assert_aborted,
assert_complete, assert_complete,
......
...@@ -3,8 +3,7 @@ from unittest.mock import patch ...@@ -3,8 +3,7 @@ from unittest.mock import patch
import pytest import pytest
from gso.products import Iptrunk from gso.products import Iptrunk
from gso.products.product_blocks.iptrunk import IptrunkType from gso.products.product_blocks.iptrunk import IptrunkType, PhyPortCapacity
from gso.utils.types.phy_port import PhyPortCapacity
from test.workflows import ( from test.workflows import (
assert_complete, assert_complete,
assert_suspended, assert_suspended,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment