Skip to content

Commit

Permalink
fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
opaduchak committed Jan 7, 2025
1 parent 97a17c8 commit 6865a6b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
3 changes: 2 additions & 1 deletion addon_service/addon_operation_invocation/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
21 changes: 13 additions & 8 deletions addon_service/credentials/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions app/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(",")))
Expand All @@ -16,6 +18,7 @@
NEW_RELIC_ENVIRONMENT = os.environ.get("NEW_RELIC_ENVIRONMENT")
SESSION_COOKIE_DOMAIN = os.environ.get("SESSION_COOKIE_DOMAIN")


###
# databases

Expand Down
3 changes: 2 additions & 1 deletion app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 6865a6b

Please sign in to comment.