Skip to content

Commit

Permalink
Merge pull request #39 from Kirill-Lekhov/feature/add-xauth-logout
Browse files Browse the repository at this point in the history
Add logout view to the django_xauth
  • Loading branch information
m1kc authored Apr 24, 2024
2 parents ac136e2 + f59cb33 commit 08d9585
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
3 changes: 2 additions & 1 deletion notalib/django_xauth/urls.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .views import DirtyHackAuthCheckViewSet, auth_view
from .views import DirtyHackAuthCheckViewSet, auth_view, logout_view

from django.urls import path, include
from rest_framework import routers
Expand All @@ -9,5 +9,6 @@

urlpatterns = [
path('auth-post', auth_view),
path('logout', logout_view),
path('', include(router.urls)),
]
8 changes: 7 additions & 1 deletion notalib/django_xauth/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from .serializers import NothingSerializer

from django.http import HttpResponse
from django.contrib.auth import authenticate, login
from django.contrib.auth import authenticate, login, logout
from django.views.decorators.csrf import csrf_exempt
from rest_framework import viewsets
from rest_framework.decorators import renderer_classes
Expand All @@ -28,6 +28,12 @@ def auth_view(request):
return HttpResponse('{"result": "fail"}', status=403)


@csrf_exempt
def logout_view(request):
logout(request)
return HttpResponse('{"result": "ok"}', status=200)


@renderer_classes([JSONRenderer])
class DirtyHackAuthCheckViewSet(viewsets.ReadOnlyModelViewSet):
queryset = Nothing.objects.none()
Expand Down
14 changes: 13 additions & 1 deletion notalib/django_xauth/views_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from notalib.django_xauth.views import auth_view
from notalib.django_xauth.views import auth_view, logout_view
from notalib.test_fakes import FakeFunction

from unittest.mock import patch
Expand Down Expand Up @@ -29,3 +29,15 @@ def test_auth_view():
assert fake_login.last_call_args[1] == "USER INSTANCE"
assert response.status_code == 200
assert response.content == b'{"result": "ok"}'


def test_logout_view():
request = HttpRequest()
fake_logout = FakeFunction()

with patch("notalib.django_xauth.views.logout", new=fake_logout):
response = logout_view(request)
assert fake_logout.call_count == 1
assert fake_logout.last_call_args[0] is request
assert response.status_code == 200
assert response.content == b'{"result": "ok"}'
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "notalib"
version = "2.2.0"
version = "2.2.1-rc0"
description = "A collection of utility functions & classes"
authors = ["m1kc (Max Musatov) <[email protected]>"]
license = "MIT"
Expand Down

0 comments on commit 08d9585

Please sign in to comment.