def test_is_user_moderator_with_normal_user(self): """ is_user_moderator should return False, when the given User is not the moderator of the related board. """ state = self.p.is_user_moderator(u_helper.get_user_by_username('U1')) self.assertEqual(state, False)
def test_is_user_moderator_with_moderator_user(self): """ is_user_moderator should return True, when the given User is the moderator of the related board. """ state = self.p.is_user_moderator(u_helper.get_user_by_username('U2')) self.assertEqual(state, True)
def setUp(self): self.c = helper.create_category('C1') self.b = helper.create_board('B1', 'C1') u_helper.create_normal_user('U1') self.t = helper.create_thread('T1', 'B1', 'C1') self.u = u_helper.get_user_by_username('U1')
def test_normal_member_must_not_call_the_update_url_from_foreign_post(self): # flake8: noqa """ A normal user shouldn't see the editing optins for a post. Nethertheless we have to disable the url call for this user. """ p = helper.get_post_by_content("P1") self.client.force_login(u_helper.get_user_by_username("U2")) response = self.client.get(p.get_update_url()) self.assertEqual(response.status_code, 403)
def test_superuser_has_no_edit_options(self): """ """ t = helper.get_thread_by_title("T1") p = helper.get_post_by_content("P1") self.client.force_login(u_helper.get_user_by_username("U4")) response = self.client.get(t.get_absolute_url()) self.assertNotContains(response, str(p.get_update_url()), status_code=200) self.assertNotContains(response, str(p.get_delete_url()), status_code=200) self.assertEqual(len(response.context["posts"]), 1)
def test_post_editing_options_for_superuser(self): """ As moderator of the related board the requested user should get the options for editing and deleting for all post. """ self.client.force_login(u_helper.get_user_by_username("U4")) t = helper.get_thread_by_title("T1") p = helper.get_post_by_content("P1") response = self.client.get(t.get_absolute_url()) self.assertContains(response, str(p.get_update_url()), status_code=200) self.assertContains(response, str(p.get_delete_url()), status_code=200) self.assertEqual(len(response.context["posts"]), 1)
def test_post_editing_options_for_loggend_in_user(self): """ A logged in user shouln't get the options for manipulating a foreign post. """ self.client.force_login(u_helper.get_user_by_username("U2")) t = helper.get_thread_by_title("T1") p = helper.get_post_by_content("P1") response = self.client.get(t.get_absolute_url()) self.assertNotContains(response, str(p.get_update_url()), status_code=200) self.assertNotContains(response, str(p.get_delete_url()), status_code=200) self.assertEqual(len(response.context["posts"]), 1)
def test_detail_view_with_two_posts_as_moderator(self): """ The thread has two posts and will be visited as logged in member. This member is moderator of the related board. """ u_helper.create_normal_user('Gustav', helper.get_board_by_name('News')) helper.create_post('Hi1!', 'Gustav', 'Thread 1', 'News', 'Public') helper.create_post('Hi2!', 'Gustav', 'Thread 1', 'News', 'Public') self.client.force_login(u_helper.get_user_by_username('Gustav')) response = self.client.get( reverse('board:threads-detail', kwargs={'category': 'public', 'board': 'news', 'pk': str(self.t.pk)})) self.assertContains(response, '', status_code=200) self.assertEqual(len(response.context['posts']), 2) self.assertEqual(response.context['is_moderator'], True)