当前位置: 首页>>代码示例>>Python>>正文


Python tests.post函数代码示例

本文整理汇总了Python中sumo.tests.post函数的典型用法代码示例。如果您正苦于以下问题:Python post函数的具体用法?Python post怎么用?Python post使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了post函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: common_vote

    def common_vote(self):
        """Helper method for question vote tests."""
        # Check that there are no votes and vote form renders
        response = get(self.client, 'questions.answers',
                       args=[self.question.id])
        doc = pq(response.content)
        eq_('0 people', doc('div.have-problem mark')[0].text)
        eq_(1, len(doc('div.me-too form')))

        # Vote
        post(self.client, 'questions.vote', args=[self.question.id])

        # Check that there is 1 vote and vote form doesn't render
        response = get(self.client, 'questions.answers',
                       args=[self.question.id])
        doc = pq(response.content)
        eq_('1 person', doc('div.have-problem mark')[0].text)
        eq_(0, len(doc('div.me-too form')))

        # Voting again (same user) should not increment vote count
        post(self.client, 'questions.vote', args=[self.question.id])
        response = get(self.client, 'questions.answers',
                       args=[self.question.id])
        doc = pq(response.content)
        eq_('1 person', doc('div.have-problem mark')[0].text)
开发者ID:MechanisM,项目名称:kitsune,代码行数:25,代码来源:test_templates.py

示例2: test_solution_notification

    def test_solution_notification(self, get_current):
        """Assert that hitting the watch toggle toggles and that proper mails
        are sent to anonymous and registered watchers."""
        # TODO: Too monolithic. Split this test into several.
        get_current.return_value.domain = 'testserver'

        question = self._toggle_watch_question('solution', turn_on=True)
        QuestionSolvedEvent.notify('[email protected]', question)

        answer = question.answers.all()[0]
        # Post a reply
        self.client.login(username='jsocol', password='testpass')
        post(self.client, 'questions.solution', args=[question.id, answer.id])

        # Order of emails is not important.
        attrs_eq(mail.outbox[0], to=['[email protected]'],
                 subject='Solution found to Firefox Help question')
        starts_with(mail.outbox[0].body, SOLUTION_EMAIL % answer.id)

        attrs_eq(mail.outbox[1], to=['[email protected]'],
                 subject='Solution found to Firefox Help question')
        starts_with(mail.outbox[1].body,
                    SOLUTION_EMAIL_TO_ANONYMOUS % answer.id)

        self._toggle_watch_question('solution', turn_on=False)
开发者ID:Akamad007,项目名称:kitsune,代码行数:25,代码来源:test_notifications.py

示例3: common_answer_vote

    def common_answer_vote(self):
        """Helper method for answer vote tests."""
        # Check that there are no votes and vote form renders
        response = get(self.client, 'questions.answers',
                       args=[self.question.id])
        doc = pq(response.content)
        eq_(1, len(doc('form.helpful input[name="helpful"]')))

        # Vote
        post(self.client, 'questions.answer_vote', {'helpful': 'y'},
             args=[self.question.id, self.answer.id])

        # Check that there is 1 vote and vote form doesn't render
        response = get(self.client, 'questions.answers',
                       args=[self.question.id])
        doc = pq(response.content)

        eq_('1 out of 1 person', doc('#answer-1 div.helpful mark')[0].text)
        eq_(0, len(doc('form.helpful input[name="helpful"]')))

        # Voting again (same user) should not increment vote count
        post(self.client, 'questions.answer_vote', {'helpful': 'y'},
             args=[self.question.id, self.answer.id])
        doc = pq(response.content)
        eq_('1 out of 1 person', doc('#answer-1 div.helpful mark')[0].text)
开发者ID:MechanisM,项目名称:kitsune,代码行数:25,代码来源:test_templates.py

示例4: test_post_ratelimit

    def test_post_ratelimit(self):
        """Verify that rate limiting kicks in after 4 threads or replies."""
        d = document(save=True)
        u = user(save=True)
        self.client.login(username=u.username, password='testpass')

        # Create 2 threads:
        for i in range(2):
            response = post(self.client, 'wiki.discuss.new_thread',
                            {'title': 'Topic', 'content': 'hellooo'},
                            args=[d.slug])
            eq_(200, response.status_code)

        # Now 3 replies (only 2 should save):
        t = Thread.objects.all()[0]
        for i in range(3):
            response = post(self.client, 'wiki.discuss.reply',
                            {'content': 'hellooo'}, args=[d.slug, t.id])
            eq_(200, response.status_code)

        # And another thread that shouldn't save:
        response = post(self.client, 'wiki.discuss.new_thread',
                        {'title': 'Topic', 'content': 'hellooo'},
                        args=[d.slug])

        # We should only have 4 posts (each thread and reply creates a post).
        eq_(4, Post.objects.count())
开发者ID:DWDRAEGER,项目名称:kitsune,代码行数:27,代码来源:test_templates.py

示例5: test_autowatch_reply

    def test_autowatch_reply(self, get_current):
        """Replying to a thread creates a watch."""
        get_current.return_value.domain = 'testserver'

        u = user(save=True)
        t1 = thread(save=True)
        t2 = thread(save=True)

        assert not NewPostEvent.is_notifying(u, t1)
        assert not NewPostEvent.is_notifying(u, t2)

        self.client.login(username=u.username, password='testpass')

        # If the poster has the forums_watch_after_reply setting set to True,
        # they will start watching threads they reply to.
        s = Setting.objects.create(user=u, name='forums_watch_after_reply',
                                   value='True')
        data = {'content': 'some content'}
        post(self.client, 'forums.reply', data, args=[t1.forum.slug, t1.pk])
        assert NewPostEvent.is_notifying(u, t1)

        # Setting forums_watch_after_reply back to False, now they shouldn't
        # start watching threads they reply to.
        s.value = 'False'
        s.save()
        post(self.client, 'forums.reply', data, args=[t2.forum.slug, t2.pk])
        assert not NewPostEvent.is_notifying(u, t2)
开发者ID:Apokalyptica79,项目名称:kitsune,代码行数:27,代码来源:test_notifications.py

示例6: test_answer_creator_can_edit

    def test_answer_creator_can_edit(self):
        """The creator of an answer can edit his/her answer."""
        self.client.login(username='rrosario', password='testpass')

        # Initially there should be no edit links
        response = get(self.client, 'questions.answers',
                       args=[self.question.id])
        doc = pq(response.content)
        eq_(0, len(doc('ol.answers a.edit')))

        # Add an answer and verify the edit link shows up
        content = 'lorem ipsum dolor sit amet'
        response = post(self.client, 'questions.reply',
                        {'content': content},
                        args=[self.question.id])
        doc = pq(response.content)
        eq_(1, len(doc('ol.answers a.edit')))
        new_answer = self.question.answers.order_by('-created')[0]
        eq_(1, len(doc('#answer-%s a.edit' % new_answer.id)))

        # Make sure it can be edited
        content = 'New content for answer'
        response = post(self.client, 'questions.edit_answer',
                        {'content': content},
                        args=[self.question.id, new_answer.id])
        eq_(200, response.status_code)

        # Now lock it and make sure it can't be edited
        self.question.is_locked = True
        self.question.save()
        response = post(self.client, 'questions.edit_answer',
                        {'content': content},
                        args=[self.question.id, new_answer.id])
        eq_(403, response.status_code)
开发者ID:MechanisM,项目名称:kitsune,代码行数:34,代码来源:test_templates.py

示例7: common_answer_vote

    def common_answer_vote(self):
        """Helper method for answer vote tests."""
        # Check that there are no votes and vote form renders
        response = get(self.client, 'questions.answers',
                       args=[self.question.id])
        doc = pq(response.content)
        eq_(1, len(doc('form.helpful input[name="helpful"]')))

        # Vote
        ua = 'Mozilla/5.0 (DjangoTestClient)'
        self.client.post(reverse('questions.answer_vote',
                                 args=[self.question.id, self.answer.id]),
                         {'helpful': 'y'}, HTTP_USER_AGENT=ua)

        # Check that there is 1 vote and vote form doesn't render
        response = get(self.client, 'questions.answers',
                       args=[self.question.id])
        doc = pq(response.content)

        eq_('1 out of 1 person found this reply helpful',
            doc('#answer-1 span.helpful')[0].text.strip())
        eq_(0, len(doc('form.helpful input[name="helpful"]')))
        # Verify user agent
        vote_meta = VoteMetadata.objects.all()[0]
        eq_('ua', vote_meta.key)
        eq_(ua, vote_meta.value)

        # Voting again (same user) should not increment vote count
        post(self.client, 'questions.answer_vote', {'helpful': 'y'},
             args=[self.question.id, self.answer.id])
        doc = pq(response.content)
        eq_('1 out of 1 person found this reply helpful',
            doc('#answer-1 span.helpful')[0].text.strip())
开发者ID:bowmasters,项目名称:kitsune,代码行数:33,代码来源:test_templates.py

示例8: test_watch_both_then_new_post

    def test_watch_both_then_new_post(self, get_current):
        """Watching both forum and thread.

        Replying to a thread should send ONE email."""
        get_current.return_value.domain = 'testserver'

        t = thread(save=True)
        f = t.forum
        forum_post(thread=t, save=True)
        poster = user(save=True)
        watcher = user(save=True)

        self._toggle_watch_forum_as(f, watcher, turn_on=True)
        self._toggle_watch_thread_as(t, watcher, turn_on=True)
        self.client.login(username=poster.username, password='testpass')
        post(self.client, 'forums.reply', {'content': 'a post'},
             args=[f.slug, t.id])

        eq_(1, len(mail.outbox))
        p = Post.objects.all().order_by('-id')[0]
        attrs_eq(mail.outbox[0], to=[watcher.email],
                 subject='Re: {f} - {t}'.format(f=f, t=t))
        body = REPLY_EMAIL.format(
            username=poster.username,
            forum_slug=f.slug,
            thread_title=t.title,
            thread_id=t.id,
            post_id=p.id)
        starts_with(mail.outbox[0].body, body)
开发者ID:Apokalyptica79,项目名称:kitsune,代码行数:29,代码来源:test_notifications.py

示例9: common_vote

    def common_vote(self):
        """Helper method for question vote tests."""
        # Check that there are no votes and vote form renders
        response = get(self.client, 'questions.answers',
                       args=[self.question.id])
        doc = pq(response.content)
        eq_('0 people', doc('div.have-problem mark')[0].text)
        eq_(1, len(doc('div.me-too form')))

        # Vote
        ua = 'Mozilla/5.0 (DjangoTestClient)'
        self.client.post(reverse('questions.vote', args=[self.question.id]),
                         {}, HTTP_USER_AGENT=ua)

        # Check that there is 1 vote and vote form doesn't render
        response = get(self.client, 'questions.answers',
                       args=[self.question.id])
        doc = pq(response.content)
        eq_('1 person', doc('div.have-problem mark')[0].text)
        eq_(0, len(doc('div.me-too form')))
        # Verify user agent
        vote_meta = VoteMetadata.objects.all()[0]
        eq_('ua', vote_meta.key)
        eq_(ua, vote_meta.value)

        # Voting again (same user) should not increment vote count
        post(self.client, 'questions.vote', args=[self.question.id])
        response = get(self.client, 'questions.answers',
                       args=[self.question.id])
        doc = pq(response.content)
        eq_('1 person', doc('div.have-problem mark')[0].text)
开发者ID:bowmasters,项目名称:kitsune,代码行数:31,代码来源:test_templates.py

示例10: test_answer_upload

    def test_answer_upload(self):
        """Posting answer attaches an existing uploaded image to the answer."""

        f = open('apps/upload/tests/media/test.jpg')
        post(self.client, 'upload.up_image_async', {'image': f},
             args=['questions.Question', self.question.id])
        f.close()

        content = 'lorem ipsum dolor sit amet'
        response = post(self.client, 'questions.reply',
                        {'content': content},
                        args=[self.question.id])
        eq_(200, response.status_code)

        new_answer = self.question.answers.order_by('-created')[0]
        eq_(1, new_answer.images.count())
        image = new_answer.images.all()[0]
        name = '098f6b.jpg'
        message = 'File name "%s" does not contain "%s"' % (
            image.file.name, name)
        assert name in image.file.name, message
        eq_('jsocol', image.creator.username)

        # Clean up
        ImageAttachment.objects.all().delete()
开发者ID:MechanisM,项目名称:kitsune,代码行数:25,代码来源:test_templates.py

示例11: test_answer_creator_can_edit

    def test_answer_creator_can_edit(self):
        """The creator of an answer can edit his/her answer."""
        self.client.login(username="rrosario", password="testpass")

        # Initially there should be no edit links
        response = get(self.client, "questions.answers", args=[self.question.id])
        doc = pq(response.content)
        eq_(0, len(doc("ol.answers li.edit")))

        # Add an answer and verify the edit link shows up
        content = "lorem ipsum dolor sit amet"
        response = post(self.client, "questions.reply", {"content": content}, args=[self.question.id])
        doc = pq(response.content)
        eq_(1, len(doc("ol.answers li.edit")))
        new_answer = self.question.answers.order_by("-created")[0]
        eq_(1, len(doc("#answer-%s li.edit" % new_answer.id)))

        # Make sure it can be edited
        content = "New content for answer"
        response = post(
            self.client, "questions.edit_answer", {"content": content}, args=[self.question.id, new_answer.id]
        )
        eq_(200, response.status_code)

        # Now lock it and make sure it can't be edited
        self.question.is_locked = True
        self.question.save()
        response = post(
            self.client, "questions.edit_answer", {"content": content}, args=[self.question.id, new_answer.id]
        )
        eq_(403, response.status_code)
开发者ID:Apokalyptica79,项目名称:kitsune,代码行数:31,代码来源:test_templates.py

示例12: _toggle_watch_question

    def _toggle_watch_question(self, event_type, turn_on=True):
        """Helper to watch/unwatch a question. Fails if called twice with
        the same turn_on value."""
        question = Question.objects.all()[0]
        self.client.login(username='pcraciunoiu', password='testpass')
        user = User.objects.get(username='pcraciunoiu')
        event_cls = (QuestionReplyEvent if event_type == 'reply'
                                        else QuestionSolvedEvent)
        # Make sure 'before' values are the reverse.
        if turn_on:
            assert not event_cls.is_notifying(user, question), (
                '%s should not be notifying.' % event_cls.__name__)
        else:
            assert event_cls.is_notifying(user, question), (
                '%s should be notifying.' % event_cls.__name__)

        url = 'questions.watch' if turn_on else 'questions.unwatch'
        data = {'event_type': event_type} if turn_on else {}
        post(self.client, url, data, args=[question.id])

        if turn_on:
            assert event_cls.is_notifying(user, question), (
                '%s should be notifying.' % event_cls.__name__)
        else:
            assert not event_cls.is_notifying(user, question), (
                '%s should not be notifying.' % event_cls.__name__)
        return question
开发者ID:Akamad007,项目名称:kitsune,代码行数:27,代码来源:test_notifications.py

示例13: test_unwatch

 def test_unwatch(self):
     """Unwatch a question."""
     self.client.login(username='rrosario', password='testpass')
     user = User.objects.get(username='rrosario')
     create_watch(Question, self.question.id, user.email, 'solution')
     post(self.client, 'questions.unwatch', args=[self.question.id])
     assert not check_watch(Question, self.question.id, user.email,
                            'solution'), 'Watch was not destroyed'
开发者ID:MechanisM,项目名称:kitsune,代码行数:8,代码来源:test_templates.py

示例14: test_unsolve

 def test_unsolve(self, delete):
     answer = Answer.objects.get(pk=1)
     question = answer.question
     self.client.login(username='jsocol', password='testpass')
     question.solution = answer
     question.save()
     post(self.client, 'questions.unsolve', args=[question.id, answer.id])
     assert delete.called
开发者ID:Apokalyptica79,项目名称:kitsune,代码行数:8,代码来源:test_karma.py

示例15: test_watch_solution

 def test_watch_solution(self):
     """Watch a question for solution."""
     self.client.logout()
     post(self.client, 'questions.watch',
          {'email': '[email protected]', 'event_type': 'solution'},
          args=[self.question.id])
     assert check_watch(Question, self.question.id, '[email protected]',
                        'solution'), 'Watch was not created'
开发者ID:MechanisM,项目名称:kitsune,代码行数:8,代码来源:test_templates.py


注:本文中的sumo.tests.post函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。