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


Python testing_utils.create_thread函数代码示例

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


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

示例1: test_sort_title_reversed

    def test_sort_title_reversed(self):
        """ Test sorting by title field reversed.

        If the request has a GET variable of 'sort' with the value of
        'title', and a variable 'reverse' with the value of 'true',
        then the threads should be ordered by title in reverse
        alphabetical order.
        """
        thread1 = create_thread(
            topic=self.topic,
            title='cats')
        thread2 = create_thread(
            topic=self.topic,
            title='animals')
        thread3 = create_thread(
            topic=self.topic,
            title='bats')

        url = thread_list_url(topic=self.topic, sort='title', rev=True)
        response = self.client.get(url)

        expected = [
            '<Thread: %s>' % thread1,
            '<Thread: %s>' % thread3,
            '<Thread: %s>' % thread2,
        ]

        self.assertEqual(200, response.status_code)
        self.assertQuerysetEqual(
            response.context['thread_list'],
            expected)
开发者ID:cdriehuys,项目名称:django_simple_forums,代码行数:31,代码来源:test_views.py

示例2: test_full_title_search

    def test_full_title_search(self):
        """ Test searching for the title of a thread.

        Searching for the title of a thread should return only that
        thread.
        """
        thread = create_thread(title='cat')
        create_thread(title='dog')

        results = [t for t, _ in self.backend.search('cat')]

        self.assertEqual([thread], results)
开发者ID:cdriehuys,项目名称:django_simple_forums,代码行数:12,代码来源:test_search_backends.py

示例3: test_full_title_search

    def test_full_title_search(self):
        """ Test searching for the title of a thread.

        Searching for the title of a thread should return only that
        thread.
        """
        create_thread(title='cat')
        create_thread(title='dog')

        self.assertQuerysetEqual(
            self.backend.search('cat'),
            ['<Thread: cat>'])
开发者ID:wbasile,项目名称:Open-Game-Benchmarks,代码行数:12,代码来源:test_search_backends.py

示例4: test_partial_title_match

    def test_partial_title_match(self):
        """ Test search that matches multiple threads.

        If a search matches multiple threads, all matching threads
        should be returned.
        """
        t1 = create_thread(title='cat escapes prison')
        t2 = create_thread(title='woman finds cat playing with yarn')
        create_thread(title='stray dog wins lottery')

        results = [t for t, _ in self.backend.search('cat')]
        expected = [t1, t2]

        self.assertEqual(expected, results)
开发者ID:cdriehuys,项目名称:django_simple_forums,代码行数:14,代码来源:test_search_backends.py

示例5: test_partial_title_match

    def test_partial_title_match(self):
        """ Test search that matches multiple threads.

        If a search matches multiple threads, all matching threads
        should be returned.
        """
        t1 = create_thread(title='cat escapes prison')
        t2 = create_thread(title='woman finds cat playing with yarn')
        create_thread(title='stray dog wins lottery')

        self.assertQuerysetEqual(
            self.backend.search('cat'),
            ['<Thread: %s>' % t1, '<Thread: %s>' % t2],
            ordered=False)
开发者ID:wbasile,项目名称:Open-Game-Benchmarks,代码行数:14,代码来源:test_search_backends.py

示例6: test_blank_search

    def test_blank_search(self):
        """ Test result of searching for a blank string.

        Searching for a blank string should return all threads.
        """
        create_thread(title='thread 1')
        create_thread(title='thread 2')

        results = [t for t, _ in self.backend.search('')]

        expected = list()
        for thread in models.Thread.objects.all():
            expected.append(thread)

        self.assertEqual(expected, results)
开发者ID:cdriehuys,项目名称:django_simple_forums,代码行数:15,代码来源:test_search_backends.py

示例7: test_add_messages

    def test_add_messages(self):
        """ Test adding a thread that has messages associated with it.

        Adding a message that has messages associated with it should
        also add those messages to the search index.
        """
        thread = create_thread()
        message = create_message(thread=thread)

        self.backend.add(thread)

        es = Elasticsearch([{'host': 'localhost', 'port': 9200}])

        source = es.get_source(
            index=self.backend.index,
            doc_type='message',
            id=message.pk)
        source_json = json.dumps(source)

        expected = {
            'body': message.body,
        }
        expected_json = json.dumps(expected)

        self.assertJSONEqual(expected_json, source_json)
开发者ID:cdriehuys,项目名称:django_simple_forums,代码行数:25,代码来源:test_search_backends.py

示例8: test_blank_search

    def test_blank_search(self):
        """ Test result of searching for a blank string.

        Searching for a blank string should return all threads.
        """
        create_thread(title='thread 1')
        create_thread(title='thread 2')

        expected = list()
        for thread in models.Thread.objects.all():
            expected.append('<Thread: %s>' % thread)

        self.assertQuerysetEqual(
            self.backend.search(''),
            expected,
            ordered=False)
开发者ID:wbasile,项目名称:Open-Game-Benchmarks,代码行数:16,代码来源:test_search_backends.py

示例9: test_thread_for_different_topic

    def test_thread_for_different_topic(self):
        """ Test view when there is a thread for a different topic.

        If a thread is associated with a different topic, it should not
        be displayed.
        """
        thread = create_thread(topic=self.topic)
        create_thread(title="I shouldn't be included")

        url = thread_list_url(topic=self.topic)
        response = self.client.get(url)

        self.assertEqual(200, response.status_code)
        self.assertQuerysetEqual(
            response.context['thread_list'],
            ['<Thread: %s>' % thread])
开发者ID:cdriehuys,项目名称:django_simple_forums,代码行数:16,代码来源:test_views.py

示例10: test_send_notification

    def test_send_notification(self):
        """ Test sending a notification email.

        Calling this method should send an email to the user assocated
        with the notification.
        """
        user = get_test_user(email='[email protected]')
        thread = create_thread()
        message = create_message(thread=thread)

        notification = models.ThreadNotification.objects.create(
            user=user,
            thread=thread)
        notification.send_notification(message)

        expected = 'Thread #%d was updated' % (thread.pk)

        self.assertEqual(1, len(mail.outbox))

        m = mail.outbox[0]

        self.assertEqual('Thread Updated', m.subject)
        self.assertEqual(expected, m.body)
        self.assertEqual('[email protected]', m.from_email)
        self.assertEqual([user.email], m.to)
开发者ID:cdriehuys,项目名称:django_simple_forums,代码行数:25,代码来源:test_models.py

示例11: test_create_new_message

    def test_create_new_message(self):
        """ Test creating a new message.

        Creating a new message on a thread that has a notification
        associated with it should send an email notification.
        """
        user = get_test_user()
        thread = create_thread()
        notification = create_thread_notification(
            user=user, thread=thread)

        message = create_message(
            user=get_test_user(username="test2"),
            thread=thread)

        self.assertEqual(1, len(mail.outbox))

        result = mail.outbox[0]

        mail.outbox = []

        notification.send_notification(message)
        expected = mail.outbox[0]

        self.assertMailEqual(expected, result)
开发者ID:cdriehuys,项目名称:django_simple_forums,代码行数:25,代码来源:test_signals.py

示例12: test_get_title

    def test_get_title(self):
        """ Test getting the thread's title.

        This method should return the title field of the thread.
        """
        thread = create_thread()

        self.assertEqual(thread.title, thread.get_title())
开发者ID:cdriehuys,项目名称:django_simple_forums,代码行数:8,代码来源:test_models.py

示例13: test_sticky_default

    def test_sticky_default(self):
        """ Test default 'sticky' value.

        Threads should not be sticky by default.
        """
        thread = create_thread()

        self.assertFalse(thread.sticky)
开发者ID:cdriehuys,项目名称:django_simple_forums,代码行数:8,代码来源:test_models.py

示例14: test_slug_generation

    def test_slug_generation(self):
        """ Test the automatic generation of a url slug.

        When creating a thread instance, the instance should generate a
        url slug based on its title.
        """
        thread = create_thread(title='test title')

        self.assertEqual('test-title', thread.slug)
开发者ID:cdriehuys,项目名称:django_simple_forums,代码行数:9,代码来源:test_models.py

示例15: test_num_replies_with_no_replies

    def test_num_replies_with_no_replies(self):
        """ Test retrieving the number of replies for a thread.

        If there are no messages associated with the thread, the number
        of replies should be 0.
        """
        thread = create_thread()

        self.assertEqual(0, thread.num_replies)
开发者ID:cdriehuys,项目名称:django_simple_forums,代码行数:9,代码来源:test_models.py


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