Exemplo n.º 1
0
class SignInFormTests(TestCase):
    def setUp(self):
        self.password = "******"
        self.user = UserFactory()
        self.user.set_password(self.password)
        self.user.save()

    def test_sign_in_success(self):
        form = SignInForm({
            "email": self.user.email,
            "password": self.password,
        })
        self.assertTrue(form.is_valid())

    def test_sign_in_error_password(self):
        form = SignInForm({
            "email": self.user.email,
            "password": "******",
        })
        self.assertFalse(form.is_valid())

    def test_sign_in_error_email(self):
        form = SignInForm({
            "email": '*****@*****.**',
            "password": self.password,
        })
        self.assertFalse(form.is_valid())
Exemplo n.º 2
0
class SignInViewTests(TestCase):
    def setUp(self):
        reload_urlconf()
        self.password = "******"
        self.user = UserFactory()
        self.user.set_password(self.password)
        self.user.save()

    def _authenticate(self):
        self.client.login(
            email=self.user.email,
            password=self.password,
            is_validate=True,
        )

    def test_show_sign_in_form(self):
        response = self.client.get(reverse('users:sign-in'))
        self.assertEqual(response.status_code, 200)

    def test_redirect_sign_in_form(self):
        self._authenticate()
        response = self.client.get(reverse('users:sign-in'))
        self.assertRedirects(response,
                             reverse('home'),
                             status_code=302,
                             target_status_code=200)

    def test_sign_out(self):
        self._authenticate()
        response = self.client.get(reverse('users:sign-out'))
        self.assertRedirects(response,
                             reverse('home'),
                             status_code=302,
                             target_status_code=200)

    def test_post_sign_in_form(self):
        data = {
            "email": self.user.email,
            "password": self.password,
        }
        response = self.client.post(reverse('users:sign-in'), data=data)
        self.assertRedirects(response,
                             reverse('home'),
                             status_code=302,
                             target_status_code=200)

    def test_post_sign_in_form_bad_password(self):
        data = {
            "email": self.user.email,
            "password": "******",
        }
        response = self.client.post(reverse('users:sign-in'), data=data)
        self.assertEqual(response.status_code, 200)
Exemplo n.º 3
0
class RestorePasswordFormTests(TestCase):
    def setUp(self):
        self.user = UserFactory()
        self.user.generate_restore_code()

    def test_restore_code_success(self):
        form = RestorePasswordForm({
            "email": self.user.email,
            "restore_code": self.user.restore_code,
            "password": "******",
            "repeat_password": "******",
        })
        self.assertTrue(form.is_valid())
Exemplo n.º 4
0
 def test_create_post(self):
     prev_posts = Post.objects.count()
     Post.objects.create(author=UserFactory(),
                         content="foo",
                         title="Title",
                         slug="Title")
     self.assertEqual(prev_posts + 1, Post.objects.count())
Exemplo n.º 5
0
 def test_reviewer_signup_existing(self):
     user = UserFactory()
     data = {"email": user.email}
     form = ReviewerSignUpForm(data)
     self.assertTrue(form.is_valid())
     user = form.save()
     self.assertIn(REVIEW_GROUP_NAME,
                   user.groups.all().values_list("name", flat=True))
Exemplo n.º 6
0
 def test_blog_details(self):
     post = Post.objects.create(author=UserFactory(),
                                title="Title",
                                slug="slug",
                                status=PUBLISHED)
     response = self.client.get(
         reverse('blog:post', kwargs={'slug': post.slug}))
     self.assertEqual(response.status_code, 200)
Exemplo n.º 7
0
 def test_more(self):
     original_summary = "part1"
     post = Post.objects.create(
         author=UserFactory(),
         content="{}<!--more-->more".format(original_summary),
         title="Title",
         slug="Title")
     summary = post.summary()
     self.assertEqual(
         summary,
         '{}<p><a href="/es/blog/title/">Seguir leyendo...</a></p>'.format(
             original_summary))
Exemplo n.º 8
0
class RequestRestoreCodeViewTests(TestCase):
    def setUp(self):
        reload_urlconf()
        self.user = UserFactory()
        self.user.save()

    def test_get_request_restore_code_form(self):
        response = self.client.get(reverse('users:request-restore-password'))
        self.assertEqual(response.status_code, 200)

    def test_post_request_request_restore_code(self):
        data = {"email": self.user.email}
        response = self.client.post(reverse('users:request-restore-password'),
                                    data=data)
        self.assertEquals(response.status_code, 200)

    def test_post_request_request_restore_code_bad_email(self):
        data = {"email": "*****@*****.**"}
        response = self.client.post(reverse('users:request-restore-password'),
                                    data=data)
        self.assertRedirects(response,
                             reverse('users:request-restore-password'),
                             status_code=302,
                             target_status_code=200)
Exemplo n.º 9
0
 def setUp(self):
     reload_urlconf()
     self.user = UserFactory()
     self.user.generate_restore_code()
Exemplo n.º 10
0
class RestorePasswordViewTests(TestCase):
    def setUp(self):
        reload_urlconf()
        self.user = UserFactory()
        self.user.generate_restore_code()

    def test_get_restore_password_form(self):
        response = self.client.get(
            reverse('users:restore-password',
                    kwargs={"restore_code": self.user.restore_code}))
        self.assertEqual(response.status_code, 200)

    def test_post_restore_password_form(self):
        data = {
            "email": self.user.email,
            "restore_code": self.user.restore_code,
            "password": "******",
            "repeat_password": "******",
        }
        response = self.client.post(reverse(
            'users:restore-password',
            kwargs={"restore_code": self.user.restore_code}),
                                    data=data)
        self.assertRedirects(response,
                             reverse('users:sign-in'),
                             status_code=302,
                             target_status_code=200)

    def test_post_restore_password_form_bad_code(self):
        data = {
            "email": self.user.email,
            "restore_code": "bad",
            "password": "******",
            "repeat_password": "******",
        }
        response = self.client.post(reverse(
            'users:restore-password',
            kwargs={"restore_code": self.user.restore_code}),
                                    data=data)
        self.assertEqual(response.status_code, 200)

    def test_post_restore_password_form_bad_password(self):
        data = {
            "email": self.user.email,
            "restore_code": self.user.restore_code,
            "password": "******",
            "repeat_password": "******",
        }
        response = self.client.post(reverse(
            'users:restore-password',
            kwargs={"restore_code": self.user.restore_code}),
                                    data=data)
        self.assertEqual(response.status_code, 200)

    def test_post_restore_password_form_bad_email(self):
        data = {
            "email": "*****@*****.**",
            "restore_code": self.user.restore_code,
            "password": "******",
            "repeat_password": "******",
        }
        response = self.client.post(reverse(
            'users:restore-password',
            kwargs={"restore_code": self.user.restore_code}),
                                    data=data)
        self.assertEqual(response.status_code, 200)
Exemplo n.º 11
0
 def setUp(self):
     reload_urlconf()
     self.user = UserFactory()
     self.user.save()
Exemplo n.º 12
0
 def setUp(self):
     reload_urlconf()
     self.password = "******"
     self.user = UserFactory()
     self.user.set_password(self.password)
     self.user.save()
Exemplo n.º 13
0
 def test_blog_atom(self):
     PostFactory.create_batch(size=5, author=UserFactory())
     response = self.client.get(reverse('blog:blog_atom'))
     self.assertEqual(response.status_code, 200)
Exemplo n.º 14
0
 def test_create_slug(self):
     post = PostFactory(author=UserFactory())
     post.save()
     self.assertEqual(post.slug, slugify(post.title))
Exemplo n.º 15
0
 def setUp(self):
     self.user = UserFactory()
     group = Group.objects.get(name=REVIEW_GROUP_NAME)
     self.user.groups.add(group)
Exemplo n.º 16
0
 def setUp(self):
     self.password = "******"
     self.user = UserFactory()
     self.user.set_password(self.password)
     self.user.save()
Exemplo n.º 17
0
 def setUp(self):
     self.user = UserFactory()
Exemplo n.º 18
0
 def setUp(self):
     self.user = UserFactory()
     self.user.generate_restore_code()