'Only authorized people can search certain forums'

def test_forums_search_authorized_forums(self):

    forum1 = ForumFactory(name=u'ou812forum')
    thread1 = ThreadFactory(forum=forum1)
    PostFactory(thread=thread1, content=u'audio')
    forum2 = RestrictedForumFactory(name=u'restrictedkeepout')
    thread2 = ThreadFactory(forum=forum2)
    PostFactory(thread=thread2, content=u'audio    restricted')
    self.refresh()
    response = self.client.get(reverse('search.advanced'), {'author': '', 'created': '0', 'created_date': '', 'updated': '0', 'updated_date': '', 'sortby': '0', 'a': '1', 'w': '4', 'q': 'audio', 'format': 'json'})
    eq_(200, response.status_code)
    content = json.loads(response.content)
    eq_(content['total'], 1)
    u = UserFactory()
    g = GroupFactory()
    g.user_set.add(u)
    ct = ContentType.objects.get_for_model(forum2)
    PermissionFactory(codename='forums_forum.view_in_forum', content_type=ct, object_id=forum2.id, group=g)
    self.client.login(username=u.username, password='testpass')
    response = self.client.get(reverse('search.advanced'), {'author': '', 'created': '0', 'created_date': '', 'updated': '0', 'updated_date': '', 'sortby': '0', 'a': '1', 'w': '4', 'q': 'audio', 'format': 'json'})
    eq_(200, response.status_code)
    content = json.loads(response.content)
    eq_(content['total'], 2)
