From 46697ae34211fecc13f20950615871d4fd586352 Mon Sep 17 00:00:00 2001 From: Topvennie Date: Wed, 6 Mar 2024 14:37:07 +0100 Subject: [PATCH] chore: fix test --- backend/authentication/serializers.py | 35 +++++++++++---------------- backend/notifications/urls.py | 2 +- backend/ypovoli/urls.py | 23 ++++++++++++------ 3 files changed, 31 insertions(+), 29 deletions(-) diff --git a/backend/authentication/serializers.py b/backend/authentication/serializers.py index 60771277..7c4f1d92 100644 --- a/backend/authentication/serializers.py +++ b/backend/authentication/serializers.py @@ -1,20 +1,20 @@ from typing import Tuple -from django.contrib.auth.models import update_last_login + +from authentication.cas.client import client +from authentication.models import User +from authentication.signals import user_created, user_login from django.contrib.auth import login +from django.contrib.auth.models import update_last_login from rest_framework.serializers import ( CharField, EmailField, + HyperlinkedRelatedField, ModelSerializer, - ValidationError, Serializer, - HyperlinkedIdentityField, - HyperlinkedRelatedField, + ValidationError, ) -from rest_framework_simplejwt.tokens import RefreshToken, AccessToken from rest_framework_simplejwt.settings import api_settings -from authentication.signals import user_created, user_login -from authentication.models import User, Faculty -from authentication.cas.client import client +from rest_framework_simplejwt.tokens import AccessToken, RefreshToken class CASTokenObtainSerializer(Serializer): @@ -22,6 +22,7 @@ class CASTokenObtainSerializer(Serializer): This serializer takes the CAS ticket and tries to validate it. Upon successful validation, create a new user if it doesn't exist. """ + ticket = CharField(required=True, min_length=49, max_length=49) def validate(self, data): @@ -40,23 +41,15 @@ def validate(self, data): if "request" in self.context: login(self.context["request"], user) - user_login.send( - sender=self, user=user - ) + user_login.send(sender=self, user=user) if created: - user_created.send( - sender=self, attributes=attributes, user=user - ) + user_created.send(sender=self, attributes=attributes, user=user) # Return access tokens for the now logged-in user. return { - "access": str( - AccessToken.for_user(user) - ), - "refresh": str( - RefreshToken.for_user(user) - ), + "access": str(AccessToken.for_user(user)), + "refresh": str(RefreshToken.for_user(user)), } def _validate_ticket(self, ticket: str) -> dict: @@ -102,7 +95,7 @@ class UserSerializer(ModelSerializer): many=True, read_only=True, view_name="faculty-detail" ) - notifications = HyperlinkedIdentityField( + notifications = HyperlinkedRelatedField( view_name="notification-detail", read_only=True, ) diff --git a/backend/notifications/urls.py b/backend/notifications/urls.py index 142fde10..e80acd66 100644 --- a/backend/notifications/urls.py +++ b/backend/notifications/urls.py @@ -2,5 +2,5 @@ from notifications.views import NotificationView urlpatterns = [ - path("/", NotificationView.as_view()), + path("/", NotificationView.as_view(), name="notification-detail"), ] diff --git a/backend/ypovoli/urls.py b/backend/ypovoli/urls.py index 25e30a72..f3093cdc 100644 --- a/backend/ypovoli/urls.py +++ b/backend/ypovoli/urls.py @@ -14,10 +14,11 @@ 1. Import the include() function: from django.urls import include, path 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ -from django.urls import path, include -from rest_framework import permissions -from drf_yasg.views import get_schema_view + +from django.urls import include, path from drf_yasg import openapi +from drf_yasg.views import get_schema_view +from rest_framework import permissions schema_view = get_schema_view( openapi.Info( @@ -25,7 +26,9 @@ default_version="v1", ), public=True, - permission_classes=[permissions.AllowAny,], + permission_classes=[ + permissions.AllowAny, + ], ) @@ -34,8 +37,14 @@ path("", include("api.urls")), # Authentication endpoints. path("auth/", include("authentication.urls")), - path("notifications/", include("notifications.urls")), + path("notifications/", include("notifications.urls"), name="notifications"), # Swagger documentation. - path("swagger/", schema_view.with_ui("swagger", cache_timeout=0), name="schema-swagger-ui"), - path("swagger/", schema_view.without_ui(cache_timeout=0), name="schema-json"), + path( + "swagger/", + schema_view.with_ui("swagger", cache_timeout=0), + name="schema-swagger-ui", + ), + path( + "swagger/", schema_view.without_ui(cache_timeout=0), name="schema-json" + ), ]