Skip to content

Commit

Permalink
task/WP-271 Upgrade Django and 3rd party dependancies (#895)
Browse files Browse the repository at this point in the history
* updated django version and dependencies

* upgraded channels to version 3 and fixed tests

* upgraded channels to version 4

* formatting fix

* Added nginx conf

* add pytest filterwarning

* removed added nginx conf, added CSRF trusted origin for cep.test

* upgrade postgres to v14.9

* linting, added CSRF setting to settings_default

* update settings

---------

Co-authored-by: Sal Tijerina <[email protected]>
Co-authored-by: Chandra Y <[email protected]>
  • Loading branch information
3 people committed Dec 8, 2023
1 parent da23c0e commit 1337741
Show file tree
Hide file tree
Showing 21 changed files with 1,279 additions and 1,005 deletions.
4 changes: 2 additions & 2 deletions server/conf/docker/docker-compose-dev.all.debug.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ services:
- 127.0.0.1:9200:9200

postgres:
image: postgres:11.5
image: postgres:14.9
volumes:
- core_portal_postgres_data:/var/lib/postgresql/data/portal
container_name: core_portal_postgres
Expand All @@ -61,7 +61,7 @@ services:
- PGDATA=/var/lib/postgresql/data/portal

postgrescms:
image: postgres:11.5
image: postgres:14.9
volumes:
- core_cms_postgres_data:/var/lib/postgresql/data/portal
container_name: core_cms_postgres
Expand Down
2,202 changes: 1,235 additions & 967 deletions server/poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion server/portal/apps/accounts/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
.. :module:: apps.accounts.api.urls
:synopsis: Manager handling anything pertaining to accounts
"""
from django.conf.urls import re_path
from django.urls import re_path
from portal.apps.accounts.api.views.systems import SystemKeysView

app_name = 'portal_accounts_api'
Expand Down
2 changes: 1 addition & 1 deletion server/portal/apps/accounts/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
.. module:: portal.apps.accounts.urls
:synopsis: Accounts URLs
"""
from django.conf.urls import re_path
from django.urls import re_path
from django.contrib.auth.views import LogoutView
from portal.apps.accounts.views import accounts
from portal.apps.accounts import views
Expand Down
2 changes: 1 addition & 1 deletion server/portal/apps/auth/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
.. module:: portal.apps.auth.urls
:synopsis: Auth URls
"""
from django.conf.urls import re_path
from django.urls import re_path
from portal.apps.auth import views

app_name = 'portal_auth'
Expand Down
4 changes: 2 additions & 2 deletions server/portal/apps/notifications/consumers_unit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ async def auth_connect(user):

# Pass session ID in headers to authenticate.
communicator = WebsocketCommunicator(
NotificationsConsumer,
path='/ws/notifications/'
NotificationsConsumer.as_asgi(),
path='/ws/notifications/',
)
communicator.scope['user'] = user
connected, _ = await communicator.connect()
Expand Down
2 changes: 1 addition & 1 deletion server/portal/apps/notifications/routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
from portal.apps.notifications.consumers import NotificationsConsumer

websocket_urlpatterns = [
re_path(r'ws/notifications/$', NotificationsConsumer),
re_path(r'ws/notifications/$', NotificationsConsumer.as_asgi()),
]
2 changes: 1 addition & 1 deletion server/portal/apps/notifications/urls.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.conf.urls import re_path
from django.urls import re_path
from portal.apps.notifications.views import ManageNotificationsView


Expand Down
2 changes: 1 addition & 1 deletion server/portal/apps/onboarding/api/views_unit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def test_admin_route(client, authenticated_staff):
# If the user is authenticated and is_staff, then the route should
# return a JsonResponse
response = client.get("/api/onboarding/admin/")
assert type(response) == JsonResponse
assert isinstance(response, JsonResponse)


def test_admin_route_is_protected(authenticated_user, client):
Expand Down
4 changes: 2 additions & 2 deletions server/portal/apps/projects/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
from portal.views.base import BaseApiView
from portal.apps.projects.managers.base import ProjectsManager
from portal.apps.projects.workspace_operations.shared_workspace_operations import \
list_projects, get_project, create_shared_workspace,\
update_project, get_workspace_role, change_user_role, add_user_to_workspace,\
list_projects, get_project, create_shared_workspace, \
update_project, get_workspace_role, change_user_role, add_user_to_workspace, \
remove_user, transfer_ownership
from portal.apps.search.tasks import tapis_project_listing_indexer
from portal.libs.elasticsearch.indexes import IndexedProject
Expand Down
3 changes: 1 addition & 2 deletions server/portal/apps/users/urls.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from django.conf.urls import re_path
from django.urls import path
from django.urls import path, re_path
from portal.apps.users.views import (SearchView, AuthenticatedView, UsageView, AllocationsView, TeamView,
UserDataView, TasUsersView, AllocationUsageView, AllocationManagementView)

Expand Down
4 changes: 2 additions & 2 deletions server/portal/apps/webhooks/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.db import models
from django.conf import settings
from datetime import datetime
from django.utils import timezone


class ExternalCall(models.Model):
Expand All @@ -21,7 +21,7 @@ class ExternalCall(models.Model):
)

# Timestamp for outbound external call
time = models.DateTimeField(default=datetime.now)
time = models.DateTimeField(default=timezone.now)

# Callback class to be executed when a webhook is received
callback = models.CharField(max_length=300, null=True)
Expand Down
2 changes: 1 addition & 1 deletion server/portal/apps/workspace/api/urls.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Workpace API Urls
"""
from django.conf.urls import re_path
from django.urls import re_path
from portal.apps.workspace.api import views


Expand Down
2 changes: 1 addition & 1 deletion server/portal/apps/workspace/urls.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Workspace URLs
"""
from django.conf.urls import re_path
from django.urls import re_path
from portal.apps.workspace import views

urlpatterns = [
Expand Down
8 changes: 6 additions & 2 deletions server/portal/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@

import os
import django
from channels.routing import get_default_application
from channels.routing import ProtocolTypeRouter
from django.core.asgi import get_asgi_application


os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'portal.settings.settings')
django.setup()
application = get_default_application()
application = ProtocolTypeRouter({
"http": get_asgi_application(),
})
10 changes: 7 additions & 3 deletions server/portal/settings/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
# whether the session cookie should be secure (https:// only)
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SAMESITE = 'Strict'
# for local testing
CSRF_TRUSTED_ORIGINS = getattr(settings_custom, '_CSRF_TRUSTED_ORIGINS', [])

SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
ALLOWED_HOSTS = ['*']
Expand All @@ -64,6 +66,10 @@

INSTALLED_APPS = [

# Django Channels
'channels',
'daphne',

# Core Django.
'django.contrib.admin',
'django.contrib.auth',
Expand All @@ -75,9 +81,7 @@
'django.contrib.sitemaps',
'django.contrib.sessions.middleware',

# Django Channels
'channels',

# Pipeline.
'termsandconditions',
'impersonate',

Expand Down
1 change: 1 addition & 0 deletions server/portal/settings/settings_custom.example.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

_RT_QUEUE = 'Web & Mobile Apps'
_RT_TAG = 'core_portal'
_CSRF_TRUSTED_ORIGINS = ['https://cep.test']

########################
# AGAVE SETTINGS
Expand Down
1 change: 1 addition & 0 deletions server/portal/settings/settings_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

_RT_QUEUE = 'Web & Mobile Apps'
_RT_TAG = 'core_portal'
_CSRF_TRUSTED_ORIGINS = ['https://cep.test']

########################
# TAPIS SETTINGS
Expand Down
7 changes: 4 additions & 3 deletions server/portal/settings/unit_test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@

INSTALLED_APPS = [

# Django Channels
'channels',
'daphne',

# Core Django.
'django.contrib.admin',
'django.contrib.auth',
Expand All @@ -58,9 +62,6 @@
'django.contrib.sitemaps',
'django.contrib.sessions.middleware',

# Django Channels
'channels',

# Pipeline.
'termsandconditions',
'impersonate',
Expand Down
8 changes: 5 additions & 3 deletions server/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ authors = ["TACC-WMA <[email protected]>"]
readme = "README.md"

[tool.poetry.dependencies]
Django = "^3.2"
Django = "^4.2"
python = "^3.11"
elasticsearch-dsl = "^7.2.1"
paramiko = "^2.10.1"
Expand All @@ -26,8 +26,9 @@ elasticsearch = "^7.7.1"
uwsgi = "^2.0.22"
requests = "^2.31.0"
django-impersonate = "^1.5"
channels = "^2.4.0"
channels-redis = "^3.1.0"
channels = "^4.0.0"
channels-redis = "^4.1.0"
daphne = "^4.0.0"
pytas = {git = "https://bitbucket.org/taccaci/pytas.git", tag = "v1.6.0"}
google-auth = "^1.23.0"
google-auth-oauthlib = "^0.4.2"
Expand All @@ -46,6 +47,7 @@ pytest-mock = "^3.10.0"
mock = "^5.0.2"
pytest-cov = "^4.0.0"
pytest-django = "^4.5.2"
pytest-asyncio = "^0.21.1"
flake8 = "^6.0.0"
coverage = "^7.2.5"
requests-mock = "^1.10.0"
Expand Down
12 changes: 3 additions & 9 deletions server/pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,9 @@
DJANGO_SETTINGS_MODULE = portal.settings.unit_test_settings
python_files = tests.py *unit_test.py

filterwarnings =
ignore::DeprecationWarning:django.*:
ignore::DeprecationWarning:openapi_schema_validator.*:
ignore::DeprecationWarning:openapi_spec_validator.*:
ignore::DeprecationWarning:openapi_core.*:
ignore::DeprecationWarning:kombu.*:
ignore::DeprecationWarning:pkg_resources.*:
ignore:.*Django now detects this configuration.*:django.utils.deprecation.RemovedInDjango41Warning

filterwarnings =
ignore::DeprecationWarning:twisted.*:
ignore::django.utils.deprecation.RemovedInDjango50Warning
markers =
asyncio: mark a test as asyncio.

Expand Down

0 comments on commit 1337741

Please sign in to comment.