Skip to content
Snippets Groups Projects
Commit 2a13cf00 authored by Mohammad Torkashvand's avatar Mohammad Torkashvand
Browse files

fix a bug when partner_id is None in customer_reolver

unified get_partner_by_name to return object instead of dict
parent 18e9ff5c
No related branches found
No related tags found
1 merge request!346fix a bug when partner_id is None in customer_reolver
Pipeline #91524 passed
Showing
with 31 additions and 40 deletions
...@@ -11,18 +11,12 @@ from gso.services.partners import get_partner_by_id, get_partner_by_name ...@@ -11,18 +11,12 @@ from gso.services.partners import get_partner_by_id, get_partner_by_name
async def resolve_customer(root: CustomerType) -> CustomerType: async def resolve_customer(root: CustomerType) -> CustomerType:
"""Resolve the customer field for a subscription or process.""" """Resolve the customer field for a subscription or process."""
if root.customer_id: partner = get_partner_by_id(root.customer_id) if root.customer_id else get_partner_by_name("GEANT")
partner = get_partner_by_id(root.customer_id)
return CustomerType(
customer_id=partner.partner_id,
fullname=partner.name,
shortcode=partner.email,
)
partner = get_partner_by_name("GEANT")
return CustomerType( return CustomerType(
customer_id=partner["partner_id"], customer_id=partner.partner_id,
fullname=partner["name"], fullname=partner.name,
shortcode=partner["email"], shortcode=partner.email,
) )
......
...@@ -7,7 +7,6 @@ from uuid import uuid4 ...@@ -7,7 +7,6 @@ from uuid import uuid4
from orchestrator.db import db from orchestrator.db import db
from pydantic import AfterValidator, BaseModel, ConfigDict, EmailStr, Field from pydantic import AfterValidator, BaseModel, ConfigDict, EmailStr, Field
from sqlalchemy import func from sqlalchemy import func
from sqlalchemy.exc import NoResultFound
from gso.db.models import PartnerTable from gso.db.models import PartnerTable
...@@ -59,20 +58,18 @@ class PartnerNotFoundError(Exception): ...@@ -59,20 +58,18 @@ class PartnerNotFoundError(Exception):
"""Exception raised when a partner is not found.""" """Exception raised when a partner is not found."""
def get_all_partners() -> list[dict]: def get_all_partners() -> list[PartnerTable]:
"""Fetch all partners from the database and serialize them to JSON.""" """Fetch all partners from the database and serialize them to JSON."""
partners = PartnerTable.query.all() return PartnerTable.query.all()
return [partner.__json__() for partner in partners]
def get_partner_by_name(name: str) -> dict[str, Any]: def get_partner_by_name(name: str) -> PartnerTable:
"""Try to get a partner by their name.""" """Try to get a partner by their name."""
try: partner = db.session.query(PartnerTable).filter_by(name=name).first()
partner = db.session.query(PartnerTable).filter(PartnerTable.name == name).one() if not partner:
return partner.__json__() raise PartnerNotFoundError
except NoResultFound as e:
msg = f"partner {name} not found" return partner
raise PartnerNotFoundError(msg) from e
def get_partner_by_id(partner_id: str) -> PartnerTable: def get_partner_by_id(partner_id: str) -> PartnerTable:
......
...@@ -277,7 +277,7 @@ def active_edge_port_selector(*, partner_id: UUIDstr | None = None) -> Choice: ...@@ -277,7 +277,7 @@ def active_edge_port_selector(*, partner_id: UUIDstr | None = None) -> Choice:
def partner_choice() -> Choice: def partner_choice() -> Choice:
"""Return a Choice object containing a list of available partners.""" """Return a Choice object containing a list of available partners."""
partners = {partner["partner_id"]: partner["name"] for partner in get_all_partners()} partners = {partner.partner_id: partner.name for partner in get_all_partners()}
return Choice("Select a partner", zip(partners.values(), partners.items(), strict=True)) # type: ignore[arg-type] return Choice("Select a partner", zip(partners.values(), partners.items(), strict=True)) # type: ignore[arg-type]
......
...@@ -27,7 +27,7 @@ from gso.utils.types.interfaces import LAGMember, PhysicalPortCapacity ...@@ -27,7 +27,7 @@ from gso.utils.types.interfaces import LAGMember, PhysicalPortCapacity
@step("Create subscription") @step("Create subscription")
def create_subscription(partner: str) -> State: def create_subscription(partner: str) -> State:
"""Create a new subscription object.""" """Create a new subscription object."""
partner_id = get_partner_by_name(partner)["partner_id"] partner_id = get_partner_by_name(partner).partner_id
product_id = get_product_id_by_name(ProductName.IMPORTED_EDGE_PORT) product_id = get_product_id_by_name(ProductName.IMPORTED_EDGE_PORT)
subscription = ImportedEdgePortInactive.from_product_id(product_id, partner_id) subscription = ImportedEdgePortInactive.from_product_id(product_id, partner_id)
......
...@@ -59,7 +59,7 @@ def initial_input_form_generator() -> FormGenerator: ...@@ -59,7 +59,7 @@ def initial_input_form_generator() -> FormGenerator:
@step("Create a new subscription") @step("Create a new subscription")
def create_subscription(partner: str) -> State: def create_subscription(partner: str) -> State:
"""Create a new subscription in the service database.""" """Create a new subscription in the service database."""
partner_id = get_partner_by_name(partner)["partner_id"] partner_id = get_partner_by_name(partner).partner_id
product_id = subscriptions.get_product_id_by_name(ProductName.IMPORTED_IP_TRUNK) product_id = subscriptions.get_product_id_by_name(ProductName.IMPORTED_IP_TRUNK)
subscription = ImportedIptrunkInactive.from_product_id(product_id, partner_id) subscription = ImportedIptrunkInactive.from_product_id(product_id, partner_id)
......
...@@ -215,7 +215,7 @@ def initial_input_form_generator(product_name: str) -> FormGenerator: ...@@ -215,7 +215,7 @@ def initial_input_form_generator(product_name: str) -> FormGenerator:
@step("Create subscription") @step("Create subscription")
def create_subscription(product: UUIDstr, partner: str) -> State: def create_subscription(product: UUIDstr, partner: str) -> State:
"""Create a new subscription object in the database.""" """Create a new subscription object in the database."""
subscription = IptrunkInactive.from_product_id(product, get_partner_by_name(partner)["partner_id"]) subscription = IptrunkInactive.from_product_id(product, get_partner_by_name(partner).partner_id)
return { return {
"subscription": subscription, "subscription": subscription,
......
...@@ -83,7 +83,7 @@ def initial_input_form_generator() -> FormGenerator: ...@@ -83,7 +83,7 @@ def initial_input_form_generator() -> FormGenerator:
@step("Create subscription") @step("Create subscription")
def create_subscription(partner: str, service_type: Layer2CircuitServiceType) -> State: def create_subscription(partner: str, service_type: Layer2CircuitServiceType) -> State:
"""Create a new subscription object.""" """Create a new subscription object."""
partner_id = get_partner_by_name(partner)["partner_id"] partner_id = get_partner_by_name(partner).partner_id
product_id = get_product_id_by_name(ProductName(service_type)) product_id = get_product_id_by_name(ProductName(service_type))
subscription = ImportedLayer2CircuitInactive.from_product_id(product_id, partner_id) subscription = ImportedLayer2CircuitInactive.from_product_id(product_id, partner_id)
......
...@@ -29,7 +29,7 @@ from gso.utils.types.virtual_identifiers import VLAN_ID ...@@ -29,7 +29,7 @@ from gso.utils.types.virtual_identifiers import VLAN_ID
def initial_input_generator(product_name: str) -> FormGenerator: def initial_input_generator(product_name: str) -> FormGenerator:
"""Gather input from the operator about a new Layer 2 Circuit subscription.""" """Gather input from the operator about a new Layer 2 Circuit subscription."""
geant_partner_id = get_partner_by_name("GEANT")["partner_id"] geant_partner_id = get_partner_by_name("GEANT").partner_id
class CreateLayer2CircuitServicePage(FormPage): class CreateLayer2CircuitServicePage(FormPage):
model_config = ConfigDict(title=f"{product_name}") model_config = ConfigDict(title=f"{product_name}")
......
...@@ -80,7 +80,7 @@ def initial_input_form_generator() -> FormGenerator: ...@@ -80,7 +80,7 @@ def initial_input_form_generator() -> FormGenerator:
@step("Create subscription") @step("Create subscription")
def create_subscription(partner: str, service_type: L3CoreServiceType) -> dict: def create_subscription(partner: str, service_type: L3CoreServiceType) -> dict:
"""Create a new subscription object in the database.""" """Create a new subscription object in the database."""
partner_id = get_partner_by_name(partner)["partner_id"] partner_id = get_partner_by_name(partner).partner_id
match service_type: match service_type:
case L3CoreServiceType.GEANT_IP: case L3CoreServiceType.GEANT_IP:
product_id = get_product_id_by_name(ProductName.IMPORTED_GEANT_IP) product_id = get_product_id_by_name(ProductName.IMPORTED_GEANT_IP)
......
...@@ -44,7 +44,7 @@ def _initial_input_form_generator() -> FormGenerator: ...@@ -44,7 +44,7 @@ def _initial_input_form_generator() -> FormGenerator:
@step("Create subscription") @step("Create subscription")
def create_subscription(partner: str) -> State: def create_subscription(partner: str) -> State:
"""Create a new subscription object.""" """Create a new subscription object."""
partner_id = get_partner_by_name(partner)["partner_id"] partner_id = get_partner_by_name(partner).partner_id
product_id = get_product_id_by_name(ProductName.IMPORTED_LAN_SWITCH_INTERCONNECT) product_id = get_product_id_by_name(ProductName.IMPORTED_LAN_SWITCH_INTERCONNECT)
subscription = ImportedLanSwitchInterconnectInactive.from_product_id(product_id, partner_id) subscription = ImportedLanSwitchInterconnectInactive.from_product_id(product_id, partner_id)
......
...@@ -125,7 +125,7 @@ def _initial_input_form(product_name: str) -> FormGenerator: ...@@ -125,7 +125,7 @@ def _initial_input_form(product_name: str) -> FormGenerator:
@step("Create subscription") @step("Create subscription")
def create_subscription(product: UUIDstr, partner: str) -> State: def create_subscription(product: UUIDstr, partner: str) -> State:
"""Create a new subscription object in the database.""" """Create a new subscription object in the database."""
subscription = LanSwitchInterconnectInactive.from_product_id(product, get_partner_by_name(partner)["partner_id"]) subscription = LanSwitchInterconnectInactive.from_product_id(product, get_partner_by_name(partner).partner_id)
return {"subscription": subscription, "subscription_id": subscription.subscription_id} return {"subscription": subscription, "subscription_id": subscription.subscription_id}
......
...@@ -20,7 +20,7 @@ from gso.utils.types.ip_address import IPv4AddressType, IPv6AddressType, PortNum ...@@ -20,7 +20,7 @@ from gso.utils.types.ip_address import IPv4AddressType, IPv6AddressType, PortNum
@step("Create subscription") @step("Create subscription")
def create_subscription(partner: str) -> State: def create_subscription(partner: str) -> State:
"""Create a new subscription object.""" """Create a new subscription object."""
partner_id = get_partner_by_name(partner)["partner_id"] partner_id = get_partner_by_name(partner).partner_id
product_id = subscriptions.get_product_id_by_name(ProductName.IMPORTED_OFFICE_ROUTER) product_id = subscriptions.get_product_id_by_name(ProductName.IMPORTED_OFFICE_ROUTER)
subscription = ImportedOfficeRouterInactive.from_product_id(product_id, partner_id) subscription = ImportedOfficeRouterInactive.from_product_id(product_id, partner_id)
......
...@@ -18,7 +18,7 @@ from gso.utils.types.ip_address import IPv4AddressType ...@@ -18,7 +18,7 @@ from gso.utils.types.ip_address import IPv4AddressType
@step("Create subscription") @step("Create subscription")
def create_subscription(partner: str) -> State: def create_subscription(partner: str) -> State:
"""Create a new subscription object.""" """Create a new subscription object."""
partner_id = get_partner_by_name(partner)["partner_id"] partner_id = get_partner_by_name(partner).partner_id
product_id = get_product_id_by_name(ProductName.IMPORTED_OPENGEAR) product_id = get_product_id_by_name(ProductName.IMPORTED_OPENGEAR)
subscription = ImportedOpengearInactive.from_product_id(product_id, partner_id) subscription = ImportedOpengearInactive.from_product_id(product_id, partner_id)
......
...@@ -21,7 +21,7 @@ from gso.utils.types.ip_address import IPv4AddressType, IPv6AddressType, PortNum ...@@ -21,7 +21,7 @@ from gso.utils.types.ip_address import IPv4AddressType, IPv6AddressType, PortNum
@step("Create subscription") @step("Create subscription")
def create_subscription(partner: str) -> State: def create_subscription(partner: str) -> State:
"""Create a new subscription object.""" """Create a new subscription object."""
partner_id = get_partner_by_name(partner)["partner_id"] partner_id = get_partner_by_name(partner).partner_id
product_id = get_product_id_by_name(ProductName.IMPORTED_ROUTER) product_id = get_product_id_by_name(ProductName.IMPORTED_ROUTER)
subscription = ImportedRouterInactive.from_product_id(product_id, partner_id) subscription = ImportedRouterInactive.from_product_id(product_id, partner_id)
......
...@@ -117,7 +117,7 @@ def initial_input_form_generator(product_name: str) -> FormGenerator: ...@@ -117,7 +117,7 @@ def initial_input_form_generator(product_name: str) -> FormGenerator:
@step("Create subscription") @step("Create subscription")
def create_subscription(product: UUIDstr, partner: str) -> State: def create_subscription(product: UUIDstr, partner: str) -> State:
"""Create a new subscription object.""" """Create a new subscription object."""
subscription = RouterInactive.from_product_id(product, get_partner_by_name(partner)["partner_id"]) subscription = RouterInactive.from_product_id(product, get_partner_by_name(partner).partner_id)
return { return {
"subscription": subscription, "subscription": subscription,
......
...@@ -22,7 +22,7 @@ from gso.utils.types.ip_address import IPAddress ...@@ -22,7 +22,7 @@ from gso.utils.types.ip_address import IPAddress
@step("Create subscription") @step("Create subscription")
def create_subscription(partner: str) -> State: def create_subscription(partner: str) -> State:
"""Create a new subscription object in the service database.""" """Create a new subscription object in the service database."""
partner_id = get_partner_by_name(partner)["partner_id"] partner_id = get_partner_by_name(partner).partner_id
product_id: UUID = subscriptions.get_product_id_by_name(ProductName.IMPORTED_SITE) product_id: UUID = subscriptions.get_product_id_by_name(ProductName.IMPORTED_SITE)
subscription = ImportedSiteInactive.from_product_id(product_id, partner_id) subscription = ImportedSiteInactive.from_product_id(product_id, partner_id)
......
...@@ -52,7 +52,7 @@ def initial_input_form_generator(product_name: str) -> FormGenerator: ...@@ -52,7 +52,7 @@ def initial_input_form_generator(product_name: str) -> FormGenerator:
@step("Create subscription") @step("Create subscription")
def create_subscription(product: UUIDstr, partner: str) -> State: def create_subscription(product: UUIDstr, partner: str) -> State:
"""Create a new subscription object in the service database.""" """Create a new subscription object in the service database."""
subscription = site.SiteInactive.from_product_id(product, get_partner_by_name(partner)["partner_id"]) subscription = site.SiteInactive.from_product_id(product, get_partner_by_name(partner).partner_id)
return { return {
"subscription": subscription, "subscription": subscription,
......
...@@ -21,7 +21,7 @@ from gso.utils.types.ip_address import IPv4AddressType, PortNumber ...@@ -21,7 +21,7 @@ from gso.utils.types.ip_address import IPv4AddressType, PortNumber
@step("Create subscription") @step("Create subscription")
def create_subscription(partner: str) -> State: def create_subscription(partner: str) -> State:
"""Create a new subscription object.""" """Create a new subscription object."""
partner_id = get_partner_by_name(partner)["partner_id"] partner_id = get_partner_by_name(partner).partner_id
product_id = subscriptions.get_product_id_by_name(ProductName.IMPORTED_SUPER_POP_SWITCH) product_id = subscriptions.get_product_id_by_name(ProductName.IMPORTED_SUPER_POP_SWITCH)
subscription = ImportedSuperPopSwitchInactive.from_product_id(product_id, partner_id) subscription = ImportedSuperPopSwitchInactive.from_product_id(product_id, partner_id)
......
...@@ -32,7 +32,7 @@ def _initial_input_form_generator() -> FormGenerator: ...@@ -32,7 +32,7 @@ def _initial_input_form_generator() -> FormGenerator:
@step("Create subscription") @step("Create subscription")
def create_subscription(partner: str) -> State: def create_subscription(partner: str) -> State:
"""Create a new subscription object.""" """Create a new subscription object."""
partner_id = get_partner_by_name(partner)["partner_id"] partner_id = get_partner_by_name(partner).partner_id
product_id = get_product_id_by_name(ProductName.IMPORTED_SWITCH) product_id = get_product_id_by_name(ProductName.IMPORTED_SWITCH)
subscription = ImportedSwitchInactive.from_product_id(product_id, partner_id) subscription = ImportedSwitchInactive.from_product_id(product_id, partner_id)
......
...@@ -67,7 +67,7 @@ def _initial_input_form_generator(product_name: str) -> FormGenerator: ...@@ -67,7 +67,7 @@ def _initial_input_form_generator(product_name: str) -> FormGenerator:
@step("Create subscription") @step("Create subscription")
def create_subscription(product: UUIDstr, partner: str) -> State: def create_subscription(product: UUIDstr, partner: str) -> State:
"""Create a new subscription object.""" """Create a new subscription object."""
subscription = SwitchInactive.from_product_id(product, get_partner_by_name(partner)["partner_id"]) subscription = SwitchInactive.from_product_id(product, get_partner_by_name(partner).partner_id)
return {"subscription": subscription, "subscription_id": subscription.subscription_id} return {"subscription": subscription, "subscription_id": subscription.subscription_id}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment