From b178960849de5940fb095b3130c2199e65008c6c Mon Sep 17 00:00:00 2001 From: MRomalde Date: Tue, 13 Dec 2022 14:26:56 +0100 Subject: [PATCH] Feat: Test logout with email and getuser witl email --- .../templates/registration/login.html | 6 ++--- decide/authentication/templates/welcome.html | 1 + decide/authentication/tests.py | 26 +++++++++++++++++++ 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/decide/authentication/templates/registration/login.html b/decide/authentication/templates/registration/login.html index abf21b0ca1..8ea1564414 100644 --- a/decide/authentication/templates/registration/login.html +++ b/decide/authentication/templates/registration/login.html @@ -21,16 +21,16 @@

Iniciar sesión

Usuario o email - + Contraseña - + - + Registrarse

diff --git a/decide/authentication/templates/welcome.html b/decide/authentication/templates/welcome.html index 71146f5e89..ff134924c4 100644 --- a/decide/authentication/templates/welcome.html +++ b/decide/authentication/templates/welcome.html @@ -5,6 +5,7 @@ + Welcome {% endblock %} {% block content %} diff --git a/decide/authentication/tests.py b/decide/authentication/tests.py index eeb7db3ded..6a3415abb9 100644 --- a/decide/authentication/tests.py +++ b/decide/authentication/tests.py @@ -158,6 +158,32 @@ def test_login_with_email_fail(self): response = self.client.post('/authentication/login/', data, format='json') self.assertEqual(response.status_code, 400) + def test_logout_with_email(self): + data = {'username': 'voter1@gmail.com', 'password': '123'} + response = self.client.post('/authentication/login/', data, format='json') + self.assertEqual(response.status_code, 200) + + token = response.json() + self.assertTrue(token.get('token')) + + response = self.client.post('/authentication/logout/', token, format='json') + self.assertEqual(response.status_code, 200) + + self.assertEqual(Token.objects.filter(user__username='voter1').count(), 0) + + def test_getuser_with_email(self): + data = {'username': 'voter1@gmail.com', 'password': '123'} + response = self.client.post('/authentication/login/', data, format='json') + self.assertEqual(response.status_code, 200) + token = response.json() + + response = self.client.post('/authentication/getuser/', token, format='json') + self.assertEqual(response.status_code, 200) + + user = response.json() + self.assertEqual(user['id'], 7) + self.assertEqual(user['username'], 'voter1') + class RegisterTestCase(StaticLiveServerTestCase):