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)
     topic = refresh(self.topic)
     assert topic.last_post_on == middle_post.created
 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)
     topic = refresh(self.topic)
     assert topic.last_post == middle_post
Exemple #3
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)
     topic = refresh(self.topic)
     assert topic.last_post == middle_post
Exemple #4
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)
     topic = refresh(self.topic)
     assert topic.last_post_on == middle_post.created
Exemple #5
0
 def test_can_approve_posts(self):
     # Setup
     correct_url = reverse('forum_moderation:approve_queued_post',
                           kwargs={'pk': self.post.pk})
     # Run
     self.client.post(correct_url, follow=True)
     # Check
     post = refresh(self.post)
     assert post.approved
 def test_can_update_topics_to_sticky_topics(self):
     # Setup
     correct_url = reverse(
         'forum_moderation:topic_update_to_announce',
         kwargs={'slug': self.topic.slug, 'pk': self.topic.pk})
     # Run
     self.client.post(correct_url, follow=True)
     # Check
     topic = refresh(self.topic)
     assert topic.is_announce
 def test_can_lock_topics(self):
     # Setup
     correct_url = reverse(
         'forum_moderation:topic_lock',
         kwargs={'slug': self.topic.slug, 'pk': self.topic.pk})
     # Run
     self.client.post(correct_url, follow=True)
     # Check
     topic = refresh(self.topic)
     assert topic.is_locked
 def test_can_approve_posts(self):
     # Setup
     correct_url = reverse(
         'forum_moderation:approve_queued_post',
         kwargs={'pk': self.post.pk})
     # Run
     self.client.post(correct_url, follow=True)
     # Check
     post = refresh(self.post)
     assert post.approved
 def test_can_be_used_to_refresh_a_model_instance(self):
     # Setup
     forum_name = self.forum.name
     new_forum_name = faker.text(max_nb_chars=200)
     # Run
     Forum.objects.all().update(name=new_forum_name)
     # Check
     assert self.forum.name == forum_name
     forum = refresh(self.forum)
     assert forum.name == new_forum_name
 def test_save_cannot_trigger_the_update_of_the_member_posts_count_if_the_related_post_is_not_approved(self):
     # Setup
     post = PostFactory.build(topic=self.topic, poster=self.u1, approved=False)
     profile = ForumProfile.objects.get(user=self.u1)
     initial_posts_count = profile.posts_count
     # Run
     post.save()
     # Check
     profile = refresh(profile)
     assert profile.posts_count == initial_posts_count
Exemple #11
0
 def test_save_triggers_the_update_of_the_member_posts_count_if_the_related_post_is_approved(
         self):
     # Setup
     post = PostFactory.build(topic=self.topic, poster=self.u1)
     profile = ForumProfile.objects.get(user=self.u1)
     initial_posts_count = profile.posts_count
     # Run
     post.save()
     # Check
     profile = refresh(profile)
     assert profile.posts_count == initial_posts_count + 1
Exemple #12
0
 def test_can_update_topics_to_sticky_topics(self):
     # Setup
     correct_url = reverse('forum_moderation:topic_update_to_announce',
                           kwargs={
                               'slug': self.topic.slug,
                               'pk': self.topic.pk
                           })
     # Run
     self.client.post(correct_url, follow=True)
     # Check
     topic = refresh(self.topic)
     assert topic.is_announce
Exemple #13
0
 def test_can_lock_topics(self):
     # Setup
     correct_url = reverse('forum_moderation:topic_lock',
                           kwargs={
                               'slug': self.topic.slug,
                               'pk': self.topic.pk
                           })
     # Run
     self.client.post(correct_url, follow=True)
     # Check
     topic = refresh(self.topic)
     assert topic.is_locked
 def test_can_move_topics(self):
     # Setup
     correct_url = reverse(
         'forum_moderation:topic_move',
         kwargs={'slug': self.topic.slug, 'pk': self.topic.pk})
     post_data = {
         'forum': self.other_forum.id,
     }
     # Run
     self.client.post(correct_url, post_data, follow=True)
     # Check
     topic = refresh(self.topic)
     assert topic.forum == self.other_forum
 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(profile)
     assert profile.posts_count == initial_posts_count
 def test_can_increase_the_posts_count_of_the_post_being_created(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=True)
     # Check
     profile = refresh(profile)
     assert profile.posts_count == initial_posts_count + 1
Exemple #17
0
 def test_save_trigger_the_update_of_the_member_posts_count_if_the_related_post_switch_to_approved(
         self):
     # Setup
     post = PostFactory.create(topic=self.topic,
                               poster=self.u1,
                               approved=False)
     profile = ForumProfile.objects.get(user=self.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
Exemple #18
0
 def test_can_update_options_associated_with_an_existing_poll(self):
     # Setup
     poll = TopicPollFactory.create(topic=self.topic)
     option_1 = TopicPollOptionFactory.create(poll=poll)
     option_2 = TopicPollOptionFactory.create(poll=poll)
     form_data = {
         'form-0-id': option_1.pk,
         'form-0-text': faker.text(max_nb_chars=100),
         'form-1-id': option_2.pk,
         'form-1-text': option_2.text,
         'form-INITIAL_FORMS': 2,
         'form-TOTAL_FORMS': 2,
         'form-MAX_NUM_FORMS': 1000,
     }
     # Run
     form = TopicPollOptionFormset(data=form_data,
                                   topic=refresh(self.topic))
     valid = form.is_valid()
     # Check
     assert valid
     form.save()
     option_1 = refresh(option_1)
     assert option_1.text == form_data['form-0-text']
 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(profile)
     assert profile.posts_count == initial_posts_count - 1
 def test_can_update_options_associated_with_an_existing_poll(self):
     # Setup
     poll = TopicPollFactory.create(topic=self.topic)
     option_1 = TopicPollOptionFactory.create(poll=poll)
     option_2 = TopicPollOptionFactory.create(poll=poll)
     form_data = {
         'form-0-id': option_1.pk,
         'form-0-text': faker.text(max_nb_chars=100),
         'form-1-id': option_2.pk,
         'form-1-text': option_2.text,
         'form-INITIAL_FORMS': 2,
         'form-TOTAL_FORMS': 2,
         'form-MAX_NUM_FORMS': 1000,
     }
     # Run
     form = TopicPollOptionFormset(
         data=form_data,
         topic=refresh(self.topic))
     valid = form.is_valid()
     # Check
     assert valid
     form.save()
     option_1 = refresh(option_1)
     assert option_1.text == form_data['form-0-text']
 def test_append_empty_forms_only_when_no_initial_data_is_provided(self):
     # Setup
     poll = TopicPollFactory.create(topic=self.topic)
     option_1 = TopicPollOptionFactory.create(poll=poll)
     option_2 = TopicPollOptionFactory.create(poll=poll)
     form_data_1 = {
         'form-0-id': option_1.pk,
         'form-0-text': faker.text(max_nb_chars=100),
         'form-1-id': option_2.pk,
         'form-1-text': option_2.text,
         'form-INITIAL_FORMS': 2,
         'form-TOTAL_FORMS': 2,
         'form-MAX_NUM_FORMS': 1000,
     }
     # Run
     form_1 = TopicPollOptionFormset(
         data=form_data_1,
         topic=refresh(self.topic))
     form_2 = TopicPollOptionFormset(topic=refresh(self.topic))  # poll already created
     form_3 = TopicPollOptionFormset(topic=self.alt_topic)  # no poll
     # Check
     assert form_1.total_form_count() == 2
     assert form_2.total_form_count() == 2
     assert form_3.total_form_count() == 2
Exemple #22
0
 def test_can_move_topics(self):
     # Setup
     correct_url = reverse('forum_moderation:topic_move',
                           kwargs={
                               'slug': self.topic.slug,
                               'pk': self.topic.pk
                           })
     post_data = {
         'forum': self.other_forum.id,
     }
     # Run
     self.client.post(correct_url, post_data, follow=True)
     # Check
     topic = refresh(self.topic)
     assert topic.forum == self.other_forum
Exemple #23
0
 def test_append_empty_forms_only_when_no_initial_data_is_provided(self):
     # Setup
     poll = TopicPollFactory.create(topic=self.topic)
     option_1 = TopicPollOptionFactory.create(poll=poll)
     option_2 = TopicPollOptionFactory.create(poll=poll)
     form_data_1 = {
         'form-0-id': option_1.pk,
         'form-0-text': faker.text(max_nb_chars=100),
         'form-1-id': option_2.pk,
         'form-1-text': option_2.text,
         'form-INITIAL_FORMS': 2,
         'form-TOTAL_FORMS': 2,
         'form-MAX_NUM_FORMS': 1000,
     }
     # Run
     form_1 = TopicPollOptionFormset(data=form_data_1,
                                     topic=refresh(self.topic))
     form_2 = TopicPollOptionFormset(topic=refresh(
         self.topic))  # poll already created
     form_3 = TopicPollOptionFormset(topic=self.alt_topic)  # no poll
     # Check
     assert form_1.total_form_count() == 2
     assert form_2.total_form_count() == 2
     assert form_3.total_form_count() == 2
 def test_can_move_and_unlock_a_topic_if_it_was_locked(self):
     # Setup
     self.topic.status = self.topic.STATUS_CHOICES.topic_locked
     self.topic.save()
     correct_url = reverse(
         'forum_moderation:topic_move',
         kwargs={'slug': self.topic.slug, 'pk': self.topic.pk})
     post_data = {
         'forum': self.other_forum.id,
         'lock_topic': False,
     }
     # Run
     self.client.post(correct_url, post_data, follow=True)
     # Check
     topic = refresh(self.topic)
     assert topic.forum == self.other_forum
     assert not topic.is_locked
Exemple #25
0
 def test_can_move_and_unlock_a_topic_if_it_was_locked(self):
     # Setup
     self.topic.status = self.topic.STATUS_CHOICES.topic_locked
     self.topic.save()
     correct_url = reverse('forum_moderation:topic_move',
                           kwargs={
                               'slug': self.topic.slug,
                               'pk': self.topic.pk
                           })
     post_data = {
         'forum': self.other_forum.id,
         'lock_topic': False,
     }
     # Run
     self.client.post(correct_url, post_data, follow=True)
     # Check
     topic = refresh(self.topic)
     assert topic.forum == self.other_forum
     assert not topic.is_locked
 def test_increments_the_post_updates_counter_in_case_of_post_edition(self):
     # Setup
     form_data = {
         'subject': 'Re: {}'.format(faker.text(max_nb_chars=200)),
         'content': '[b]{}[/b]'.format(faker.text()),
     }
     initial_updates_count = self.post.updates_count
     # Run
     form = PostForm(data=form_data,
                     user=self.user,
                     user_ip=faker.ipv4(),
                     forum=self.top_level_forum,
                     topic=self.topic,
                     instance=self.post)
     # Check
     assert form.is_valid()
     form.save()
     self.post = refresh(self.post)
     assert self.post.updates_count == initial_updates_count + 1
 def test_can_be_used_to_update_the_topic_type(self):
     # Setup
     form_data = {
         'subject': 'Re: {}'.format(faker.text(max_nb_chars=200)),
         'content': '[b]{}[/b]'.format(faker.text()),
         'topic_type': Topic.TYPE_CHOICES.topic_sticky,
     }
     assign_perm('can_post_stickies', self.user, self.top_level_forum)
     # Run
     form = TopicForm(data=form_data,
                      user=self.user,
                      user_ip=faker.ipv4(),
                      forum=self.top_level_forum,
                      topic=self.topic,
                      instance=self.post)
     # Check
     assert form.is_valid()
     form.save()
     self.topic = refresh(self.topic)
     assert self.topic.type == Topic.TYPE_CHOICES.topic_sticky
    def save(self, *args, **kwargs):
        # It is vital to track the changes of the forum associated with a topic in order to
        # maintain counters up-to-date.
        old_instance = None
        if self.pk:
            old_instance = self.__class__._default_manager.get(pk=self.pk)

        # Update the slug field
        self.slug = slugify(force_text(self.subject))

        # Do the save
        super(AbstractTopic, self).save(*args, **kwargs)

        # If any change has been made to the parent forum, trigger the update of the counters
        if old_instance and old_instance.forum != self.forum:
            self.update_trackers()
            # The previous parent forum counters should also be updated
            if old_instance.forum:
                old_forum = refresh(old_instance.forum)
                old_forum.update_trackers()
Exemple #29
0
    def save(self, *args, **kwargs):
        # It is vital to track the changes of the forum associated with a topic in order to
        # maintain counters up-to-date.
        old_instance = None
        if self.pk:
            old_instance = self.__class__._default_manager.get(pk=self.pk)

        # Update the slug field
        self.slug = slugify(force_text(self.subject))

        # Do the save
        super(AbstractTopic, self).save(*args, **kwargs)

        # If any change has been made to the parent forum, trigger the update of the counters
        if old_instance and old_instance.forum != self.forum:
            self.update_trackers()
            # The previous parent forum counters should also be updated
            if old_instance.forum:
                old_forum = refresh(old_instance.forum)
                old_forum.update_trackers()
    def save(self, *args, **kwargs):
        # It is vital to track the changes of the parent associated with a forum in order to
        # maintain counters up-to-date and to trigger other operations such as permissions updates.
        old_instance = None
        if self.pk:
            old_instance = self.__class__._default_manager.get(pk=self.pk)

        # Update the slug field
        self.slug = slugify(force_text(self.name))

        # Do the save
        super(AbstractForum, self).save(*args, **kwargs)

        # If any change has been made to the forum parent, trigger the update of the counters
        if old_instance and old_instance.parent != self.parent:
            self.update_trackers()
            # The previous parent trackers should also be updated
            if old_instance.parent:
                old_parent = refresh(old_instance.parent)
                old_parent.update_trackers()
            # Trigger the 'forum_moved' signal
            signals.forum_moved.send(sender=self, previous_parent=old_instance.parent)