Skip to content
Snippets Groups Projects
Commit a1228219 authored by Neda Moeini's avatar Neda Moeini
Browse files

Improved codebase.

parent 01e4942a
No related branches found
No related tags found
1 merge request!60Feature/nat 217 import sites
Pipeline #83894 passed
......@@ -20,9 +20,9 @@ run-tox-pipeline:
# only cache local items.
variables:
POSTGRES_DB: gso-test-db
POSTGRES_USER: gso
POSTGRES_PASSWORD: gso
DATABASE_URI_TEST: 'postgresql://gso:gso@postgres:5432/gso-test-db'
POSTGRES_USER: nwa
POSTGRES_PASSWORD: nwa
DATABASE_URI_TEST: 'postgresql://nwa:nwa@postgres:5432/gso-test-db'
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
# Pip's cache doesn't store the python packages
......
from orchestrator.db import (
ProductTable,
ResourceTypeTable,
SubscriptionInstanceTable,
SubscriptionInstanceValueTable,
SubscriptionTable,
)
from gso.products.product_types.site import Site
def get_site_by_name(site_name: str) -> Site:
"""Get a site by its name.
Args:
----
site_name (str): The name of the site.
"""
subscription = (
SubscriptionTable.query.join(
ProductTable, SubscriptionInstanceTable, SubscriptionInstanceValueTable, ResourceTypeTable
)
.filter(SubscriptionInstanceValueTable.value == site_name)
.filter(ResourceTypeTable.resource_type == "site_name")
.filter(SubscriptionTable.status == "active")
.first()
)
if not subscription:
raise ValueError(f"Site with name {site_name} not found.")
return Site.from_subscription(subscription.subscription_id)
......@@ -3,13 +3,7 @@ from typing import Optional
from uuid import UUID
from orchestrator import workflow
from orchestrator.db import (
ProductTable,
ResourceTypeTable,
SubscriptionInstanceTable,
SubscriptionInstanceValueTable,
SubscriptionTable,
)
from orchestrator.db import ProductTable
from orchestrator.forms import FormPage
from orchestrator.targets import Target
from orchestrator.types import FormGenerator, State, SubscriptionLifecycle
......@@ -20,8 +14,8 @@ from gso.products.product_blocks import router as router_pb
from gso.products.product_blocks.router import RouterRole, RouterVendor
from gso.products.product_types import router
from gso.products.product_types.router import RouterInactive
from gso.products.product_types.site import Site
from gso.services.crm import get_customer_by_name
from gso.services.subscriptions import get_site_by_name
@step("Create subscription")
......@@ -60,21 +54,6 @@ def initial_input_form_generator() -> FormGenerator:
return user_input.dict()
def get_site_by_name(site_name: str) -> Site:
subscription = (
SubscriptionTable.query.join(
ProductTable, SubscriptionInstanceTable, SubscriptionInstanceValueTable, ResourceTypeTable
)
.filter(SubscriptionInstanceValueTable.value == site_name)
.filter(ResourceTypeTable.resource_type == "site_name")
.filter(SubscriptionTable.status == "active")
.first()
)
if not subscription:
raise ValueError(f"Site with name {site_name} not found.")
return Site.from_subscription(subscription.subscription_id)
@step("Initialize subscription")
def initialize_subscription(
subscription: RouterInactive,
......
......@@ -93,7 +93,7 @@ def data_config_filename(configuration_data) -> str:
def db_uri():
"""Provide the database uri configuration to run the migration on."""
return os.environ.get("DATABASE_URI_TEST", "postgresql://gso:gos@localhost/gso-test-db")
return os.environ.get("DATABASE_URI_TEST", "postgresql://nwa:nwa@localhost/gso-test-db")
def run_migrations(db_uri: str) -> None:
......
......@@ -51,6 +51,7 @@ class TestImportEndpoints:
resource_type="site_name", value=self.site_data["site_name"]
)
assert subscription is not None
self.site_data.pop("customer")
def test_import_site_endpoint_with_existing_site(self):
response = self.client.post(self.site_import_endpoint, json=self.site_data)
......@@ -63,11 +64,10 @@ class TestImportEndpoints:
def test_import_site_endpoint_with_invalid_data(self):
# invalid data, missing site_latitude and invalid site_longitude
site_data = self.site_data.copy()
site_data.pop("site_latitude")
site_data["site_longitude"] = "invalid"
self.site_data.pop("site_latitude")
self.site_data["site_longitude"] = "invalid"
assert SubscriptionTable.query.count() == 0
response = self.client.post(self.site_import_endpoint, json=site_data)
response = self.client.post(self.site_import_endpoint, json=self.site_data)
assert response.status_code == 422
assert SubscriptionTable.query.count() == 0
response = response.json()
......@@ -92,10 +92,9 @@ class TestImportEndpoints:
assert SubscriptionTable.query.count() == 1
# invalid data, missing hostname and invalid router_lo_ipv6_address
router_data = self.router_data.copy()
router_data.pop("hostname")
router_data["router_lo_ipv6_address"] = "invalid"
response = self.client.post(self.router_import_endpoint, json=router_data)
self.router_data.pop("hostname")
self.router_data["router_lo_ipv6_address"] = "invalid"
response = self.client.post(self.router_import_endpoint, json=self.router_data)
assert response.status_code == 422
assert SubscriptionTable.query.count() == 1
response = response.json()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment