Skip to content

Commit

Permalink
Merge pull request EGCETSII#25 from Decide-Part-Rota/Rota3-004
Browse files Browse the repository at this point in the history
Feat: Test logout with email and getuser witl email
  • Loading branch information
MRomalde authored Dec 13, 2022
2 parents b7f798b + b178960 commit 16cd9d2
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
6 changes: 3 additions & 3 deletions decide/authentication/templates/registration/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ <h1>Iniciar sesión</h1>
<tbody>
<tr>
<th scope="row">Usuario o email </th>
<td><input type="text" name="username"></td>
<td><input id="id_username" type="text" name="username"></td>
</tr>
<tr>
<th scope="row">Contraseña</th>
<td><input type="password" name="password"></td>
<td><input id="id_password" type="password" name="password"></td>
</tr>
</tbody>
</table>

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

<br><br>
Expand Down
1 change: 1 addition & 0 deletions decide/authentication/templates/welcome.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<link type="text/css" rel="stylesheet" href="https://unpkg.com/bootstrap/dist/css/bootstrap.min.css" />

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

{% block content %}
Expand Down
26 changes: 26 additions & 0 deletions decide/authentication/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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': '[email protected]', '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': '[email protected]', '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):

Expand Down

0 comments on commit 16cd9d2

Please sign in to comment.