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())
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)
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())
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())
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))
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)
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))
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)
def setUp(self): reload_urlconf() self.user = UserFactory() self.user.generate_restore_code()
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)
def setUp(self): reload_urlconf() self.user = UserFactory() self.user.save()
def setUp(self): reload_urlconf() self.password = "******" self.user = UserFactory() self.user.set_password(self.password) self.user.save()
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)
def test_create_slug(self): post = PostFactory(author=UserFactory()) post.save() self.assertEqual(post.slug, slugify(post.title))
def setUp(self): self.user = UserFactory() group = Group.objects.get(name=REVIEW_GROUP_NAME) self.user.groups.add(group)
def setUp(self): self.password = "******" self.user = UserFactory() self.user.set_password(self.password) self.user.save()
def setUp(self): self.user = UserFactory()
def setUp(self): self.user = UserFactory() self.user.generate_restore_code()