From 6865a6bc7a943e898a0d92bf55439e0a4e8b2b4b Mon Sep 17 00:00:00 2001 From: Oleh Paduchak Date: Tue, 7 Jan 2025 17:06:15 +0200 Subject: [PATCH] fixed tests --- .../addon_operation_invocation/views.py | 3 ++- addon_service/credentials/models.py | 21 ++++++++++++------- app/env.py | 3 +++ app/settings.py | 3 ++- 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/addon_service/addon_operation_invocation/views.py b/addon_service/addon_operation_invocation/views.py index 6e2a86bc..b1b10e32 100644 --- a/addon_service/addon_operation_invocation/views.py +++ b/addon_service/addon_operation_invocation/views.py @@ -95,7 +95,8 @@ def perform_create(self, serializer): ) .first() ) - _invocation.thru_addon.base_account = _invocation.thru_account + if _invocation.thru_addon: + _invocation.thru_addon.base_account = _invocation.thru_account _operation_type = _invocation.operation.operation_type match _operation_type: case AddonOperationType.REDIRECT | AddonOperationType.IMMEDIATE: diff --git a/addon_service/credentials/models.py b/addon_service/credentials/models.py index 627d1690..a0ebe128 100644 --- a/addon_service/credentials/models.py +++ b/addon_service/credentials/models.py @@ -88,32 +88,37 @@ def _key_parameters(self, value: encryption.KeyParameters) -> None: ### @property - def authorized_account(self): + def authorized_accounts(self): """Returns the list of all accounts that point to this set of credentials. For now, this will just be a single AuthorizedAccount, but in the future other types of accounts for the same user could point to the same set of credentials """ try: - if account := getattr(self, "authorized_account", None): - return account - else: - return getattr(self, "temporary_authorized_account", None) + return [ + *filter( + bool, + [ + getattr(self, "authorized_account", None), + getattr(self, "temporary_authorized_account", None), + ], + ) + ] except ExternalCredentials.authorized_account.RelatedObjectDoesNotExist: return None @property def format(self): - if not self.authorized_account: + if not self.authorized_accounts: return None - return self.authorized_account.external_service.credentials_format + return self.authorized_accounts[0].external_service.credentials_format def clean_fields(self, *args, **kwargs): super().clean_fields(*args, **kwargs) self._validate_credentials() def _validate_credentials(self): - if not self.authorized_account: + if not self.authorized_accounts: return try: self.decrypted_credentials diff --git a/app/env.py b/app/env.py index 1efaf036..25d60e49 100644 --- a/app/env.py +++ b/app/env.py @@ -2,8 +2,10 @@ """ import os +import sys +TESTING = "test" in sys.argv DEBUG = bool(os.environ.get("DEBUG")) # any non-empty value enables debug mode SECRET_KEY = os.environ.get("SECRET_KEY") # used by django for cryptographic signing ALLOWED_HOSTS = list(filter(bool, os.environ.get("ALLOWED_HOSTS", "").split(","))) @@ -16,6 +18,7 @@ NEW_RELIC_ENVIRONMENT = os.environ.get("NEW_RELIC_ENVIRONMENT") SESSION_COOKIE_DOMAIN = os.environ.get("SESSION_COOKIE_DOMAIN") + ### # databases diff --git a/app/settings.py b/app/settings.py index eec43218..1a6c6f6e 100644 --- a/app/settings.py +++ b/app/settings.py @@ -107,10 +107,11 @@ ] -if DEBUG: +if DEBUG and not env.TESTING: # add django-silk to enable profiling INSTALLED_APPS.append("silk") MIDDLEWARE.insert(0, "silk.middleware.SilkyMiddleware") +if DEBUG: # run under ASGI locally: INSTALLED_APPS.insert(0, "daphne") # django's reference asgi server ASGI_APPLICATION = "app.asgi.application"