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, ]
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, ]
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, ]
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, ]
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
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)
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)
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
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, ]
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, ]
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, ]
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, ]
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, ]