Exemplo n.º 1
0
 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)
Exemplo n.º 2
0
 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)
Exemplo n.º 3
0
 def setUp(self):
     email = '*****@*****.**'
     User.objects.create_user(username='******',
                              email=email,
                              password='******')
     url = reverse('password_reset')
     self.response = self.client.post(url, {'email': email})
Exemplo n.º 4
0
 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)
Exemplo n.º 5
0
    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)
Exemplo n.º 6
0
    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)
Exemplo n.º 7
0
 def test_redirection(self):
     '''
     A valid form submission should redirect the user
     '''
     self.assertRedirects(self.response, reverse('password_change_done'))
Exemplo n.º 8
0
 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}')
Exemplo n.º 9
0
 def setUp(self):
     url = reverse('password_reset_done')
     self.response = self.client.get(url)
Exemplo n.º 10
0
 def setUp(self):
     url = reverse('password_reset')
     self.response = self.client.post(url,
                                      {'email': '*****@*****.**'})
Exemplo n.º 11
0
 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)
Exemplo n.º 12
0
 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))