Skip to content

Commit 16cd9d2

Browse files
authored
Merge pull request EGCETSII#25 from Decide-Part-Rota/Rota3-004
Feat: Test logout with email and getuser witl email
2 parents b7f798b + b178960 commit 16cd9d2

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

decide/authentication/templates/registration/login.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@ <h1>Iniciar sesión</h1>
2121
<tbody>
2222
<tr>
2323
<th scope="row">Usuario o email </th>
24-
<td><input type="text" name="username"></td>
24+
<td><input id="id_username" type="text" name="username"></td>
2525
</tr>
2626
<tr>
2727
<th scope="row">Contraseña</th>
28-
<td><input type="password" name="password"></td>
28+
<td><input id="id_password" type="password" name="password"></td>
2929
</tr>
3030
</tbody>
3131
</table>
3232

33-
<button type="submit" class="btn btn-outline-dark">Iniciar sesión</button>
33+
<button id="id_button" type="submit" class="btn btn-outline-dark">Iniciar sesión</button>
3434
<a href="/authentication/registerForm/">Registrarse</a>
3535

3636
<br><br>

decide/authentication/templates/welcome.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<link type="text/css" rel="stylesheet" href="https://unpkg.com/bootstrap/dist/css/bootstrap.min.css" />
66

77
<link type="text/css" rel="stylesheet" href="https://unpkg.com/bootstrap-vue@latest/dist/bootstrap-vue.css" />
8+
<title>Welcome</title>
89
{% endblock %}
910

1011
{% block content %}

decide/authentication/tests.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,32 @@ def test_login_with_email_fail(self):
158158
response = self.client.post('/authentication/login/', data, format='json')
159159
self.assertEqual(response.status_code, 400)
160160

161+
def test_logout_with_email(self):
162+
data = {'username': '[email protected]', 'password': '123'}
163+
response = self.client.post('/authentication/login/', data, format='json')
164+
self.assertEqual(response.status_code, 200)
165+
166+
token = response.json()
167+
self.assertTrue(token.get('token'))
168+
169+
response = self.client.post('/authentication/logout/', token, format='json')
170+
self.assertEqual(response.status_code, 200)
171+
172+
self.assertEqual(Token.objects.filter(user__username='voter1').count(), 0)
173+
174+
def test_getuser_with_email(self):
175+
data = {'username': '[email protected]', 'password': '123'}
176+
response = self.client.post('/authentication/login/', data, format='json')
177+
self.assertEqual(response.status_code, 200)
178+
token = response.json()
179+
180+
response = self.client.post('/authentication/getuser/', token, format='json')
181+
self.assertEqual(response.status_code, 200)
182+
183+
user = response.json()
184+
self.assertEqual(user['id'], 7)
185+
self.assertEqual(user['username'], 'voter1')
186+
161187

162188
class RegisterTestCase(StaticLiveServerTestCase):
163189

0 commit comments

Comments
 (0)