From 56ad58342114b564c2c688fa6c987e70ce45a7ba Mon Sep 17 00:00:00 2001 From: ARYAN-NIKNEZHAD Date: Fri, 26 Jul 2024 09:36:53 +0430 Subject: [PATCH] :hammer: :zap: Refactor IMAPSettings: Add constants file and update validation logic - Moved DEFAULTS dictionary to a new constants file for better organization. - Added EXCLUDED_FROM_VALIDATION constant to IMAPSettings class to specify which settings should not trigger validation errors if they are None. - Updated IMAPSettings class to use EXCLUDED_FROM_VALIDATION for validation checks. This refactoring improves code readability and maintainability by centralizing constants and clarifying validation logic. --- sage_mailbox/conf.py | 13 ++++--------- sage_mailbox/constants.py | 8 ++++++++ 2 files changed, 12 insertions(+), 9 deletions(-) create mode 100644 sage_mailbox/constants.py diff --git a/sage_mailbox/conf.py b/sage_mailbox/conf.py index 8fedd70..7b92b23 100644 --- a/sage_mailbox/conf.py +++ b/sage_mailbox/conf.py @@ -1,22 +1,17 @@ from django.conf import settings from sage_mailbox.exc import IMAPConfigurationError - -DEFAULTS = { - "IMAP_SERVER_DOMAIN": None, - "IMAP_SERVER_PORT": 993, - "IMAP_SERVER_USER": None, - "IMAP_SERVER_PASSWORD": None, - "IMAP_DEBUG_ENABLED": True, -} +from sage_mailbox.constants import DEFAULTS class IMAPSettings: + EXCLUDED_FROM_VALIDATION = ["IMAP_DEBUG_ENABLED"] + def __init__(self): self._settings = {} for setting, default in DEFAULTS.items(): value = getattr(settings, setting, default) - if value is None and setting not in ["MAILCOW_DEBUG_ENABLED"]: + if value is None and setting not in self.EXCLUDED_FROM_VALIDATION: raise IMAPConfigurationError( f"{setting} must be set in your Django settings." ) diff --git a/sage_mailbox/constants.py b/sage_mailbox/constants.py new file mode 100644 index 0000000..af8f1e9 --- /dev/null +++ b/sage_mailbox/constants.py @@ -0,0 +1,8 @@ + +DEFAULTS = { + "IMAP_SERVER_DOMAIN": None, + "IMAP_SERVER_PORT": 993, + "IMAP_SERVER_USER": None, + "IMAP_SERVER_PASSWORD": None, + "IMAP_DEBUG_ENABLED": True, +}