Add enums.py

This commit is contained in:
zandercymatics 2024-01-09 12:27:38 -07:00
parent a7fa332d36
commit 5b2eeee547
No known key found for this signature in database
GPG key ID: FF4636ABEC9682B7
4 changed files with 33 additions and 28 deletions

View file

@ -11,6 +11,7 @@ import os
import sys
from typing import Dict, List
from django.core.paginator import Paginator
from registrar.utility.enums import LogCode
from registrar.models.transition_domain import TransitionDomain
from registrar.management.commands.utility.load_organization_error import (
LoadOrganizationError,
@ -28,7 +29,8 @@ from .epp_data_containers import (
)
from .transition_domain_arguments import TransitionDomainArguments
from .terminal_helper import TerminalColors, TerminalHelper, LogCode
from .terminal_helper import TerminalColors, TerminalHelper
logger = logging.getLogger(__name__)

View file

@ -1,29 +1,10 @@
from enum import Enum
import logging
import sys
from typing import List
from registrar.utility.enums import LogCode
logger = logging.getLogger(__name__)
class LogCode(Enum):
"""Stores the desired log severity
Overview of error codes:
- 1 ERROR
- 2 WARNING
- 3 INFO
- 4 DEBUG
- 5 DEFAULT
"""
ERROR = 1
WARNING = 2
INFO = 3
DEBUG = 4
DEFAULT = 5
class TerminalColors:
"""Colors for terminal outputs
(makes reading the logs WAY easier)"""

View file

@ -8,9 +8,6 @@ from api.views import DOMAIN_API_MESSAGES, check_domain_available
from registrar.utility import errors
from epplibwrapper.errors import RegistryError
class ValidationErrorReturnType(Enum):
JSON_RESPONSE = "JSON_RESPONSE"
FORM_VALIDATION_ERROR = "FORM_VALIDATION_ERROR"
class DomainHelper:
"""Utility functions and constants for domain names."""
@ -102,17 +99,15 @@ class DomainHelper:
raise forms.ValidationError(DOMAIN_API_MESSAGES[code], code=code)
# Why is this not working??
"""
match return_type:
case ValidationErrorReturnType.FORM_VALIDATION_ERROR:
case ValidationErrorReturnType.FORM_VALIDATION_ERROR.value:
raise forms.ValidationError(DOMAIN_API_MESSAGES[code], code=code)
case ValidationErrorReturnType.JSON_RESPONSE:
case ValidationErrorReturnType.JSON_RESPONSE.value:
return JsonResponse(
{"available": available, "code": code, "message": DOMAIN_API_MESSAGES[code]}
)
case _:
raise ValueError("Invalid return type specified")
"""
@classmethod
def sld(cls, domain: str):

View file

@ -0,0 +1,27 @@
"""Used for holding various enums"""
from enum import Enum
class ValidationErrorReturnType(Enum):
"""Determines the return value of the validate_and_handle_errors class"""
JSON_RESPONSE = "JSON_RESPONSE"
FORM_VALIDATION_ERROR = "FORM_VALIDATION_ERROR"
class LogCode(Enum):
"""Stores the desired log severity
Overview of error codes:
- 1 ERROR
- 2 WARNING
- 3 INFO
- 4 DEBUG
- 5 DEFAULT
"""
ERROR = 1
WARNING = 2
INFO = 3
DEBUG = 4
DEFAULT = 5