Skip to content

Commit

Permalink
fix mock
Browse files Browse the repository at this point in the history
  • Loading branch information
SKairinos committed Sep 29, 2023
1 parent 425410f commit 9fba8a8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
12 changes: 6 additions & 6 deletions backend/api/tests/test_views.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from unittest.mock import Mock, patch
from unittest.mock import patch

import pyotp
from codeforlife.tests import CronTestCase
from codeforlife.user.models import AuthFactor, User
from django.core import management
from django.test import TestCase
from django.urls import reverse
from django.utils import timezone
Expand Down Expand Up @@ -48,8 +49,7 @@ def test_post__otp(self):


class TestClearExpiredView(CronTestCase):
@patch("django.core.management.call_command")
def test_clear_expired_view(self, call_command: Mock):
self.client.get(reverse("clear-expired-sessions"))

call_command.assert_called_once_with("clearsessions")
def test_clear_expired_view(self):
with patch.object(management, "call_command") as call_command:
self.client.get(reverse("clear-expired-sessions"))
call_command.assert_called_once_with("clearsessions")
4 changes: 2 additions & 2 deletions backend/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from django.contrib.auth import login
from django.contrib.auth.views import LoginView as _LoginView
from django.contrib.sessions.models import Session, SessionManager
from django.core.management import call_command
from django.core import management
from django.http import JsonResponse
from rest_framework import status
from rest_framework.response import Response
Expand Down Expand Up @@ -82,7 +82,7 @@ def get(self, request):

# Clears expired sessions.
# https://docs.djangoproject.com/en/3.2/ref/django-admin/#clearsessions
call_command("clearsessions")
management.call_command("clearsessions")

after_session_count = session_objects.count()
logging.info(f"Session count after clearance: {after_session_count}")
Expand Down

0 comments on commit 9fba8a8

Please sign in to comment.