Exemplo n.º 1
0
 def test_update_someone_else(self):
     user = UserFactory()
     user2 = UserFactory()
     self.client.force_login(user)
     response = self.client.post(
         reverse('user-update', kwargs={'pk': user2.id}))
     self.assertEqual(response.status_code, 403)
Exemplo n.º 2
0
 def test_save_multi(self):
     user1 = UserFactory(email='*****@*****.**')
     UserFactory(email='*****@*****.**')
     data = {'email': user1.email}
     request = self.request_factory.post(reverse('password-reset'), data=data)
     form = PasswordResetForm(data=data)
     self.assertTrue(form.is_valid())
     form.save(request=request)
     self.assertEqual(len(mail.outbox), 2)
Exemplo n.º 3
0
 def test_unusable_password(self):
     user = UserFactory()
     data = {"email": user.email}
     form = PasswordResetForm(data)
     self.assertTrue(form.is_valid())
     user.set_unusable_password()
     user.save()
     form = PasswordResetForm(data)
     # The form itself is valid, but no email is sent
     self.assertTrue(form.is_valid())
     form.save()
     self.assertEqual(len(mail.outbox), 0)
Exemplo n.º 4
0
    def test_invalid(self):
        # Empty
        data = {'email': ''}
        form = PasswordResetForm(data=data)
        self.assertFalse(form.is_valid())
        self.assertEqual('This field is required.', form.errors['email'][0])

        # Invalid
        data = {'email': '*****@*****.**'}
        form = PasswordResetForm(data=data)
        self.assertFalse(form.is_valid())
        self.assertEqual('Enter a valid email address', form.errors['email'][0])

        # Inactive
        user = UserFactory(is_active=False)
        data = {'email': user.email}
        form = PasswordResetForm(data=data)
        self.assertFalse(form.is_valid())
        self.assertEqual('Enter a valid email address', form.errors['email'][0])

        # Disabled password
        user = UserFactory()
        user.set_unusable_password()
        user.save()
        data = {'email': user.email}
        form = PasswordResetForm(data=data)
        self.assertFalse(form.is_valid())
        self.assertEqual('Enter a valid email address', form.errors['email'][0])
Exemplo n.º 5
0
 def test_get_update_when_anonymous(self):
     user = UserFactory()
     response = self.client.get(
         reverse('user-update', kwargs={'pk': user.id}))
     self.assertRedirects(
         response, "%s?next=%s" %
         (reverse('login'), reverse('user-update', kwargs={'pk': user.id})))
Exemplo n.º 6
0
 def test_matching_email(self):
     user = UserFactory()
     request = RequestFactory().post('/')
     url = PasswordResetForm().get_context_data(request, user)['url']
     msg = Email(body=url)
     email_url, path = (read_signup_email(msg))
     self.assertEqual(email_url, url)
Exemplo n.º 7
0
 def test_delete_anonymous(self):
     user2 = UserFactory()
     response = self.client.delete(
         reverse('user-delete', kwargs={'pk': user2.id}))
     self.assertRedirects(
         response,
         "%s?next=%s" % (reverse('login'),
                         reverse('user-delete', kwargs={'pk': user2.id})))
Exemplo n.º 8
0
 def test_update_self_invalid(self):
     user = UserFactory()
     self.client.force_login(user)
     response = self.client.post(reverse('user-update',
                                         kwargs={'pk': user.id}),
                                 data=self.invalid_data)
     self.assertEqual(response.status_code, 200)
     self.assertFormError(response, 'form', 'email',
                          'Enter a valid email address.')
Exemplo n.º 9
0
 def setUp(self):
     self.user = UserFactory()
     self.valid_uidb64 = urlsafe_base64_encode(force_bytes(self.user.pk))
     self.valid_data = {
         'new_password1': 'newpwd',
         'new_password2': 'newpwd'
     }
     self.invalid_data = {
         'new_password1': 'newpwd',
         'new_password2': '1234'
     }
Exemplo n.º 10
0
 def test_token_generation(self):
     user = UserFactory()
     data = {'email': user.email}
     request = self.request_factory.post(reverse('password-reset'), data=data)
     reset_form = PasswordResetForm(data=data)
     self.assertTrue(reset_form.is_valid())
     context = reset_form.get_context_data(request, user, default_token_generator)
     uidb64, token = urlparse(context['url']).path.split('/')[-3:-1]
     self.assertIsNotNone(re.match("[0-9A-Za-z_\-]+", uidb64))
     self.assertIsNotNone(re.match("[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20}", token))
     self.assertEqual(urlsafe_base64_decode(uidb64).decode("utf-8"), str(user.id))
     self.assertTrue(default_token_generator.check_token(user, token))
Exemplo n.º 11
0
 def setUp(self):
     self.factory = RequestFactory()
     self.user = UserFactory()
     self.valid_data = {
         'old_password': '******',
         'new_password1': 'new',
         'new_password2': 'new'
     }
     self.invalid_data = {
         'old_password': '******',
         'new_password1': 'test',
         'new_password2': '1234'
     }
Exemplo n.º 12
0
 def test_update_self_valid(self):
     user = UserFactory()
     self.client.force_login(user)
     response = self.client.post(reverse('user-update',
                                         kwargs={'pk': user.id}),
                                 data=self.valid_data,
                                 follow=True)
     self.assertRedirects(response,
                          reverse('user-detail', kwargs={'pk': user.id}))
     self.assertEqual('User details updated',
                      list(response.context['messages'])[0].message)
     updated_user = User.objects.get(username=user.username)
     self.assertNotEqual(updated_user.first_name, user.first_name)
     self.assertNotEqual(updated_user.last_name, user.last_name)
     self.assertNotEqual(updated_user.email, user.email)
Exemplo n.º 13
0
 def setUp(self):
     self.factory = RequestFactory()
     self.user = UserFactory()
Exemplo n.º 14
0
 def test_get_delete_someone_else(self):
     user2 = UserFactory()
     self.client.force_login(self.user)
     response = self.client.get(
         reverse('user-delete', kwargs={'pk': user2.id}))
     self.assertEqual(response.status_code, 403)
Exemplo n.º 15
0
 def setUp(self):
     self.user = UserFactory()
Exemplo n.º 16
0
 def setUp(self):
     self.user = UserFactory()
     self.cell_type = CellTypeFactory()