From b705da3be9aa4ef42dd8407c27d5f44d633ea0bc Mon Sep 17 00:00:00 2001 From: Rohan Rangray Date: Tue, 5 May 2015 03:53:09 -0700 Subject: [PATCH] Added a password reset test. --- flashcards/tests/test_api.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/flashcards/tests/test_api.py b/flashcards/tests/test_api.py index 98115e8..5fe4d09 100644 --- a/flashcards/tests/test_api.py +++ b/flashcards/tests/test_api.py @@ -2,6 +2,7 @@ from django.core import mail from flashcards.models import User from rest_framework.status import HTTP_201_CREATED, HTTP_200_OK, HTTP_401_UNAUTHORIZED from rest_framework.test import APITestCase +from re import search class LoginTests(APITestCase): @@ -47,6 +48,28 @@ class LoginTests(APITestCase): # since we're not logged in, we shouldn't be able to see this self.assertEqual(response.status_code, HTTP_401_UNAUTHORIZED) +class PasswordResetTest(APITestCase): + def setUp(self): + email = "test@flashy.cards" + User.objects.create_user(email=email, password="12345") + + def reset_password(self): + url = '/api/reset_password' + post_data = {'email': 'test@flashy.cards'} + patch_data = {'new_password': '54321', + 'uid': '', 'token': ''} + self.client.post(url, post_data, format='json') + self.assertEqual(len(mail.outbox), 1) + self.assertIn('reset your password', mail.outbox[0].body) + + capture = search('https://flashy.cards/app/reset_password/(\d+)/(.*)', + mail.outbox[0].body) + data['uid'] = capture.group(0) + data['token'] = capture.group(1) + self.client.patch(url, patch_data, format='json') + user = User.objects.get(id=data['uid']) + assert user.check_password(data['new_password']) + class RegistrationTest(APITestCase): def test_create_account(self): @@ -149,4 +172,4 @@ class DeleteUserTest(APITestCase): self.client.login(email='none@none.com', password='1234') self.client.delete(url) - self.assertFalse(User.objects.filter(email='none@none.com').exists()) \ No newline at end of file + self.assertFalse(User.objects.filter(email='none@none.com').exists()) -- 1.9.1