From dee6e0075ca0682a768e899ce7448b5b166e0099 Mon Sep 17 00:00:00 2001
From: Mohammad Torkashvand <mohammad.torkashvand@geant.org>
Date: Mon, 14 Aug 2023 15:53:51 +0200
Subject: [PATCH] added mocked customer_id

---
 .gitignore                              |  2 ++
 gso/services/crm.py                     |  7 +++++++
 gso/workflows/device/create_device.py   |  7 ++++---
 gso/workflows/iptrunk/create_iptrunk.py |  8 ++++----
 gso/workflows/site/create_site.py       |  8 ++++----
 gso/workflows/utils.py                  | 11 +++++++++++
 tox.ini                                 | 10 +++++-----
 7 files changed, 37 insertions(+), 16 deletions(-)
 create mode 100644 gso/services/crm.py
 create mode 100644 gso/workflows/utils.py

diff --git a/.gitignore b/.gitignore
index 0831a3be..4d87beab 100644
--- a/.gitignore
+++ b/.gitignore
@@ -14,3 +14,5 @@ oss-params.json
 docs/build
 docs/vale/styles/*
 !docs/vale/styles/Vocab/
+
+.idea
diff --git a/gso/services/crm.py b/gso/services/crm.py
new file mode 100644
index 00000000..b340dac0
--- /dev/null
+++ b/gso/services/crm.py
@@ -0,0 +1,7 @@
+def all_customers() -> list[dict]:
+    return [
+        {
+            "id": "8f0df561-ce9d-4d9c-89a8-7953d3ffc961",
+            "name": "Geant",
+        },
+    ]
diff --git a/gso/workflows/device/create_device.py b/gso/workflows/device/create_device.py
index 4d3f0cd7..78bc5dd2 100644
--- a/gso/workflows/device/create_device.py
+++ b/gso/workflows/device/create_device.py
@@ -1,6 +1,5 @@
 import ipaddress
 import re
-from uuid import uuid4
 
 from orchestrator.db.models import ProductTable, SubscriptionTable
 
@@ -19,6 +18,7 @@ from gso.products.product_types.device import DeviceInactive, DeviceProvisioning
 from gso.products.product_types.site import Site
 from gso.services import ipam, provisioning_proxy
 from gso.services.provisioning_proxy import pp_interaction
+from gso.workflows.utils import customer_selector
 
 
 def site_selector() -> Choice:
@@ -43,6 +43,7 @@ def initial_input_form_generator(product_name: str) -> FormGenerator:
         class Config:
             title = product_name
 
+        customer: customer_selector()  # type: ignore
         device_site: site_selector()  # type: ignore
         hostname: str
         ts_port: int
@@ -56,8 +57,8 @@ def initial_input_form_generator(product_name: str) -> FormGenerator:
 
 
 @step("Create subscription")
-def create_subscription(product: UUIDstr) -> State:
-    subscription = DeviceInactive.from_product_id(product, uuid4())
+def create_subscription(product: UUIDstr, customer: UUIDstr) -> State:
+    subscription = DeviceInactive.from_product_id(product, customer)
 
     return {
         "subscription": subscription,
diff --git a/gso/workflows/iptrunk/create_iptrunk.py b/gso/workflows/iptrunk/create_iptrunk.py
index 2b70dc70..89cca024 100644
--- a/gso/workflows/iptrunk/create_iptrunk.py
+++ b/gso/workflows/iptrunk/create_iptrunk.py
@@ -1,5 +1,3 @@
-from uuid import uuid4
-
 from orchestrator.db.models import ProductTable, SubscriptionTable
 from orchestrator.forms import FormPage
 from orchestrator.forms.validators import Choice, UniqueConstrainedList
@@ -15,6 +13,7 @@ from gso.products.product_types.device import Device
 from gso.products.product_types.iptrunk import IptrunkInactive, IptrunkProvisioning
 from gso.services import ipam, provisioning_proxy
 from gso.services.provisioning_proxy import pp_interaction
+from gso.workflows.utils import customer_selector
 
 
 def initial_input_form_generator(product_name: str) -> FormGenerator:
@@ -37,6 +36,7 @@ def initial_input_form_generator(product_name: str) -> FormGenerator:
         class Config:
             title = product_name
 
+        customer: customer_selector()  # type: ignore
         geant_s_sid: str
         iptrunk_description: str
         iptrunk_type: IptrunkType
@@ -86,8 +86,8 @@ def initial_input_form_generator(product_name: str) -> FormGenerator:
 
 
 @step("Create subscription")
-def create_subscription(product: UUIDstr) -> State:
-    subscription = IptrunkInactive.from_product_id(product, uuid4())
+def create_subscription(product: UUIDstr, customer: UUIDstr) -> State:
+    subscription = IptrunkInactive.from_product_id(product, customer)
 
     return {
         "subscription": subscription,
diff --git a/gso/workflows/site/create_site.py b/gso/workflows/site/create_site.py
index 5930bf15..67e3b912 100644
--- a/gso/workflows/site/create_site.py
+++ b/gso/workflows/site/create_site.py
@@ -1,5 +1,3 @@
-from uuid import uuid4
-
 from orchestrator.forms import FormPage
 from orchestrator.targets import Target
 from orchestrator.types import FormGenerator, State, SubscriptionLifecycle, UUIDstr
@@ -9,6 +7,7 @@ from orchestrator.workflows.utils import wrap_create_initial_input_form
 
 from gso.products.product_blocks import site as site_pb
 from gso.products.product_types import site
+from gso.workflows.utils import customer_selector
 
 
 def initial_input_form_generator(product_name: str) -> FormGenerator:
@@ -16,6 +15,7 @@ def initial_input_form_generator(product_name: str) -> FormGenerator:
         class Config:
             title = product_name
 
+        customer: customer_selector()  # type: ignore
         site_name: str
         site_city: str
         site_country: str
@@ -33,8 +33,8 @@ def initial_input_form_generator(product_name: str) -> FormGenerator:
 
 
 @step("Create subscription")
-def create_subscription(product: UUIDstr) -> State:
-    subscription = site.SiteInactive.from_product_id(product, uuid4())
+def create_subscription(product: UUIDstr, customer: UUIDstr) -> State:
+    subscription = site.SiteInactive.from_product_id(product, customer)
 
     return {
         "subscription": subscription,
diff --git a/gso/workflows/utils.py b/gso/workflows/utils.py
new file mode 100644
index 00000000..d2c63137
--- /dev/null
+++ b/gso/workflows/utils.py
@@ -0,0 +1,11 @@
+from orchestrator.forms.validators import Choice
+
+from gso.services.crm import all_customers
+
+
+def customer_selector() -> Choice:
+    customers = {}
+    for customer in all_customers():
+        customers[customer["id"]] = customer["name"]
+
+    return Choice("Select a customer", zip(customers.keys(), customers.items()))  # type: ignore
diff --git a/tox.ini b/tox.ini
index 8bfef47e..ed2f8f9a 100644
--- a/tox.ini
+++ b/tox.ini
@@ -19,14 +19,14 @@ deps =
     -r requirements.txt
 
 commands =
+    isort -c .
+    ruff .
+    black --check .
+    mypy .
+    flake8
     coverage erase
     coverage run --source gso -m pytest {posargs}
     coverage xml
     coverage html
     # coverage report --fail-under 80
     coverage report
-    isort -c .
-    ruff .
-    black --check .
-    mypy .
-    flake8
-- 
GitLab