Exemple #1
0
 def test_allows_the_creation_of_announces_if_the_user_has_required_permission(self):
     # Setup
     form_data = {
         'subject': faker.text(max_nb_chars=200),
         'content': '[b]{}[/b]'.format(faker.text()),
         'topic_type': Topic.TOPIC_ANNOUNCE,
     }
     form_kwargs = {
         'data': form_data,
         'user': self.user,
         'forum': self.top_level_forum,
     }
     # Run & check
     form = TopicForm(**form_kwargs)
     assert not form.is_valid()
     choices = [ch[0] for ch in form.fields['topic_type'].choices]
     assert Topic.TOPIC_ANNOUNCE not in choices
     assign_perm('can_post_announcements', self.user, self.top_level_forum)
     form = TopicForm(**form_kwargs)
     assert form.is_valid()
     choices = [ch[0] for ch in form.fields['topic_type'].choices]
     assert Topic.TOPIC_ANNOUNCE in choices
Exemple #2
0
 def test_can_valid_a_basic_topic(self):
     # Setup
     form_data = {
         'subject': faker.text(max_nb_chars=200),
         'content': '[b]{}[/b]'.format(faker.text()),
         'topic_type': Topic.TOPIC_POST,
     }
     # Run
     form = TopicForm(data=form_data,
                      user=self.user,
                      forum=self.top_level_forum)
     valid = form.is_valid()
     # Check
     assert valid
 def test_can_valid_a_basic_topic(self):
     # Setup
     form_data = {
         'subject': faker.text(max_nb_chars=200),
         'content': '[b]{}[/b]'.format(faker.text()),
         'topic_type': Topic.TOPIC_POST,
     }
     # Run
     form = TopicForm(
         data=form_data,
         user=self.user,
         forum=self.top_level_forum)
     valid = form.is_valid()
     # Check
     assert valid
Exemple #4
0
 def test_creates_a_post_topic_if_no_topic_type_is_provided(self):
     # Setup
     form_data = {
         'subject': '{}'.format(faker.text(max_nb_chars=200)),
         'content': '[b]{}[/b]'.format(faker.text()),
     }
     # Run
     form = TopicForm(data=form_data,
                      user=self.user,
                      forum=self.top_level_forum)
     valid = form.is_valid()
     # Check
     assert valid
     post = form.save()
     assert post.topic.type == Topic.TOPIC_POST
Exemple #5
0
 def test_can_valid_a_basic_announce(self):
     # Setup
     form_data = {
         'subject': faker.text(max_nb_chars=200),
         'content': '[b]{}[/b]'.format(faker.text()),
         'topic_type': Topic.TOPIC_ANNOUNCE,
     }
     assign_perm('can_post_announcements', self.user, self.top_level_forum)
     # Run
     form = TopicForm(data=form_data,
                      user=self.user,
                      forum=self.top_level_forum)
     valid = form.is_valid()
     # Check
     assert valid
 def test_can_valid_a_basic_sticky_post(self):
     # Setup
     form_data = {
         'subject': faker.text(max_nb_chars=200),
         'content': '[b]{}[/b]'.format(faker.text()),
         'topic_type': Topic.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)
     valid = form.is_valid()
     # Check
     assert valid
 def test_creates_a_post_topic_if_no_topic_type_is_provided(self):
     # Setup
     form_data = {
         'subject': '{}'.format(faker.text(max_nb_chars=200)),
         'content': '[b]{}[/b]'.format(faker.text()),
     }
     # Run
     form = TopicForm(
         data=form_data,
         user=self.user,
         forum=self.top_level_forum)
     valid = form.is_valid()
     # Check
     assert valid
     post = form.save()
     assert post.topic.type == Topic.TOPIC_POST
 def test_can_valid_a_basic_announce(self):
     # Setup
     form_data = {
         'subject': faker.text(max_nb_chars=200),
         'content': '[b]{}[/b]'.format(faker.text()),
         'topic_type': Topic.TOPIC_ANNOUNCE,
     }
     assign_perm('can_post_announcements', self.user, self.top_level_forum)
     # Run
     form = TopicForm(
         data=form_data,
         user=self.user,
         forum=self.top_level_forum)
     valid = form.is_valid()
     # Check
     assert valid
Exemple #9
0
 def test_can_valid_a_basic_sticky_post(self):
     # Setup
     form_data = {
         'subject': 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)
     valid = form.is_valid()
     # Check
     assert valid
Exemple #10
0
 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.TOPIC_STICKY,
     }
     assign_perm('can_post_stickies', self.user, self.top_level_forum)
     # Run
     form = TopicForm(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.topic.refresh_from_db()
     assert self.topic.type == Topic.TOPIC_STICKY
Exemple #11
0
 def test_cannot_allow_users_to_create_polls_without_settings_the_maximum_options_number(self):
     # Setup
     form_data = {
         'subject': faker.text(max_nb_chars=200),
         'content': '[b]{}[/b]'.format(faker.text()),
         'topic_type': Topic.TOPIC_STICKY,
         'poll_question': faker.text(max_nb_chars=100),
     }
     assign_perm('can_create_polls', self.user, self.top_level_forum)
     # Run
     form = TopicForm(
         data=form_data,
         user=self.user,
         forum=self.top_level_forum,
         topic=self.topic,
         instance=self.post)
     # Check
     valid = form.is_valid()
     assert not valid
     assert 'poll_max_options' in form.errors
Exemple #12
0
 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.TOPIC_STICKY,
     }
     assign_perm('can_post_stickies', self.user, self.top_level_forum)
     # Run
     form = TopicForm(
         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.topic.refresh_from_db()
     assert self.topic.type == Topic.TOPIC_STICKY