WIP: active-sessions #93586
@ -21,7 +21,8 @@ Active Sessions
|
||||
<tr>
|
||||
<td title="{{ session.created_at }}">{{ session.created_at|naturaltime }}</td>
|
||||
<td>
|
||||
{% if session.location %}
|
||||
{# check ip to avoid triggering a geoip warning #}
|
||||
{% if session.ip and session.ip != '127.0.0.1' and session.location %}
|
||||
{{ session.location }}
|
||||
{% else %}
|
||||
Not detected
|
||||
|
29
bid_main/tests/test_sessions.py
Normal file
29
bid_main/tests/test_sessions.py
Normal file
@ -0,0 +1,29 @@
|
||||
import re
|
||||
|
||||
from django.test import TestCase
|
||||
from django.test.client import Client
|
||||
from django.urls import reverse
|
||||
|
||||
from bid_main.tests.factories import UserFactory
|
||||
|
||||
|
||||
class TestActiveSessions(TestCase):
|
||||
def test_active_sessions(self):
|
||||
user = UserFactory()
|
||||
client1 = Client()
|
||||
client2 = Client()
|
||||
client1.force_login(user)
|
||||
client2.force_login(user)
|
||||
response = client1.get(reverse('bid_main:active_sessions'))
|
||||
self.assertContains(response, 'Current Session')
|
||||
self.assertContains(response, 'Terminate Session')
|
||||
|
||||
key = re.search(r'name="session_key_hashed" value="(\w+)"', str(response.content)).group(1)
|
||||
response = client1.post(reverse('bid_main:terminate_session'), {'session_key_hashed': key})
|
||||
self.assertEqual(response.status_code, 302)
|
||||
response = client1.get(reverse('bid_main:active_sessions'))
|
||||
self.assertNotContains(response, 'Terminate Session')
|
||||
|
||||
# got logged out, redirect to login
|
||||
response = client2.get(reverse('bid_main:active_sessions'))
|
||||
self.assertEqual(response.status_code, 302)
|
Loading…
Reference in New Issue
Block a user