Skip to content

Commit

Permalink
Added clearsessions management command
Browse files Browse the repository at this point in the history
  • Loading branch information
Bouke committed May 14, 2015
1 parent bb951ca commit 337da8d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
12 changes: 11 additions & 1 deletion tests/tests.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import timedelta
from datetime import datetime, timedelta
import sys
try:
from urllib.parse import urlencode
Expand All @@ -10,6 +10,7 @@
from django.contrib import auth
from django.contrib.auth.models import User
from django.contrib.sessions.backends.base import CreateError
from django.core.management import call_command
from django.core.urlresolvers import reverse
from django.db import IntegrityError
from django.test import TestCase
Expand Down Expand Up @@ -375,3 +376,12 @@ def test_chrome(self):
device('Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 ('
'KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36')
)


@skipUnless(django.VERSION >= (1, 5), "Django 1.5 and higher")
class ClearsessionsCommandTest(TestCase):
def test_can_call(self):
Session.objects.create(expire_date=datetime.now() - timedelta(days=1),
ip='127.0.0.1')
call_command('clearsessions')
self.assertEqual(Session.objects.count(), 0)
Empty file.
Empty file.
4 changes: 4 additions & 0 deletions user_sessions/management/commands/clearsessions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
try:
from django.contrib.sessions.management.commands.clearsessions import Command # flake8: noqa
except ImportError:
pass # not supported on Django 1.4

0 comments on commit 337da8d

Please sign in to comment.