Пример #1
0
 def test_set_the_topic_as_unapproved_if_the_user_has_not_the_required_permission(
         self):
     # Setup
     form_data = {
         'subject': faker.text(max_nb_chars=200),
         'content': '[b]{}[/b]'.format(faker.text()),
     }
     # Run
     form_kwargs = {
         'data': form_data,
         'user': self.user,
         'user_ip': faker.ipv4(),
         'forum': self.top_level_forum,
         'topic': self.topic,
     }
     form = PostForm(**form_kwargs)
     # Check
     assert form.is_valid()
     post = form.save()
     assert not post.approved
     assign_perm('can_post_without_approval', self.user,
                 self.top_level_forum)
     form = PostForm(**form_kwargs)
     assert form.is_valid()
     post = form.save()
     assert post.approved
Пример #2
0
 def test_can_valid_a_basic_post(self):
     # Setup
     form_data = {
         'subject': 'Re: {}'.format(faker.text(max_nb_chars=200)),
         'content': '[b]{}[/b]'.format(faker.text()),
     }
     # Run
     form = PostForm(data=form_data,
                     user=self.user,
                     forum=self.top_level_forum,
                     topic=self.topic)
     valid = form.is_valid()
     # Check
     assert valid
Пример #3
0
 def test_set_the_topic_as_unapproved_if_the_user_has_not_the_required_permission(self):
     # Setup
     form_data = {
         'subject': faker.text(max_nb_chars=200),
         'content': '[b]{}[/b]'.format(faker.text()),
     }
     # Run
     form_kwargs = {
         'data': form_data,
         'user': self.user,
         'forum': self.top_level_forum,
         'topic': self.topic,
     }
     form = PostForm(**form_kwargs)
     # Check
     assert form.is_valid()
     post = form.save()
     assert not post.approved
     assign_perm('can_post_without_approval', self.user, self.top_level_forum)
     form = PostForm(**form_kwargs)
     assert form.is_valid()
     post = form.save()
     assert post.approved
Пример #4
0
 def test_can_valid_a_basic_post(self):
     # Setup
     form_data = {
         'subject': 'Re: {}'.format(faker.text(max_nb_chars=200)),
         'content': '[b]{}[/b]'.format(faker.text()),
     }
     # Run
     form = PostForm(
         data=form_data,
         user=self.user,
         forum=self.top_level_forum,
         topic=self.topic)
     valid = form.is_valid()
     # Check
     assert valid
Пример #5
0
 def test_adds_the_username_field_if_the_user_is_anonymous(self):
     # Setup
     form_data = {
         'subject': faker.text(max_nb_chars=200),
         'content': '[b]{}[/b]'.format(faker.text()),
         'username': '******',
     }
     # Run
     form = PostForm(data=form_data,
                     user=AnonymousUser(),
                     user_ip=faker.ipv4(),
                     forum=self.top_level_forum,
                     topic=self.topic)
     # Check
     assert 'username' in form.fields
     assert form.is_valid()
     post = form.save()
     assert post.username == 'testname'
Пример #6
0
 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,
                     forum=self.top_level_forum,
                     topic=self.topic,
                     instance=self.post)
     # Check
     assert form.is_valid()
     form.save()
     self.post.refresh_from_db()
     assert self.post.updates_count == initial_updates_count + 1
Пример #7
0
 def test_adds_the_update_reason_field_if_the_post_is_updated(self):
     # Setup
     form_data = {
         'subject': faker.text(max_nb_chars=200),
         'content': '[b]{}[/b]'.format(faker.text()),
         'update_reason': 'X',
     }
     # Run
     form = PostForm(data=form_data,
                     user=self.user,
                     forum=self.top_level_forum,
                     topic=self.topic,
                     instance=self.post)
     # Check
     assert 'update_reason' in form.fields
     assert form.is_valid()
     post = form.save()
     assert post.update_reason == 'X'
Пример #8
0
 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,
         forum=self.top_level_forum,
         topic=self.topic,
         instance=self.post)
     # Check
     assert form.is_valid()
     form.save()
     self.post.refresh_from_db()
     assert self.post.updates_count == initial_updates_count + 1
Пример #9
0
 def test_adds_the_update_reason_field_if_the_post_is_updated(self):
     # Setup
     form_data = {
         'subject': faker.text(max_nb_chars=200),
         'content': '[b]{}[/b]'.format(faker.text()),
         'update_reason': 'X',
     }
     # Run
     form = PostForm(
         data=form_data,
         user=self.user,
         forum=self.top_level_forum,
         topic=self.topic,
         instance=self.post)
     # Check
     assert 'update_reason' in form.fields
     assert form.is_valid()
     post = form.save()
     assert post.update_reason == 'X'
Пример #10
0
 def test_cannot_overwrite_the_original_poster_when_a_post_is_edited_by_another_user(self):
     # Setup
     user = UserFactory.create()
     assign_perm('can_read_forum', user, self.top_level_forum)
     assign_perm('can_start_new_topics', user, self.top_level_forum)
     form_data = {
         'subject': faker.text(max_nb_chars=200),
         'content': faker.text(),
     }
     # Run
     form = PostForm(
         data=form_data,
         user=user,
         forum=self.top_level_forum,
         topic=self.topic,
         instance=self.post)
     # Check
     assert form.is_valid()
     post = form.save()
     assert post.poster == self.user
Пример #11
0
 def test_cannot_allow_a_user_to_lock_a_topic_if_he_has_not_the_permission_to_lock_topics(self):
     # Setup
     form_data = {
         'subject': faker.text(max_nb_chars=200),
         'content': faker.text(),
         'lock_topic': True,
     }
     # Run
     form = PostForm(
         data=form_data,
         user=self.user,
         forum=self.top_level_forum,
         topic=self.topic,
         instance=self.post)
     # Check
     assert 'lock_topic' not in form.fields
     assert form.is_valid()
     post = form.save()
     post.refresh_from_db()
     assert not post.topic.is_locked
Пример #12
0
 def test_adds_the_username_field_if_the_user_is_anonymous(self):
     # Setup
     form_data = {
         'subject': faker.text(max_nb_chars=200),
         'content': '[b]{}[/b]'.format(faker.text()),
         'username': '******',
     }
     user = AnonymousUser()
     user.forum_key = '1234'
     # Run
     form = PostForm(
         data=form_data,
         user=user,
         forum=self.top_level_forum,
         topic=self.topic)
     # Check
     assert 'username' in form.fields
     assert form.is_valid()
     post = form.save()
     assert post.username == 'testname'