Skip to content
Snippets Groups Projects

Address SonarQube code smells

Merged JORGE SASIAIN requested to merge feature/NAT-356-sonarqube-code-smells into develop
All threads resolved!
2 files
+ 44
35
Compare changes
  • Side-by-side
  • Inline
Files
2
  • 9b11b288
    NAT-356: create BaseSiteModel and extend it in CreateSiteForm · 9b11b288
    JORGE SASIAIN authored
+ 42
0
Neda Moeini
Last comment by JORGE SASIAIN
from pydantic import BaseModel, validator
from pydantic.fields import ModelField
from gso.products.product_blocks.site import SiteTier
from gso.utils.helpers import (
validate_site_fields_is_unique,
validate_ipv4_or_ipv6,
validate_country_code,
validate_site_name,
)
class BaseSiteModel(BaseModel):
site_bgp_community_id: int
site_internal_id: int
site_tier: SiteTier
site_ts_address: str
@validator("site_ts_address", check_fields=False, allow_reuse=True)
def validate_ts_address(cls, site_ts_address: str) -> str:
"""Validate that a terminal server address is valid."""
validate_ipv4_or_ipv6(site_ts_address)
return site_ts_address
@validator("site_country_code", check_fields=False, allow_reuse=True)
def country_code_must_exist(cls, country_code: str) -> str:
"""Validate that the country code exists."""
validate_country_code(country_code)
return country_code
@validator("site_ts_address", "site_internal_id", "site_bgp_community_id", "site_name", check_fields=False, allow_reuse=True)
def validate_unique_fields(cls, value: str, field: ModelField) -> str | int:
"""Validate that the internal and :term:`BGP` community IDs are unique."""
return validate_site_fields_is_unique(field.name, value)
@validator("site_name", check_fields=False, allow_reuse=True)
def site_name_must_be_valid(cls, site_name: str) -> str:
"""Validate the site name.
The site name must consist of three uppercase letters, followed by an optional single digit.
"""
validate_site_name(site_name)
return site_name
\ No newline at end of file
Loading