Пример #1
0
 def test_can_search_forum_posts_by_using_the_registered_poster_name(self):
     # Setup
     self.topic_1.first_post.subject = 'newsubject'
     self.topic_1.first_post.save()
     self.topic_2.first_post.subject = 'newsubject'
     self.topic_2.first_post.save()
     self.topic_3.first_post.subject = 'newsubject'
     self.topic_3.first_post.save()
     management.call_command('clear_index', verbosity=0, interactive=False)
     management.call_command('update_index', verbosity=0)
     form = SearchForm(
         {
             'q': 'newsubject',
             'search_poster_name': self.user.username,
         },
         user=self.user,
     )
     # Run
     results = form.search()
     # Check
     assert form.is_valid()
     assert [r.object for r in results] == [
         self.post_1,
         self.post_2,
         self.post_3,
     ]
Пример #2
0
    def test_can_search_forum_posts_by_using_the_anonymous_poster_name(self):
        # Setup
        self.topic_1.first_post.subject = 'newsubject'
        self.topic_1.first_post.save()
        self.topic_2.first_post.subject = 'newsubject'
        self.topic_2.first_post.save()
        self.topic_3.first_post.subject = 'newsubject'
        self.topic_3.first_post.save()
        post_4 = PostFactory.create(
            subject='newsubject', topic=self.topic_3, poster=None, username='******')
        management.call_command('clear_index', verbosity=0, interactive=False)
        management.call_command('update_index', verbosity=0)
        form = SearchForm(
            {
                'q': 'newsubject',
                'search_poster_name': 'newtest',

            },
            user=self.user,
        )
        # Run
        results = form.search()
        # Check
        assert form.is_valid()
        assert [r.object for r in results] == [post_4, ]
Пример #3
0
 def test_can_search_forum_posts_by_using_the_registered_poster_name(self):
     # Setup
     self.topic_1.first_post.subject = 'newsubject'
     self.topic_1.first_post.save()
     self.topic_2.first_post.subject = 'newsubject'
     self.topic_2.first_post.save()
     self.topic_3.first_post.subject = 'newsubject'
     self.topic_3.first_post.save()
     rebuild_index.Command().handle(interactive=False, verbosity=-1)
     form = SearchForm(
         {
             'q': 'newsubject',
             'search_poster_name': self.user.username,
         },
         user=self.user,
     )
     # Run
     results = form.search()
     # Check
     assert form.is_valid()
     assert [r.object for r in results] == [
         self.post_1,
         self.post_2,
         self.post_3,
     ]
Пример #4
0
 def test_can_search_forum_posts_by_using_the_anonymous_poster_name(self):
     # Setup
     self.topic_1.first_post.subject = 'newsubject'
     self.topic_1.first_post.save()
     self.topic_2.first_post.subject = 'newsubject'
     self.topic_2.first_post.save()
     self.topic_3.first_post.subject = 'newsubject'
     self.topic_3.first_post.save()
     post_4 = PostFactory.create(subject='newsubject',
                                 topic=self.topic_3,
                                 poster=None,
                                 username='******')
     management.call_command('clear_index', verbosity=0, interactive=False)
     management.call_command('update_index', verbosity=0)
     form = SearchForm(
         {
             'q': 'newsubject',
             'search_poster_name': 'newtest',
         },
         user=self.user,
     )
     # Run
     results = form.search()
     # Check
     assert form.is_valid()
     assert [r.object for r in results] == [
         post_4,
     ]
Пример #5
0
 def test_can_search_forum_posts(self):
     # Setup
     form = SearchForm(
         {'q': self.topic_1.first_post.subject},
         user=self.user,
     )
     # Run
     results = form.search()
     # Check
     assert form.is_valid()
     assert results[0].forum == self.topic_1.forum.pk
Пример #6
0
 def test_can_search_forum_posts(self):
     # Setup
     form = SearchForm(
         {'q': self.topic_1.first_post.subject},
         user=self.user,
     )
     # Run
     results = form.search()
     # Check
     assert form.is_valid()
     assert results[0].forum == self.topic_1.forum.pk
Пример #7
0
 def test_cannot_search_forum_posts_if_the_user_has_not_the_required_permissions(self):
     # Setup
     u1 = UserFactory.create()
     form = SearchForm(
         {'q': self.topic_1.first_post.content},
         user=u1,
     )
     # Run
     results = form.search()
     # Check
     assert form.is_valid()
     assert not len(results)
Пример #8
0
 def test_cannot_search_forum_posts_if_the_user_has_not_the_required_permissions(self):
     # Setup
     u1 = UserFactory.create()
     form = SearchForm(
         {'q': self.topic_1.first_post.content},
         user=u1,
     )
     # Run
     results = form.search()
     # Check
     assert form.is_valid()
     assert not len(results)
Пример #9
0
 def test_cannot_search_forum_posts_if_the_form_is_not_valid(self):
     # Setup
     form = SearchForm(
         {
             'q': self.topic_1.first_post.content,
             'search_forums': [1000, ],
         },
         user=self.user,
     )
     # Run
     results = form.search()
     # Check
     assert not len(results)
Пример #10
0
 def test_cannot_search_forum_posts_if_the_form_is_not_valid(self):
     # Setup
     form = SearchForm(
         {
             'q': self.topic_1.first_post.content,
             'search_forums': [1000, ],
         },
         user=self.user,
     )
     # Run
     results = form.search()
     # Check
     assert not len(results)
Пример #11
0
 def test_can_search_forum_posts_by_using_only_topic_subjects(self):
     # Setup
     form = SearchForm(
         {
             'q': self.topic_1.subject,
             'search_topics': True,
         },
         user=self.user,
     )
     # Run
     results = form.search()
     # Check
     assert form.is_valid()
     assert results[0].forum == self.topic_1.forum.pk
Пример #12
0
    def test_can_search_forum_posts_by_using_only_topic_subjects(self):
        # Setup
        form = SearchForm(
            {
                'q': self.topic_1.subject,
                'search_topics': True,

            },
            user=self.user,
        )
        # Run
        results = form.search()
        # Check
        assert form.is_valid()
        assert results[0].forum == self.topic_1.forum.pk
Пример #13
0
    def test_can_search_forum_posts_by_using_a_set_of_forums(self):
        # Setup
        self.topic_2.first_post.subject = self.topic_1.subject
        self.topic_2.first_post.save()
        rebuild_index.Command().handle(interactive=False, verbosity=-1)
        form = SearchForm(
            {
                'q': self.topic_1.subject,
                'search_forums': [self.forum_1.pk, self.forum_2.pk, ],

            },
            user=self.user,
        )
        # Run
        results = form.search()
        # Check
        assert form.is_valid()
        assert [r.object for r in results] == [self.post_1, self.post_2, ]
Пример #14
0
    def test_can_search_forum_posts_by_using_a_set_of_forums(self):
        # Setup
        self.topic_2.first_post.subject = self.topic_1.subject
        self.topic_2.first_post.save()
        rebuild_index.Command().handle(interactive=False, verbosity=-1)
        form = SearchForm(
            {
                'q': self.topic_1.subject,
                'search_forums': [self.forum_1.pk, self.forum_2.pk, ],

            },
            user=self.user,
        )
        # Run
        results = form.search()
        # Check
        assert form.is_valid()
        assert [r.object for r in results] == [self.post_1, self.post_2, ]
Пример #15
0
    def test_can_search_forum_posts_by_using_a_set_of_forums(self):
        # Setup
        self.topic_2.first_post.subject = self.topic_1.subject
        self.topic_2.first_post.save()
        management.call_command('clear_index', verbosity=0, interactive=False)
        management.call_command('update_index', verbosity=0)
        form = SearchForm(
            {
                'q': self.topic_1.subject,
                'search_forums': [self.forum_1.pk, self.forum_2.pk, ],

            },
            user=self.user,
        )
        # Run
        results = form.search()
        # Check
        assert form.is_valid()
        assert [r.object for r in results] == [self.post_1, self.post_2, ]
Пример #16
0
    def test_can_search_forum_posts_by_using_the_registered_poster_name(self):
        # Setup
        self.topic_1.first_post.subject = 'newsubject'
        self.topic_1.first_post.save()
        self.topic_2.first_post.subject = 'newsubject'
        self.topic_2.first_post.save()
        self.topic_3.first_post.subject = 'newsubject'
        self.topic_3.first_post.save()
        rebuild_index.Command().handle(interactive=False, verbosity=-1)
        form = SearchForm(
            {
                'q': 'newsubject',
                'search_poster_name': self.user.username,

            },
            user=self.user,
        )
        # Run
        results = form.search()
        # Check
        assert form.is_valid()
        assert [r.object for r in results] == [self.post_1, self.post_2, self.post_3, ]
Пример #17
0
    def test_can_search_forum_posts_by_using_the_registered_poster_name(self):
        # Setup
        self.topic_1.first_post.subject = 'newsubject'
        self.topic_1.first_post.save()
        self.topic_2.first_post.subject = 'newsubject'
        self.topic_2.first_post.save()
        self.topic_3.first_post.subject = 'newsubject'
        self.topic_3.first_post.save()
        management.call_command('clear_index', verbosity=0, interactive=False)
        management.call_command('update_index', verbosity=0)
        form = SearchForm(
            {
                'q': 'newsubject',
                'search_poster_name': self.user.username,

            },
            user=self.user,
        )
        # Run
        results = form.search()
        # Check
        assert form.is_valid()
        assert [r.object for r in results] == [self.post_1, self.post_2, self.post_3, ]
Пример #18
0
 def test_can_search_forum_posts_by_using_a_set_of_forums(self):
     # Setup
     self.topic_2.first_post.subject = self.topic_1.subject
     self.topic_2.first_post.save()
     management.call_command('clear_index', verbosity=0, interactive=False)
     management.call_command('update_index', verbosity=0)
     form = SearchForm(
         {
             'q': self.topic_1.subject,
             'search_forums': [
                 self.forum_1.pk,
                 self.forum_2.pk,
             ],
         },
         user=self.user,
     )
     # Run
     results = form.search()
     # Check
     assert form.is_valid()
     assert [r.object for r in results] == [
         self.post_1,
         self.post_2,
     ]