def setUp(self):
        self.loadstatement = '{% load forum_tracking_tags %}'
        self.request_factory = RequestFactory()

        # Tracking handler
        self.tracks_handler = TrackingHandler()

        self.g1 = GroupFactory.create()
        self.u1 = UserFactory.create()
        self.u2 = UserFactory.create()
        self.u1.groups.add(self.g1)
        self.u2.groups.add(self.g1)

        # Set up a top-level category
        self.top_level_cat = create_category_forum()

        # Set up some forums
        self.forum_1 = create_forum(parent=self.top_level_cat)
        self.forum_2 = create_forum(parent=self.top_level_cat)

        # Set up some topics and posts
        self.forum_1_topic = create_topic(forum=self.forum_1, poster=self.u1)
        self.forum_2_topic = create_topic(forum=self.forum_2, poster=self.u1)
        self.post_1 = PostFactory.create(topic=self.forum_1_topic, poster=self.u1)
        self.post_2 = PostFactory.create(topic=self.forum_2_topic, poster=self.u1)

        # Assign some permissions
        assign_perm('can_see_forum', self.g1, self.top_level_cat)
        assign_perm('can_read_forum', self.g1, self.top_level_cat)
        assign_perm('can_see_forum', self.g1, self.forum_1)
        assign_perm('can_read_forum', self.g1, self.forum_1)
        assign_perm('can_see_forum', self.g1, self.forum_2)
        assign_perm('can_read_forum', self.g1, self.forum_2)
示例#2
0
    def setup(self):
        # Create a basic user
        self.user = UserFactory.create()

        # Permission handler
        self.perm_handler = PermissionHandler()

        # Set up a top-level forum
        self.cat = create_category_forum()
        self.top_level_forum = create_forum()
        self.other_forum = create_forum()

        # Set up a topic and some posts
        self.topic = create_topic(forum=self.top_level_forum, poster=self.user)
        self.first_post = PostFactory.create(topic=self.topic, poster=self.user)
        self.post = PostFactory.create(topic=self.topic, poster=self.user)

        # Mark the forum as read
        ForumReadTrackFactory.create(forum=self.top_level_forum, user=self.user)

        # Assign some permissions
        assign_perm('can_read_forum', self.user, self.top_level_forum)
        assign_perm('can_reply_to_topics', self.user, self.top_level_forum)
        assign_perm('can_edit_own_posts', self.user, self.top_level_forum)
        assign_perm('can_delete_own_posts', self.user, self.top_level_forum)
        assign_perm('can_lock_topics', self.user, self.top_level_forum)
示例#3
0
    def setup(self):
        self.u1 = UserFactory.create()
        self.g1 = GroupFactory.create()
        self.u1.groups.add(self.g1)

        # Permission handler
        self.perm_handler = PermissionHandler()

        # Set up a top-level category
        self.top_level_cat = create_category_forum()

        # Set up some forums
        self.forum_1 = create_forum(parent=self.top_level_cat)
        self.forum_2 = create_forum(parent=self.top_level_cat)
        self.forum_3 = create_link_forum(parent=self.top_level_cat)

        # Set up a top-level forum link
        self.top_level_link = create_link_forum()

        # Set up some topics
        self.forum_1_topic = create_topic(forum=self.forum_1, poster=self.u1)
        self.forum_3_topic = create_topic(forum=self.forum_3, poster=self.u1)
        self.forum_3_topic_2 = create_topic(
            forum=self.forum_3, poster=self.u1, status=Topic.TOPIC_LOCKED)

        # Set up some posts
        self.post_1 = PostFactory.create(topic=self.forum_1_topic, poster=self.u1)
        self.post_2 = PostFactory.create(topic=self.forum_3_topic, poster=self.u1)

        # Assign some permissions
        assign_perm('can_see_forum', self.u1, self.top_level_cat)
        assign_perm('can_see_forum', self.u1, self.forum_1)
        assign_perm('can_read_forum', self.g1, self.forum_3)
    def setup(self):
        self.loadstatement = '{% load forum_permission_tags %}'
        self.request_factory = RequestFactory()

        self.g1 = GroupFactory.create()
        self.u1 = UserFactory.create()
        self.u2 = UserFactory.create()
        self.u1.groups.add(self.g1)
        self.u2.groups.add(self.g1)
        self.moderators = GroupFactory.create()
        self.moderator = UserFactory.create()
        self.moderator.groups.add(self.moderators)
        self.superuser = UserFactory.create(is_superuser=True)

        # Permission handler
        self.perm_handler = PermissionHandler()

        # Set up a top-level category
        self.top_level_cat = create_category_forum()

        # Set up some forums
        self.forum_1 = create_forum(parent=self.top_level_cat)
        self.forum_2 = create_forum(parent=self.top_level_cat)

        # Set up some topics and posts
        self.forum_1_topic = create_topic(forum=self.forum_1, poster=self.u1)
        self.forum_2_topic = create_topic(forum=self.forum_2, poster=self.u2)
        self.post_1 = PostFactory.create(topic=self.forum_1_topic, poster=self.u1)
        self.post_2 = PostFactory.create(topic=self.forum_2_topic, poster=self.u2)
示例#5
0
    def setup(self):
        # Add some users
        self.u1 = UserFactory.create()
        self.g1 = GroupFactory.create()
        self.u1.groups.add(self.g1)
        self.user.groups.add(self.g1)

        # Permission handler
        self.perm_handler = PermissionHandler()

        self.top_level_cat_1 = create_category_forum()

        self.forum_1 = create_forum(parent=self.top_level_cat_1)
        self.forum_2 = create_forum(parent=self.top_level_cat_1)
        self.forum_3 = create_forum(parent=self.top_level_cat_1)

        self.topic_1 = create_topic(forum=self.forum_2, poster=self.u1)
        PostFactory.create(topic=self.topic_1, poster=self.u1)
        PostFactory.create(topic=self.topic_1, poster=self.user)

        self.topic_2 = create_topic(forum=self.forum_1, poster=self.user)
        PostFactory.create(topic=self.topic_2, poster=self.user)
        PostFactory.create(topic=self.topic_2, poster=self.u1)

        self.topic_3 = create_topic(forum=self.forum_2, poster=self.u1)
        PostFactory.create(topic=self.topic_3, poster=self.u1)

        self.topic_4 = create_topic(forum=self.forum_2, poster=self.user)
        PostFactory.create(topic=self.topic_4, poster=self.user)

        # Assign some permissions
        assign_perm('can_read_forum', self.g1, self.top_level_cat_1)
        assign_perm('can_read_forum', self.g1, self.forum_1)
        assign_perm('can_read_forum', self.g1, self.forum_2)
    def setup(self):
        self.loadstatement = '{% load forum_tags %}'
        self.request_factory = RequestFactory()
        self.user = UserFactory.create()

        # Set up a top-level category
        self.top_level_cat = create_category_forum()

        # Set up some forums
        self.forum_1 = create_forum(parent=self.top_level_cat)
        self.forum_2 = create_forum(parent=self.top_level_cat)
示例#7
0
    def setup(self):
        self.u1 = UserFactory.create()

        # Set up top-level forums: a category, a default forum and a link forum
        self.top_level_cat = create_category_forum()
        self.top_level_forum = create_forum()
        self.top_level_link = create_link_forum()
示例#8
0
 def setUp(self):
     self.rf = RequestFactory()
     self.u1 = UserFactory.create()
     self.top_level_forum = create_forum()
     self.topic = create_topic(forum=self.top_level_forum, poster=self.u1)
     self.post = PostFactory.create(topic=self.topic, poster=self.u1)
     self.topic_pk = self.topic.pk
示例#9
0
    def setup(self):
        self.u1 = UserFactory.create()

        # Set up a top-level forum, an associated topic and a post
        self.top_level_forum = create_forum()
        self.topic = create_topic(forum=self.top_level_forum, poster=self.u1)
        self.post = PostFactory.create(topic=self.topic, poster=self.u1)
示例#10
0
 def test_do_nothing_if_the_poster_is_anonymous(self):
     # Setup
     top_level_forum = create_forum()
     topic = create_topic(forum=top_level_forum, poster=None)
     # Run
     PostFactory.create(topic=topic, poster=None, username='******')
     # Check
     assert ForumProfile.objects.exists() is False
示例#11
0
    def setup(self):
        self.loadstatement = '{% load forum_polls_tags %}'
        self.request_factory = RequestFactory()

        self.g1 = GroupFactory.create()
        self.u1 = UserFactory.create()
        self.u2 = UserFactory.create()
        self.u1.groups.add(self.g1)
        self.u2.groups.add(self.g1)
        self.moderators = GroupFactory.create()
        self.moderator = UserFactory.create()
        self.moderator.groups.add(self.moderators)
        self.superuser = UserFactory.create(is_superuser=True)

        # Permission handler
        self.perm_handler = PermissionHandler()

        # Set up a top-level category
        self.top_level_cat = create_category_forum()

        # Set up some forums
        self.forum_1 = create_forum(parent=self.top_level_cat)
        self.forum_2 = create_forum(parent=self.top_level_cat)

        # Set up some topics and posts
        self.forum_1_topic = create_topic(forum=self.forum_1, poster=self.u1)
        self.forum_2_topic = create_topic(forum=self.forum_2, poster=self.u2)
        self.post_1 = PostFactory.create(topic=self.forum_1_topic, poster=self.u1)
        self.post_2 = PostFactory.create(topic=self.forum_2_topic, poster=self.u2)
        self.poll_1 = TopicPollFactory.create(topic=self.forum_1_topic)
        self.poll_2 = TopicPollFactory.create(topic=self.forum_2_topic)

        # Assign some permissions
        assign_perm('can_see_forum', self.g1, self.forum_1)
        assign_perm('can_read_forum', self.g1, self.forum_1)
        assign_perm('can_edit_own_posts', self.g1, self.forum_1)
        assign_perm('can_delete_own_posts', self.g1, self.forum_1)
        assign_perm('can_reply_to_topics', self.g1, self.forum_1)
        assign_perm('can_see_forum', self.moderators, self.forum_1)
        assign_perm('can_read_forum', self.moderators, self.forum_1)
        assign_perm('can_edit_own_posts', self.moderators, self.forum_1)
        assign_perm('can_delete_own_posts', self.moderators, self.forum_1)
        assign_perm('can_edit_posts', self.moderators, self.forum_1)
        assign_perm('can_delete_posts', self.moderators, self.forum_1)
        assign_perm('can_vote_in_polls', self.g1, self.forum_1)
示例#12
0
 def test_can_reset_last_post_datetime_if_all_topics_have_been_deleted(self):
     # Setup
     sub_level_forum = create_forum(parent=self.top_level_forum)
     topic = create_topic(forum=sub_level_forum, poster=self.u1)
     PostFactory.create(topic=topic, poster=self.u1)
     # Run
     topic.delete()
     # Check
     sub_level_forum.refresh_from_db()
     assert sub_level_forum.last_post_on is None
示例#13
0
 def test_stores_its_last_post_datetime(self):
     # Setup
     sub_level_forum = create_forum(parent=self.top_level_forum)
     topic = create_topic(forum=sub_level_forum, poster=self.u1)
     PostFactory.create(topic=topic, poster=self.u1)
     # Run
     p2 = PostFactory.create(topic=topic, poster=self.u1)
     # Check
     sub_level_forum.refresh_from_db()
     assert sub_level_forum.last_post_on == p2.created
示例#14
0
 def test_save_can_trigger_the_update_of_the_counters_of_a_new_forum(self):
     # Setup
     new_top_level_forum = create_forum()
     # Run
     self.topic.forum = new_top_level_forum
     self.topic.save()
     # Check
     assert self.topic.forum == new_top_level_forum
     assert new_top_level_forum.topics_count == 1
     assert new_top_level_forum.posts_count == self.topic.posts_count
示例#15
0
 def test_can_trigger_the_update_of_the_counters_of_a_previous_forum(self):
     # Setup
     new_top_level_forum = create_forum()
     # Run
     self.topic.forum = new_top_level_forum
     self.topic.save()
     # Check
     self.top_level_forum = Forum.objects.get(pk=self.top_level_forum.pk)  # Reload the forum from DB
     assert self.topic.forum == new_top_level_forum
     assert self.top_level_forum.topics_count == 0
     assert self.top_level_forum.posts_count == 0
示例#16
0
    def setup(self):
        self.u1 = UserFactory.create()
        self.u2 = UserFactory.create()

        self.top_level_cat_1 = create_category_forum()
        self.top_level_cat_2 = create_category_forum()

        self.forum_1 = create_forum(parent=self.top_level_cat_1)
        self.forum_2 = create_forum(parent=self.top_level_cat_1)
        self.forum_2_child_1 = create_link_forum(parent=self.forum_2)
        self.forum_2_child_2 = create_forum(parent=self.forum_2)
        self.forum_3 = create_forum(parent=self.top_level_cat_1)

        self.forum_4 = create_forum(parent=self.top_level_cat_2)

        self.topic = create_topic(forum=self.forum_2, poster=self.u1)
        PostFactory.create(topic=self.topic, poster=self.u1)

        # Initially u2 read the previously created topic
        ForumReadTrackFactory.create(forum=self.forum_2, user=self.u2)
示例#17
0
    def setup(self):
        # Permission handler
        self.perm_handler = PermissionHandler()

        # Set up a top-level forum and a link forum
        self.top_level_forum = create_forum()
        self.top_level_link = create_link_forum(link_redirects=True)

        # Assign some permissions
        assign_perm('can_read_forum', self.user, self.top_level_forum)
        assign_perm('can_read_forum', self.user, self.top_level_link)
示例#18
0
 def test_can_trigger_the_update_of_the_counters_of_a_previous_parent(self):
     # Setup
     sub_level_forum = create_forum(parent=self.top_level_forum)
     topic = create_topic(forum=sub_level_forum, poster=self.u1)
     PostFactory.create(topic=topic, poster=self.u1)
     PostFactory.create(topic=topic, poster=self.u1)
     # Run
     sub_level_forum.parent = self.top_level_cat
     sub_level_forum.save()
     # Check
     self.top_level_forum = Forum.objects.get(pk=self.top_level_forum.pk)
     assert self.top_level_forum.posts_count == 0
     assert self.top_level_forum.topics_count == 0
示例#19
0
 def test_cannot_increase_the_posts_count_of_the_post_being_created_if_it_is_not_approved(self):
     # Setup
     u1 = UserFactory.create()
     top_level_forum = create_forum()
     topic = create_topic(forum=top_level_forum, poster=u1)
     PostFactory.create(topic=topic, poster=u1)
     profile = ForumProfile.objects.get(user=u1)
     initial_posts_count = profile.posts_count
     # Run
     PostFactory.create(topic=topic, poster=u1, approved=False)
     # Check
     profile.refresh_from_db()
     assert profile.posts_count == initial_posts_count
示例#20
0
    def setup(self):
        # Add some users
        self.u1 = UserFactory.create()
        self.u2 = UserFactory.create()
        self.g1 = GroupFactory.create()
        self.u1.groups.add(self.g1)
        self.u2.groups.add(self.g1)
        self.user.groups.add(self.g1)

        # Permission handler
        self.perm_handler = PermissionHandler()

        # Tracking handler
        self.tracks_handler = TrackingHandler()

        self.top_level_cat_1 = create_category_forum()
        self.top_level_cat_2 = create_category_forum()

        self.forum_1 = create_forum(parent=self.top_level_cat_1)
        self.forum_2 = create_forum(parent=self.top_level_cat_1)
        self.forum_2_child_1 = create_forum(parent=self.forum_2)
        self.forum_3 = create_forum(parent=self.top_level_cat_1)

        self.forum_4 = create_forum(parent=self.top_level_cat_2)

        self.topic = create_topic(forum=self.forum_2, poster=self.u1)
        PostFactory.create(topic=self.topic, poster=self.u1)

        # Initially u2 and user read the previously created topic
        ForumReadTrackFactory.create(forum=self.forum_2, user=self.u2)
        ForumReadTrackFactory.create(forum=self.forum_2, user=self.user)

        # Assign some permissions
        assign_perm('can_read_forum', self.g1, self.top_level_cat_1)
        assign_perm('can_read_forum', self.g1, self.top_level_cat_2)
        assign_perm('can_read_forum', self.g1, self.forum_1)
        assign_perm('can_read_forum', self.g1, self.forum_2)
        assign_perm('can_read_forum', self.g1, self.forum_2_child_1)
        assign_perm('can_read_forum', self.g1, self.forum_4)
示例#21
0
    def setup(self):
        self.u1 = UserFactory.create()

        # Set up a top-level category
        self.top_level_cat = create_category_forum()

        # Set up some forums
        self.forum_1 = create_forum(parent=self.top_level_cat)
        self.forum_2 = create_forum(parent=self.top_level_cat)
        self.forum_3 = create_link_forum(parent=self.top_level_cat)

        # Set up a top-level forum link
        self.top_level_link = create_link_forum()

        # Set up some topics
        self.forum_1_topic = create_topic(forum=self.forum_1, poster=self.u1)
        self.forum_3_topic = create_topic(forum=self.forum_3, poster=self.u1)
        self.forum_3_topic_2 = create_topic(forum=self.forum_3, poster=self.u1, approved=False)

        # Set up some posts
        self.post_1 = PostFactory.create(topic=self.forum_1_topic, poster=self.u1)
        self.post_2 = PostFactory.create(topic=self.forum_3_topic, poster=self.u1)
        self.post_3 = PostFactory.create(topic=self.forum_3_topic, poster=self.u1, approved=False)
示例#22
0
    def setup(self):
        self.user = UserFactory.create()
        self.factory = RequestFactory()

        # Permission handler
        self.perm_handler = PermissionHandler()

        # Set up a single forum
        self.forum = create_forum()

        # Assign some permissions
        assign_perm('can_see_forum', self.user, self.forum)

        self.mixin = PermissionRequiredMixin()
示例#23
0
 def test_display_only_posts_whose_forums_are_eligible_to_the_moderation_queue_for_the_given_user(self):  # noqa
     # Setup
     post2 = PostFactory.create(topic=self.topic, poster=self.user, approved=False)
     f1 = create_forum()
     topic = create_topic(
         forum=f1, poster=self.user)
     PostFactory.create(topic=topic, poster=self.user, approved=False)
     correct_url = reverse(
         'forum_moderation:queue')
     # Run
     response = self.client.get(correct_url, follow=True)
     # Check
     assert response.status_code == 200
     assert set(response.context_data['posts']) == set([post2, ])
示例#24
0
    def setup(self):
        self.loadstatement = '{% load forum_tags %}'
        self.user = UserFactory.create()

        # Permission handler
        self.perm_handler = PermissionHandler()

        # Set up a top-level category
        self.top_level_cat = create_category_forum()

        # Set up some forums
        self.forum_1 = create_forum(parent=self.top_level_cat)
        self.forum_2 = create_forum(parent=self.top_level_cat)

        # Set up some topics and posts
        self.forum_1_topic = create_topic(forum=self.forum_1, poster=self.user)
        self.forum_2_topic = create_topic(forum=self.forum_2, poster=self.user)
        self.post_1 = PostFactory.create(topic=self.forum_1_topic, poster=self.user)
        self.post_2 = PostFactory.create(topic=self.forum_2_topic, poster=self.user)

        # Assign some permissions
        assign_perm('can_see_forum', self.user, self.top_level_cat)
        assign_perm('can_see_forum', self.user, self.forum_1)
示例#25
0
 def test_can_decrease_the_posts_count_of_the_post_being_deleted(self):
     # Setup
     u1 = UserFactory.create()
     top_level_forum = create_forum()
     topic = create_topic(forum=top_level_forum, poster=u1)
     PostFactory.create(topic=topic, poster=u1)
     post = PostFactory.create(topic=topic, poster=u1)
     profile = ForumProfile.objects.get(user=u1)
     initial_posts_count = profile.posts_count
     # Run
     post.delete()
     # Check
     profile.refresh_from_db()
     assert profile.posts_count == initial_posts_count - 1
示例#26
0
 def test_can_increase_the_posts_count_of_a_post_being_approved(self):
     # Setup
     u1 = UserFactory.create()
     top_level_forum = create_forum()
     topic = create_topic(forum=top_level_forum, poster=u1)
     PostFactory.create(topic=topic, poster=u1)
     post = PostFactory.create(topic=topic, poster=u1, approved=False)
     profile = ForumProfile.objects.get(user=u1)
     initial_posts_count = profile.posts_count
     # Run
     post.approved = True
     post.save()
     # Check
     profile = refresh(profile)
     assert profile.posts_count == initial_posts_count + 1
示例#27
0
    def setup(self):
        # Permission handler
        self.perm_handler = PermissionHandler()

        # Create a basic user
        self.user = UserFactory.create()

        # Set up a top-level forum
        self.top_level_forum = create_forum()

        # Set up a topic and some posts
        self.topic = create_topic(forum=self.top_level_forum, poster=self.user)
        self.post = PostFactory.create(topic=self.topic, poster=self.user)

        # Assign some permissions
        assign_perm('can_read_forum', self.user, self.top_level_forum)
        assign_perm('can_start_new_topics', self.user, self.top_level_forum)
示例#28
0
    def setup(self):
        # Permission handler
        self.perm_handler = PermissionHandler()

        # Create a basic user
        self.user = UserFactory.create()

        # Set up a top-level forum
        self.top_level_forum = create_forum()

        # Set up a topic and some posts
        self.topic = create_topic(forum=self.top_level_forum, poster=self.user)
        self.post = PostFactory.create(topic=self.topic, poster=self.user)

        # Assign some permissions
        assign_perm('can_read_forum', self.user, self.top_level_forum)
        assign_perm('can_start_new_topics', self.user, self.top_level_forum)
示例#29
0
 def test_display_only_posts_whose_forums_are_eligible_to_the_moderation_queue_for_the_given_user(
         self):  # noqa
     # Setup
     post2 = PostFactory.create(topic=self.topic,
                                poster=self.user,
                                approved=False)
     f1 = create_forum()
     topic = create_topic(forum=f1, poster=self.user)
     PostFactory.create(topic=topic, poster=self.user, approved=False)
     correct_url = reverse('forum_moderation:queue')
     # Run
     response = self.client.get(correct_url, follow=True)
     # Check
     assert response.status_code == 200
     assert set(response.context_data['posts']) == set([
         post2,
     ])
示例#30
0
    def setup(self):
        # Permission handler
        self.perm_handler = PermissionHandler()

        # Set up a top-level forum
        self.top_level_forum = create_forum()

        # Set up a topic and some posts
        self.topic = create_topic(
            forum=self.top_level_forum, poster=self.user,
            status=Topic.TOPIC_LOCKED)
        self.first_post = PostFactory.create(topic=self.topic, poster=self.user)
        self.post = PostFactory.create(topic=self.topic, poster=self.user, approved=False)

        # Mark the forum as read
        ForumReadTrackFactory.create(forum=self.top_level_forum, user=self.user)

        # Assign some permissions
        assign_perm('can_approve_posts', self.user, self.top_level_forum)
示例#31
0
    def setup(self):
        # Permission handler
        self.perm_handler = PermissionHandler()

        # Set up a top-level forum
        self.top_level_forum = create_forum()

        # Set up a topic and some posts
        self.topic = create_topic(
            forum=self.top_level_forum, poster=self.user,
            status=Topic.STATUS_CHOICES.topic_locked)
        self.first_post = PostFactory.create(topic=self.topic, poster=self.user)
        self.post = PostFactory.create(topic=self.topic, poster=self.user)

        # Mark the forum as read
        ForumReadTrackFactory.create(forum=self.top_level_forum, user=self.user)

        # Assign some permissions
        assign_perm('can_read_forum', self.user, self.top_level_forum)
        assign_perm('can_approve_posts', self.user, self.top_level_forum)
示例#32
0
    def setup(self):
        # Add some users
        self.u1 = UserFactory.create()
        self.g1 = GroupFactory.create()
        self.u1.groups.add(self.g1)
        self.user.groups.add(self.g1)

        # Permission handler
        self.perm_handler = PermissionHandler()

        self.top_level_cat_1 = create_category_forum()

        self.forum_1 = create_forum(parent=self.top_level_cat_1)
        self.topic_1 = create_topic(forum=self.forum_1, poster=self.u1)
        PostFactory.create(topic=self.topic_1, poster=self.u1)
        PostFactory.create(topic=self.topic_1, poster=self.user)

        # Assign some permissions
        assign_perm('can_read_forum', self.g1, self.top_level_cat_1)
        assign_perm('can_read_forum', self.g1, self.forum_1)
 def test_topic_is_auto_subscribed_when_setting_is_enabled(self):
     # Setup
     u1 = UserFactory.create()
     u2 = UserFactory.create()
     top_level_forum = create_forum()
     # Create topics to auto create a forum profile
     topic = create_topic(forum=top_level_forum, poster=u1)
     PostFactory.create(topic=topic, poster=u1)
     PostFactory.create(topic=topic, poster=u2)
     profile = ForumProfile.objects.get(user=u2)
     profile.auto_subscribe_posts = True
     profile.save()
     # Run
     topic = create_topic(forum=top_level_forum, poster=u1)
     PostFactory.create(topic=topic, poster=u1)
     PostFactory.create(topic=topic, poster=u2)
     PostFactory.create(topic=topic, poster=u1)
     # Check
     assert topic in u2.topic_subscriptions.all()
     assert topic not in u1.topic_subscriptions.all()
示例#34
0
    def setup(self):
        # Permission handler
        self.perm_handler = PermissionHandler()

        # Set up a top-level forum
        self.top_level_forum = create_forum()

        # Set up a topic and some posts
        self.topic = create_topic(forum=self.top_level_forum,
                                  poster=self.user,
                                  status=Topic.TOPIC_LOCKED)
        self.first_post = PostFactory.create(topic=self.topic,
                                             poster=self.user)
        self.post = PostFactory.create(topic=self.topic, poster=self.user)

        # Mark the forum as read
        ForumReadTrackFactory.create(forum=self.top_level_forum,
                                     user=self.user)

        # Assign some permissions
        assign_perm('can_read_forum', self.user, self.top_level_forum)
        assign_perm('can_approve_posts', self.user, self.top_level_forum)
示例#35
0
    def setup(self):
        # Permission handler
        self.perm_handler = PermissionHandler()

        # Set up a top-level forum
        self.top_level_forum = create_forum()

        # Set up a topic and some posts
        self.topic = create_topic(forum=self.top_level_forum, poster=self.user)
        self.post = PostFactory.create(topic=self.topic, poster=self.user)

        # Creates a poll and two options
        self.poll = TopicPollFactory.create(topic=self.topic)
        self.option_1 = TopicPollOptionFactory.create(poll=self.poll)
        self.option_2 = TopicPollOptionFactory.create(poll=self.poll)

        # Mark the forum as read
        ForumReadTrackFactory.create(forum=self.top_level_forum, user=self.user)

        # Assign some permissions
        assign_perm('can_read_forum', self.user, self.top_level_forum)
        assign_perm('can_vote_in_polls', self.user, self.top_level_forum)
示例#36
0
    def setup(self):
        # Permission handler
        self.perm_handler = PermissionHandler()

        # Set up a top-level forum
        self.top_level_forum = create_forum()

        # Set up a topic and some posts
        self.topic = create_topic(forum=self.top_level_forum,
                                  poster=self.user,
                                  status=Topic.STATUS_CHOICES.topic_locked)
        self.first_post = PostFactory.create(topic=self.topic,
                                             poster=self.user)
        self.post = PostFactory.create(topic=self.topic,
                                       poster=self.user,
                                       approved=False)

        # Mark the forum as read
        ForumReadTrackFactory.create(forum=self.top_level_forum,
                                     user=self.user)

        # Assign some permissions
        assign_perm('can_approve_posts', self.user, self.top_level_forum)
示例#37
0
    def setup(self):
        # Permission handler
        self.perm_handler = PermissionHandler()

        # Set up a top-level forum
        self.top_level_forum = create_forum()

        # Set up a topic and some posts
        self.topic = create_topic(forum=self.top_level_forum, poster=self.user)
        self.first_post = PostFactory.create(topic=self.topic,
                                             poster=self.user)
        self.post = PostFactory.create(topic=self.topic, poster=self.user)

        # Mark the forum as read
        ForumReadTrackFactory.create(forum=self.top_level_forum,
                                     user=self.user)

        # Assign some permissions
        assign_perm('can_read_forum', self.user, self.top_level_forum)
        assign_perm('can_reply_to_topics', self.user, self.top_level_forum)
        assign_perm('can_edit_own_posts', self.user, self.top_level_forum)
        assign_perm('can_delete_own_posts', self.user, self.top_level_forum)
        assign_perm('can_lock_topics', self.user, self.top_level_forum)
示例#38
0
    def test_send_auto_subscribe_topics(self, mailoutbox):
        # Setup
        u1 = UserFactory.create()
        top_level_forum = create_forum()
        # Create a topic to auto create a forum profile
        topic = create_topic(forum=top_level_forum, poster=u1)
        PostFactory.create(topic=topic, poster=u1)
        profile = ForumProfile.objects.get(user=u1)
        profile.notify_subscribed_topics = True
        profile.auto_subscribe_topics = True
        profile.save()

        # Create the actual topic with a post
        topic = create_topic(forum=top_level_forum, poster=u1)
        PostFactory.create(topic=topic, poster=u1)

        # Create a post in a topic that u1 subscribes to
        u2 = UserFactory.create()
        PostFactory.create(topic=topic, poster=u2)

        # Run & check
        call_command('send_notifications')
        assert len(mailoutbox) == 1
示例#39
0
    def test_send_email(self, mailoutbox):
        # Setup
        user = UserFactory.create()
        top_level_forum = create_forum()
        topic = create_topic(forum=top_level_forum, poster=user)
        post = PostFactory.create(topic=topic, poster=user)

        email = NotificationEmail(from_email='*****@*****.**')
        context = {
            'user': user,
            'post': post,
            'topic': post.topic,
            'current_site': Site.objects.get_current(),
        }
        email.send([user.email], context)
        # Send & check
        assert len(mailoutbox) == 1
        notification = mailoutbox[0]
        assert 'New reply on' in notification.subject
        assert 'Hello' in notification.body
        assert '<h2>Hello,</h2>' in notification.alternatives[0][0]
        assert notification.from_email == '*****@*****.**'
        assert list(notification.to) == [user.email]
示例#40
0
    def setup(self):
        # Permission handler
        self.perm_handler = PermissionHandler()

        # Set up a top-level forum
        self.top_level_forum = create_forum()

        # Set up a topic and some posts
        self.topic = create_topic(forum=self.top_level_forum, poster=self.user)
        self.post = PostFactory.create(topic=self.topic, poster=self.user)

        # Set up an attachment
        f = open(settings.MEDIA_ROOT + '/attachment.jpg', 'rb')
        self.attachment_file = File(f)
        self.attachment = AttachmentFactory.create(post=self.post,
                                                   file=self.attachment_file)

        # Mark the forum as read
        ForumReadTrackFactory.create(forum=self.top_level_forum,
                                     user=self.user)

        # Assign some permissions
        assign_perm('can_read_forum', self.user, self.top_level_forum)
        assign_perm('can_download_file', self.user, self.top_level_forum)

        yield

        # teardown
        # --

        self.attachment_file.close()
        attachments = Attachment.objects.all()
        for attachment in attachments:
            try:
                attachment.file.delete()
            except:
                pass
示例#41
0
    def test_email_not_sent_for_unapproved_post(self, mailoutbox):
        # Setup
        u1 = UserFactory.create()
        top_level_forum = create_forum()
        # Create a topic to auto create a forum profile
        topic = create_topic(forum=top_level_forum, poster=u1)
        PostFactory.create(topic=topic, poster=u1)
        profile = ForumProfile.objects.get(user=u1)
        profile.notify_subscribed_topics = True
        profile.auto_subscribe_topics = True
        profile.save()

        # Create the actual topic with a post
        topic = create_topic(forum=top_level_forum, poster=u1)
        PostFactory.create(topic=topic, poster=u1)

        # Create a post in a topic that u1 subscribes to
        u2 = UserFactory.create()
        PostFactory.create(topic=topic, poster=u2, approved=False)

        send_notifications()

        # Send & check
        assert len(mailoutbox) == 0
示例#42
0
 def setup(self):
     self.forum = create_forum()
示例#43
0
 def test_has_a_margin_level_two_times_greater_than_its_real_level(self):
     # Run
     sub_level_forum = create_forum(parent=self.top_level_forum)
     # Check
     assert self.top_level_forum.margin_level == 0
     assert sub_level_forum.margin_level == 2
示例#44
0
    def setup(self):
        self.factory = RequestFactory()
        self.user = UserFactory.create()

        # Set up the following forum tree:
        #
        #     top_level_cat
        #         forum_1
        #         forum_2
        #             forum_2_child_1
        #     top_level_forum_1
        #     top_level_forum_2
        #         sub_cat
        #             sub_sub_forum
        #     top_level_forum_3
        #         forum_3
        #             forum_3_child_1
        #                 forum_3_child_1_1
        #                     deep_forum
        #     last_forum
        #
        self.top_level_cat = create_category_forum()

        self.forum_1 = create_forum(parent=self.top_level_cat)
        self.forum_2 = create_forum(parent=self.top_level_cat)
        self.forum_2_child_1 = create_forum(parent=self.forum_2)

        self.top_level_forum_1 = create_forum()

        self.top_level_forum_2 = create_forum()
        self.sub_cat = create_category_forum(parent=self.top_level_forum_2)
        self.sub_sub_forum = create_forum(parent=self.sub_cat)

        self.top_level_forum_3 = create_forum()
        self.forum_3 = create_forum(parent=self.top_level_forum_3)
        self.forum_3_child_1 = create_forum(parent=self.forum_3)
        self.forum_3_child_1_1 = create_forum(parent=self.forum_3_child_1)
        self.deep_forum = create_forum(parent=self.forum_3_child_1_1)

        self.last_forum = create_forum()

        # Set up a topic and some posts
        self.topic_1 = create_topic(forum=self.forum_1, poster=self.user)
        self.post_1 = PostFactory.create(topic=self.topic_1, poster=self.user)
        self.topic_2 = create_topic(forum=self.forum_2, poster=self.user)
        self.post_2 = PostFactory.create(topic=self.topic_2, poster=self.user)
        self.topic_3 = create_topic(forum=self.forum_2_child_1,
                                    poster=self.user)
        self.post_3 = PostFactory.create(topic=self.topic_3, poster=self.user)

        # Assign some permissions
        assign_perm('can_read_forum', self.user, self.top_level_cat)
        assign_perm('can_read_forum', self.user, self.forum_1)
        assign_perm('can_read_forum', self.user, self.forum_2)
        assign_perm('can_read_forum', self.user, self.forum_2_child_1)
        assign_perm('can_read_forum', self.user, self.top_level_forum_1)
 def setup(self):
     self.forum = create_forum()
     machina_settings.DEFAULT_AUTHENTICATED_USER_FORUM_PERMISSIONS = [
         'can_see_forum',
     ]
示例#46
0
    def setup(self):
        # Permission handler
        self.perm_handler = PermissionHandler()

        # Create a basic user
        self.user = UserFactory.create(username='******')

        # Set up the following forum tree:
        #
        #     top_level_cat
        #         forum_1
        #         forum_2
        #             forum_2_child_1
        #     top_level_forum_1
        #     top_level_forum_2
        #         sub_cat
        #             sub_sub_forum
        #     top_level_forum_3
        #         forum_3
        #             forum_3_child_1
        #                 forum_3_child_1_1
        #                     deep_forum
        #     last_forum
        #
        self.top_level_cat = create_category_forum()

        self.forum_1 = create_forum(parent=self.top_level_cat)
        self.forum_2 = create_forum(parent=self.top_level_cat)
        self.forum_2_child_1 = create_forum(parent=self.forum_2)

        self.top_level_forum_1 = create_forum()

        self.top_level_forum_2 = create_forum()
        self.sub_cat = create_category_forum(parent=self.top_level_forum_2)
        self.sub_sub_forum = create_forum(parent=self.sub_cat)

        self.top_level_forum_3 = create_forum()
        self.forum_3 = create_forum(parent=self.top_level_forum_3)
        self.forum_3_child_1 = create_forum(parent=self.forum_3)
        self.forum_3_child_1_1 = create_forum(parent=self.forum_3_child_1)
        self.deep_forum = create_forum(parent=self.forum_3_child_1_1)

        self.last_forum = create_forum()

        # Set up a topic and some posts
        self.topic_1 = create_topic(forum=self.forum_1, poster=self.user)
        self.post_1 = PostFactory.create(topic=self.topic_1, poster=self.user)
        self.topic_2 = create_topic(forum=self.forum_2, poster=self.user)
        self.post_2 = PostFactory.create(topic=self.topic_2, poster=self.user)
        self.topic_3 = create_topic(forum=self.forum_2_child_1, poster=self.user)
        self.post_3 = PostFactory.create(topic=self.topic_3, poster=self.user)

        # Assign some permissions
        assign_perm('can_read_forum', self.user, self.top_level_cat)
        assign_perm('can_read_forum', self.user, self.forum_1)
        assign_perm('can_read_forum', self.user, self.forum_2)
        assign_perm('can_read_forum', self.user, self.forum_2_child_1)
        assign_perm('can_read_forum', self.user, self.top_level_forum_1)

        self.request = HttpRequest

        yield
    def setup(self):
        # Set up the following forum tree:
        #
        #     top_level_cat
        #         forum_1
        #         forum_2
        #             forum_2_child_1
        #             forum_2_child_2
        #                 forum_2_child_2_1
        #                 forum_2_child_2_2
        #     top_level_forum_1
        #     top_level_forum_2
        #         sub_cat
        #             sub_sub_forum
        #     top_level_forum_3
        #         forum_3
        #             forum_3_child_1
        #                 forum_3_child_1_1
        #                     deep_forum
        #     last_forum
        #
        self.top_level_cat = create_category_forum()

        self.forum_1 = create_forum(parent=self.top_level_cat)
        self.forum_2 = create_forum(parent=self.top_level_cat)
        self.forum_2_child_1 = create_link_forum(parent=self.forum_2)
        self.forum_2_child_2 = create_forum(parent=self.forum_2)
        self.forum_2_child_2_1 = create_forum(parent=self.forum_2_child_2)
        self.forum_2_child_2_2 = create_forum(parent=self.forum_2_child_2)

        self.top_level_forum_1 = create_forum()

        self.top_level_forum_2 = create_forum()
        self.sub_cat = create_category_forum(parent=self.top_level_forum_2)
        self.sub_sub_forum = create_forum(parent=self.sub_cat)

        self.top_level_forum_3 = create_forum()
        self.forum_3 = create_forum(parent=self.top_level_forum_3)
        self.forum_3_child_1 = create_forum(parent=self.forum_3)
        self.forum_3_child_1_1 = create_forum(parent=self.forum_3_child_1)
        self.deep_forum = create_forum(parent=self.forum_3_child_1_1)

        self.last_forum = create_forum()
示例#48
0
    def setup(self):
        # Permission handler
        self.perm_handler = PermissionHandler()

        # Set up the following forum tree:
        #
        #     top_level_cat
        #         forum_1
        #         forum_2
        #             forum_2_child_1
        #     top_level_forum_1
        #     top_level_forum_2
        #         sub_cat
        #             sub_sub_forum
        #     top_level_forum_3
        #         forum_3
        #             forum_3_child_1
        #                 forum_3_child_1_1
        #                     deep_forum
        #     last_forum
        #
        self.top_level_cat = create_category_forum()

        self.forum_1 = create_forum(parent=self.top_level_cat)
        self.forum_2 = create_forum(parent=self.top_level_cat)
        self.forum_2_child_1 = create_forum(parent=self.forum_2)

        self.top_level_forum_1 = create_forum()

        self.top_level_forum_2 = create_forum()
        self.sub_cat = create_category_forum(parent=self.top_level_forum_2)
        self.sub_sub_forum = create_forum(parent=self.sub_cat)

        self.top_level_forum_3 = create_forum()
        self.forum_3 = create_forum(parent=self.top_level_forum_3)
        self.forum_3_child_1 = create_forum(parent=self.forum_3)
        self.forum_3_child_1_1 = create_forum(parent=self.forum_3_child_1)
        self.deep_forum = create_forum(parent=self.forum_3_child_1_1)

        self.last_forum = create_forum()

        # Set up a topic and some posts
        self.topic_1 = create_topic(forum=self.forum_1, poster=self.user)
        self.post_1 = PostFactory.create(topic=self.topic_1, poster=self.user)
        self.topic_2 = create_topic(forum=self.forum_2, poster=self.user)
        self.post_2 = PostFactory.create(topic=self.topic_2, poster=self.user)
        self.topic_3 = create_topic(forum=self.forum_2_child_1,
                                    poster=self.user)
        self.post_3 = PostFactory.create(topic=self.topic_3, poster=self.user)

        # Assign some permissions
        assign_perm('can_read_forum', self.user, self.top_level_cat)
        assign_perm('can_read_forum', self.user, self.forum_1)
        assign_perm('can_read_forum', self.user, self.forum_2)
        assign_perm('can_read_forum', self.user, self.forum_2_child_1)
        assign_perm('can_read_forum', self.user, self.top_level_forum_1)

        self.sqs = SearchQuerySet()

        rebuild_index.Command().handle(interactive=False, verbosity=-1)

        yield

        # teardown
        # --

        clear_index.Command().handle(interactive=False, verbosity=-1)
示例#49
0
    def setup(self):
        # Permission handler
        self.perm_handler = PermissionHandler()

        # Create a basic user
        self.user = UserFactory.create(username='******')

        # Set up the following forum tree:
        #
        #     top_level_cat
        #         forum_1
        #         forum_2
        #             forum_2_child_1
        #     top_level_forum_1
        #     top_level_forum_2
        #         sub_cat
        #             sub_sub_forum
        #     top_level_forum_3
        #         forum_3
        #             forum_3_child_1
        #                 forum_3_child_1_1
        #                     deep_forum
        #     last_forum
        #
        self.top_level_cat = create_category_forum()

        self.forum_1 = create_forum(parent=self.top_level_cat)
        self.forum_2 = create_forum(parent=self.top_level_cat)
        self.forum_2_child_1 = create_forum(parent=self.forum_2)

        self.top_level_forum_1 = create_forum()

        self.top_level_forum_2 = create_forum()
        self.sub_cat = create_category_forum(parent=self.top_level_forum_2)
        self.sub_sub_forum = create_forum(parent=self.sub_cat)

        self.top_level_forum_3 = create_forum()
        self.forum_3 = create_forum(parent=self.top_level_forum_3)
        self.forum_3_child_1 = create_forum(parent=self.forum_3)
        self.forum_3_child_1_1 = create_forum(parent=self.forum_3_child_1)
        self.deep_forum = create_forum(parent=self.forum_3_child_1_1)

        self.last_forum = create_forum()

        # Set up a topic and some posts
        self.topic_1 = create_topic(forum=self.forum_1, poster=self.user)
        self.post_1 = PostFactory.create(topic=self.topic_1, poster=self.user)
        self.topic_2 = create_topic(forum=self.forum_2, poster=self.user)
        self.post_2 = PostFactory.create(topic=self.topic_2, poster=self.user)
        self.topic_3 = create_topic(forum=self.forum_2_child_1,
                                    poster=self.user)
        self.post_3 = PostFactory.create(topic=self.topic_3, poster=self.user)

        # Assign some permissions
        assign_perm('can_read_forum', self.user, self.top_level_cat)
        assign_perm('can_read_forum', self.user, self.forum_1)
        assign_perm('can_read_forum', self.user, self.forum_2)
        assign_perm('can_read_forum', self.user, self.forum_2_child_1)
        assign_perm('can_read_forum', self.user, self.top_level_forum_1)

        self.sqs = SearchQuerySet()

        management.call_command('clear_index', verbosity=0, interactive=False)
        management.call_command('update_index', verbosity=0)

        yield

        # teardown
        # --

        management.call_command('clear_index', verbosity=0, interactive=False)