WIP: active-sessions #93586

Closed
Oleg-Komarov wants to merge 3 commits from active-sessions into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
2 changed files with 31 additions and 1 deletions
Showing only changes of commit 8b835ab870 - Show all commits

View File

@ -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

View 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)