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)
Exemplo n.º 2
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_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)
Exemplo n.º 4
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)
Exemplo n.º 5
0
 def test_cannot_tell_that_a_non_approved_post_is_the_last_post(self):
     # Setup
     create_topic(forum=self.top_level_forum, poster=self.u1)
     # Run & check
     middle_post = PostFactory.create(topic=self.topic, poster=self.u1)
     PostFactory.create(topic=self.topic, poster=self.u1, approved=False)
     self.topic.refresh_from_db()
     assert self.topic.last_post == middle_post
Exemplo n.º 6
0
 def test_cannot_update_its_last_post_date_with_the_creation_date_of_a_non_approved_post(self):
     # Setup
     create_topic(forum=self.top_level_forum, poster=self.u1)
     # Run & check
     middle_post = PostFactory.create(topic=self.topic, poster=self.u1)
     PostFactory.create(topic=self.topic, poster=self.u1, approved=False)
     self.topic.refresh_from_db()
     assert self.topic.last_post_on == middle_post.created
Exemplo n.º 7
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)
Exemplo n.º 8
0
 def test_cannot_mark_parent_forums_as_read_when_marking_a_list_of_forums_as_read_if_they_have_unread_topics(self):  # noqa
     # Setup
     new_topic_1 = create_topic(forum=self.forum_2_child_2, poster=self.u1)
     new_topic_2 = create_topic(forum=self.forum_2, poster=self.u1)
     PostFactory.create(topic=new_topic_1, poster=self.u1)
     PostFactory.create(topic=new_topic_2, poster=self.u1)
     # Run
     self.tracks_handler.mark_forums_read([self.forum_2_child_2, ], self.u2)
     # Check
     assert set(self.tracks_handler.get_unread_forums(self.u2)) \
         == set([self.top_level_cat_1, self.forum_2, ])
     assert ForumReadTrack.objects.filter(user=self.u2).count() == 2
Exemplo n.º 9
0
    def test_saves_its_numbers_of_posts_and_topics(self):
        # Run & check
        topic = create_topic(forum=self.top_level_forum, poster=self.u1)
        PostFactory.create(topic=topic, poster=self.u1)
        PostFactory.create(topic=topic, poster=self.u1)
        assert self.top_level_forum.posts_count == topic.posts.filter(approved=True).count()
        assert self.top_level_forum.topics_count == self.top_level_forum.topics.count()

        topic2 = create_topic(forum=self.top_level_forum, poster=self.u1, approved=False)
        PostFactory.create(topic=topic2, poster=self.u1, approved=False)
        assert self.top_level_forum.posts_count == \
            topic.posts.filter(approved=True).count() + topic2.posts.filter(approved=True).count()
        assert self.top_level_forum.topics_count == \
            self.top_level_forum.topics.filter(approved=True).count()
Exemplo n.º 10
0
 def test_can_mark_subforums_read(self):
     # Setup
     new_topic = create_topic(forum=self.forum_2, poster=self.u1)
     PostFactory.create(topic=new_topic, poster=self.u1)
     new_topic = create_topic(forum=self.forum_4, poster=self.u1)
     PostFactory.create(topic=new_topic, poster=self.u1)
     correct_url = reverse(
         'forum_tracking:mark_subforums_read', kwargs={'pk': self.top_level_cat_1.pk})
     # Run
     response = self.client.get(correct_url, follow=True)
     # Check
     assert response.status_code == 200
     assert set(self.tracks_handler.get_unread_forums(self.user)) \
         == set([self.top_level_cat_2, self.forum_4, ])
Exemplo n.º 11
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)
Exemplo n.º 12
0
 def test_knows_if_it_is_an_announce(self):
     # Setup
     announce = create_topic(
         forum=self.top_level_forum, poster=self.u1,
         type=Topic.TOPIC_ANNOUNCE)
     # Run & check
     assert announce.is_announce
Exemplo n.º 13
0
 def test_knows_if_it_is_sticky(self):
     # Setup
     sticky_topic = create_topic(
         forum=self.top_level_forum, poster=self.u1,
         type=Topic.TOPIC_STICKY)
     # Run & check
     assert sticky_topic.is_sticky
Exemplo n.º 14
0
 def test_knows_if_it_is_sticky(self):
     # Setup
     sticky_topic = create_topic(
         forum=self.top_level_forum, poster=self.u1,
         type=Topic.TYPE_CHOICES.topic_sticky)
     # Run & check
     assert sticky_topic.is_sticky
Exemplo n.º 15
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
Exemplo n.º 16
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)
Exemplo n.º 17
0
 def test_knows_if_it_is_an_announce(self):
     # Setup
     announce = create_topic(
         forum=self.top_level_forum, poster=self.u1,
         type=Topic.TYPE_CHOICES.topic_announce)
     # Run & check
     assert announce.is_announce
Exemplo n.º 18
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
Exemplo n.º 19
0
 def test_says_that_a_topic_with_a_creation_date_greater_than_the_forum_mark_time_is_unread(self):  # noqa
     # Setup
     new_topic = create_topic(forum=self.forum_2, poster=self.u1)
     PostFactory.create(topic=new_topic, poster=self.u1)
     # Run
     unread_topics = self.tracks_handler.get_unread_topics(self.forum_2.topics.all(), self.u2)
     # Check
     assert unread_topics == [new_topic, ]
Exemplo n.º 20
0
 def test_says_that_a_topic_is_unread_if_the_related_forum_is_not_marked(self):
     # Setup
     new_topic = create_topic(forum=self.forum_3, poster=self.u1)
     PostFactory.create(topic=new_topic, poster=self.u1)
     # Run
     unread_topics = self.tracks_handler.get_unread_topics(self.forum_3.topics.all(), self.u2)
     # Check
     assert unread_topics == [new_topic, ]
Exemplo n.º 21
0
 def test_cannot_say_that_a_forum_is_unread_if_it_is_not_visible_by_the_user(self):
     # Setup
     new_topic = create_topic(forum=self.forum_3, poster=self.u1)
     PostFactory.create(topic=new_topic, poster=self.u1)
     # Run
     unread_forums = self.tracks_handler.get_unread_forums(self.u2)
     # Check
     assert self.forum_3 not in unread_forums
Exemplo n.º 22
0
 def test_can_mark_topics_read(self):
     # Setup
     new_topic = create_topic(forum=self.forum_2, poster=self.u1)
     PostFactory.create(topic=new_topic, poster=self.u1)
     # Run
     self.tracks_handler.mark_topic_read(new_topic, self.u2)
     # Check
     assert list(self.tracks_handler.get_unread_forums(self.u2)) == []
Exemplo n.º 23
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)
Exemplo n.º 24
0
 def test_has_a_last_post(self):
     # Setup
     new_topic = create_topic(forum=self.top_level_forum, poster=self.u1)
     # Run & check
     middle_post = PostFactory.create(topic=self.topic, poster=self.u1)
     assert self.topic.last_post == middle_post
     new_last_post = Post.objects.create(topic=self.topic, poster=self.u1, content='last')
     assert self.topic.last_post == new_last_post
     assert new_topic.last_post is None
Exemplo n.º 25
0
 def test_cannot_mark_forums_read_for_anonymous_users(self):
     # Setup
     new_topic = create_topic(forum=self.forum_2, poster=self.u1)
     PostFactory.create(topic=new_topic, poster=self.u1)
     initial_read_tracks_count = ForumReadTrack.objects.count()
     # Run
     self.tracks_handler.mark_forums_read(Forum.objects.all(), AnonymousUser())
     # Check
     assert ForumReadTrack.objects.count() == initial_read_tracks_count
Exemplo n.º 26
0
 def test_cannot_say_that_a_topic_is_unread_if_it_has_been_marked(self):
     # Setup
     PostFactory.create(topic=self.topic, poster=self.u1)
     new_topic = create_topic(forum=self.forum_2, poster=self.u1)
     TopicReadTrackFactory.create(topic=self.topic, user=self.u2)
     # Run
     unread_topics = self.tracks_handler.get_unread_topics(self.forum_2.topics.all(), self.u2)
     # Check
     assert unread_topics == [new_topic, ]
Exemplo n.º 27
0
 def test_marks_parent_forums_as_read_when_marking_a_list_of_forums_as_read(self):
     # Setup
     new_topic = create_topic(forum=self.forum_2_child_2, poster=self.u1)
     PostFactory.create(topic=new_topic, poster=self.u1)
     # Run
     self.tracks_handler.mark_forums_read([self.forum_2_child_2, ], self.u2)
     # Check
     assert list(self.tracks_handler.get_unread_forums(self.u2)) == []
     assert ForumReadTrack.objects.filter(user=self.u2).count() == 3
Exemplo n.º 28
0
 def test_can_mark_forum_topics_read(self):
     # Setup
     new_topic = create_topic(forum=self.forum_4, poster=self.u1)
     PostFactory.create(topic=new_topic, poster=self.u1)
     correct_url = reverse('forum_tracking:mark_topics_read', kwargs={'pk': self.forum_4.pk})
     # Run
     response = self.client.get(correct_url, follow=True)
     # Check
     assert response.status_code == 200
     assert list(self.tracks_handler.get_unread_topics(self.forum_4.topics.all(), self.user)) == []
Exemplo n.º 29
0
 def test_cannot_insert_unapproved_topics_into_the_context(self):
     # Setup
     new_topic = create_topic(forum=self.forum_4, poster=self.u1)
     PostFactory.create(topic=new_topic, poster=self.u1, approved=False)
     correct_url = reverse('forum_tracking:unread_topics')
     # Run
     response = self.client.get(correct_url, follow=True)
     # Check
     assert response.status_code == 200
     assert not response.context_data['topics']
Exemplo n.º 30
0
 def test_does_not_consider_non_approved_posts(self):
     # Setup
     topic_5 = create_topic(forum=self.forum_2, poster=self.user)
     PostFactory.create(topic=topic_5, poster=self.user, approved=False)
     correct_url = reverse('forum_member:user_topics')
     # Run
     response = self.client.get(correct_url, follow=True)
     # Check
     assert response.status_code == 200
     assert list(response.context_data['topics']) == [self.topic_4, self.topic_2, self.topic_1, ]
Exemplo n.º 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.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)
Exemplo n.º 32
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)
Exemplo n.º 33
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)
Exemplo n.º 34
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]
Exemplo n.º 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)

        # 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
Exemplo n.º 36
0
    def setup(self):
        self.u1 = UserFactory.create()
        self.u2 = UserFactory.create()
        self.g1 = GroupFactory.create()
        self.u1.groups.add(self.g1)
        self.u2.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_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)

        # 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_2)
Exemplo n.º 37
0
 def test_can_properly_create_the_slug_for_topic_titles_containing_non_latin_words(self):
     # Run & check
     topic = create_topic(forum=self.top_level_forum, poster=self.u1, subject='你好')
     assert topic.slug == '你好'
Exemplo n.º 38
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)
Exemplo n.º 39
0
 def test_fallback_the_slug_to_a_hardcoded_value_if_the_generated_slug_is_empty(self):
     topic = create_topic(forum=self.top_level_forum, poster=self.u1, subject='&&')
     assert topic.slug == 'topic'
Exemplo n.º 40
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)
Exemplo n.º 41
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