Ejemplo n.º 1
0
    def test_delete(self):
        comment = CommentFactory()

        # anonymous
        resp = self.app.get('/comment/{}/delete/'.format(comment.id),
                            HTTP_REFERER='/material/news/1/')
        self.assertEqual(resp.status_code, 403)
        self.assertTrue(Comment.objects.active().exists())

        # auth user
        user = UserFactory(username='******')
        user.set_password('secret')
        user.save()
        self.app.login(username='******', password='******')

        resp = self.app.get('/comment/{}/delete/'.format(comment.id),
                            HTTP_REFERER='/material/news/1/')
        self.assertEqual(resp.status_code, 403)
        self.assertTrue(Comment.objects.active().exists())

        # admin
        user.is_staff = True
        user.save()
        resp = self.app.get('/comment/{}/delete/'.format(comment.id),
                            HTTP_REFERER='/material/news/1/')
        self.assertEqual(resp.status_code, 302)
        self.assertEqual(resp.url, '/material/news/1/')
        self.assertFalse(Comment.objects.active().exists())
Ejemplo n.º 2
0
    def test_create_vote_user(self):
        user = UserFactory(username='******')
        user.set_password('secret')
        user.save()
        self.app.login(username='******', password='******')

        poll = PollFactory()
        choice = ChoiceFactory(poll=poll)
        resp = self.app.post('/polls/', {'poll_id': poll.id, 'choices': choice.id})
        self.assertEqual(resp.status_code, 302)
        self.assertEqual(resp.url, '/polls/{}/'.format(poll.id))

        votes = Vote.objects.all()
        self.assertEqual(len(votes), 1)
        self.assertEqual(votes[0].content_object, choice)

        choice.refresh_from_db()
        self.assertEqual(choice.vote_count, 1)
        poll.refresh_from_db()
        self.assertEqual(poll.sum_votes, 1)

        # try again: has no effect
        resp = self.app.post('/polls/', {'poll_id': poll.id, 'choices': choice.id})
        self.assertEqual(resp.status_code, 302)
        self.assertEqual(Vote.objects.count(), 1)

        choice.refresh_from_db()
        self.assertEqual(choice.vote_count, 1)
        poll.refresh_from_db()
        self.assertEqual(poll.sum_votes, 1)
Ejemplo n.º 3
0
    def test_redirect_auth_user(self):
        user = UserFactory(username='******')
        user.set_password('secret')
        user.save()
        self.app.login(username='******', password='******')

        resp = self.app.get('/login/')
        self.assertEqual(resp.status_code, 302)
Ejemplo n.º 4
0
    def test_login(self):
        user = UserFactory(username='******')
        user.set_password('secret')
        user.save()

        data = {
            'username': '******',
            'password': '******',
            'captcha_0': '*',
            'captcha_1': 'passed'
        }
        resp = self.app.post('/login/?next=/forum/', data)
        self.assertEqual(resp.status_code, 302)
        self.assertEqual(resp.url, '/forum/')
Ejemplo n.º 5
0
    def test_create_vote_comment_user(self):
        comment = CommentFactory()

        user = UserFactory(username='******')
        user.set_password('secret')
        user.save()
        self.app.login(username='******', password='******')

        resp = self.app.post('/votes/comment/', {
            'object_id': comment.id,
            'score': 1
        },
                             HTTP_REFERER='/material/news/1/')
        self.assertEqual(resp.status_code, 302)
        self.assertEqual(resp.url, '/material/news/1/')

        votes = Vote.objects.all()
        self.assertEqual(len(votes), 1)
        self.assertEqual(votes[0].user, user)
        self.assertEqual(votes[0].object_id, comment.id)
        self.assertEqual(votes[0].score, 1)
Ejemplo n.º 6
0
    def test_login_fail(self):
        user = UserFactory(username='******')
        user.set_password('secret')
        user.save()

        data = {
            'username': '******',
            'password': '******',
            'captcha_0': '*',
            'captcha_1': 'passed'
        }
        resp = self.app.post('/login/', data)
        self.assertEqual(resp.status_code, 200)
        self.assertIn('введите правильные имя пользователя и пароль',
                      resp.context['form'].errors['__all__'][0])
        self.assertContains(resp,
                            'введите правильные имя пользователя и пароль')

        data = {'password': '******', 'captcha_0': '*', 'captcha_1': 'passed'}
        resp = self.app.post('/login/', data)
        self.assertEqual(resp.status_code, 200)
        self.assertContains(resp, 'Обязательное поле')
Ejemplo n.º 7
0
    def test_update_vote_article_user(self):
        article = ArticleFactory()

        user = UserFactory(username='******')
        user.set_password('secret')
        user.save()
        self.app.login(username='******', password='******')

        VoteFactory(content_object=article, score=2, user=user)

        resp = self.app.post('/votes/article/', {
            'object_id': article.id,
            'score': 3
        },
                             HTTP_REFERER='/material/news/1/')
        self.assertEqual(resp.status_code, 302)
        self.assertEqual(resp.url, '/material/news/1/')

        votes = Vote.objects.all()
        self.assertEqual(len(votes), 1)
        self.assertEqual(votes[0].user, user)
        self.assertEqual(votes[0].object_id, article.id)
        self.assertEqual(votes[0].score, 3)