def setUp(self, data={}): self.user = User.objects.create_user(username='******', email='*****@*****.**', password='******') self.url = reverse('password_change') self.client.login(username='******', password='******') self.response = self.client.post(self.url, data)
def test_redirection(self): ''' Even invalid emails in the database should redirect the user to `password_reset_done` view ''' url = reverse('password_reset_done') self.assertRedirects(self.response, url)
def setUp(self): email = '*****@*****.**' User.objects.create_user(username='******', email=email, password='******') url = reverse('password_reset') self.response = self.client.post(url, {'email': email})
def test_user_authentication(self): ''' Create a new request to an arbitrary page. The resulting response should now have an `user` to its context, after a successful sign up. ''' response = self.client.get(reverse('home')) user = response.context.get('user') self.assertTrue(user.is_authenticated)
def setUp(self): user = User.objects.create_user(username='******', email='*****@*****.**', password='******') ''' create a valid password reset token based on how django creates the token internally: https://github.com/django/django/blob/1.11.5/django/contrib/auth/forms.py#L280 ''' self.uid = urlsafe_base64_encode(force_bytes(user.pk)).decode() self.token = default_token_generator.make_token(user) url = reverse('password_reset_confirm', kwargs={ 'uidb64': self.uid, 'token': self.token }) self.response = self.client.get(url, follow=True)
def setUp(self): user = User.objects.create_user(username='******', email='*****@*****.**', password='******') uid = urlsafe_base64_encode(force_bytes(user.pk)).decode() token = default_token_generator.make_token(user) ''' invalidate the token by changing the password ''' user.set_password('abcdef123') user.save() url = reverse('password_reset_confirm', kwargs={ 'uidb64': uid, 'token': token }) self.response = self.client.get(url)
def test_redirection(self): ''' A valid form submission should redirect the user ''' self.assertRedirects(self.response, reverse('password_change_done'))
def test_redirection(self): url = reverse('password_change') login_url = reverse('login') response = self.client.get(url) self.assertRedirects(response, f'{login_url}?next={url}')
def setUp(self): url = reverse('password_reset_done') self.response = self.client.get(url)
def setUp(self): url = reverse('password_reset') self.response = self.client.post(url, {'email': '*****@*****.**'})
def test_redirection(self): ''' A valid form submission should redirect the user to `password_reset_done` view ''' url = reverse('password_reset_done') self.assertRedirects(self.response, url)
def test_html(self): password_reset_url = reverse('password_reset') self.assertContains(self.response, 'invalid password reset link') self.assertContains(self.response, 'href="{0}"'.format(password_reset_url))