text: 
  import smart_imports
  
  smart_imports.all()
  
  
  class TestModeration(utils_testcase.TestCase):
  
      def setUp(self):
          super(TestModeration, self).setUp()
  
          game_logic.create_test_map()
  
          self.main_account = self.accounts_factory.create_account()
          self.moderator = self.accounts_factory.create_account()
          self.second_account = self.accounts_factory.create_account()
  
          group = utils_permissions.sync_group(conf.settings.MODERATOR_GROUP_NAME, ['forum.moderate_post', 'forum.moderate_thread'])
  
          group.user_set.add(self.moderator._model)
  
          self.category = prototypes.CategoryPrototype.create(caption='cat-caption', slug='cat-slug', order=0)
          self.subcategory = prototypes.SubCategoryPrototype.create(category=self.category, caption='subcat-caption', order=0)
          self.subcategory2 = prototypes.SubCategoryPrototype.create(category=self.category, caption='subcat2-caption', order=1, closed=True)
          self.thread = prototypes.ThreadPrototype.create(self.subcategory, 'thread-caption', self.main_account, 'thread-text')
          self.post = prototypes.PostPrototype.create(self.thread, self.main_account, 'post-text')
          self.post2 = prototypes.PostPrototype.create(self.thread, self.main_account, 'post2-text')
          self.post5 = prototypes.PostPrototype.create(self.thread, self.main_account, 'post5-text', technical=True)
  
          self.thread2 = prototypes.ThreadPrototype.create(self.subcategory, 'thread2-caption', self.main_account, 'thread2-text')
          self.post3 = prototypes.PostPrototype.create(self.thread2, self.main_account, 'post3-text')
          self.post4 = prototypes.PostPrototype.create(self.thread2, self.second_account, 'post4-text')
  
          self.thread3 = prototypes.ThreadPrototype.create(self.subcategory, 'thread3-caption', self.second_account, 'thread3-text')
  
  
  class TestModerationRequests(TestModeration):
  
      def test_initialization(self):
          self.assertEqual(models.Category.objects.all().count(), 1)
          self.assertEqual(models.SubCategory.objects.all().count(), 2)
          self.assertEqual(models.Thread.objects.all().count(), 3)
          self.assertEqual(models.Post.objects.all().count(), 8)
  
  
  class TestModerationSubcategoryRequests(TestModeration):
  
      ###############################
      # add thread
      ###############################
  
      # button
      def test_loggined_has_add_thread_button(self):
          self.request_login(self.main_account.email)
          self.check_html_ok(self.request_html(utils_urls.url('forum:subcategories:show', self.subcategory.id)), texts=[('pgf-new-thread-button', 1)])
  
      def test_unlogined_has_add_thread_button(self):
          self.check_html_ok(self.request_html(utils_urls.url('forum:subcategories:show', self.subcategory.id)), texts=[('pgf-new-thread-button', 0)])
  
      def test_loggined_has_no_add_thread_button_in_closed_theme(self):
          self.request_login(self.main_account.email)
          self.check_html_ok(self.request_html(utils_urls.url('forum:subcategories:show', self.subcategory2.id)), texts=[('pgf-new-thread-button', 0)])
  
      def test_moderator_has_add_thread_button_in_closed_theme(self):
          self.request_login(self.moderator.email)
          self.check_html_ok(self.request_html(utils_urls.url('forum:subcategories:show', self.subcategory2.id)), texts=[('pgf-new-thread-button', 1)])
  
  
  class TestModerationNewThreadRequests(TestModeration):
      # new page
  
      def test_loggined_new_thread_page(self):
          self.request_login(self.main_account.email)
          self.check_html_ok(self.request_html(utils_urls.url('forum:subcategories:new-thread', self.subcategory.id)),
                             texts=[('pgf-new-thread-form', 2)])
  
      @mock.patch('the_tale.accounts.prototypes.AccountPrototype.is_ban_forum', True)
      def test_loggined_new_thread_page__banned(self):
          self.request_login(self.main_account.email)
          self.check_html_ok(self.request_html(utils_urls.url('forum:subcategories:new-thread', self.subcategory.id)),
                             texts=[('pgf-new-thread-form', 0),
                                    ('common.ban_forum', 1)])
  
      def test_unlogined_new_thread_page(self):
          request_url = utils_urls.url('forum:subcategories:new-thread', self.subcategory.id)
          self.check_redirect(request_url, accounts_logic.login_page_url(request_url))
  
      def test_loggined_new_thread_page_in_closed_theme(self):
          self.request_login(self.main_account.email)
          self.check_html_ok(self.request_html(utils_urls.url('forum:subcategories:new-thread', self.subcategory2.id)),
                             texts=[('pgf-new-thread-form', 0), ('forum.new_thread.no_permissions', 1)])
  
      def test_moderator_new_thread_page_in_closed_theme(self):
          self.request_login(self.moderator.email)
          self.check_html_ok(self.request_html(utils_urls.url('forum:subcategories:new-thread', self.subcategory2.id)),
                             texts=[('pgf-new-thread-form', 2)])
  
  
  class TestModerationCreateThreadRequests(TestModeration):
  
      @mock.patch('the_tale.forum.conf.settings.THREAD_DELAY', 0)
      def test_loggined_create_thread_page(self):
          self.request_login(self.main_account.email)
          response = self.client.post(utils_urls.url('forum:subcategories:create-thread', self.subcategory.id),
                                      {'caption': 'thread5-caption', 'text': 'thread5-text'})
  
          thread = models.Thread.objects.all().order_by('-created_at')[0]
  
          self.check_ajax_ok(response, {'thread_id': thread.id,
                                        'thread_url': utils_urls.url('forum:threads:show', thread.id)})
  
      @mock.patch('the_tale.accounts.prototypes.AccountPrototype.is_ban_forum', True)
      def test_loggined_create_thread_page__banned(self):
          old_threads_number = prototypes.ThreadPrototype._db_count()
          self.request_login(self.main_account.email)
          response = self.client.post(utils_urls.url('forum:subcategories:create-thread', self.subcategory.id),
                                      {'caption': 'thread5-caption', 'text': 'thread5-text'})
          self.check_ajax_error(response, 'common.ban_forum')
  
          self.assertEqual(old_threads_number, prototypes.ThreadPrototype._db_count())
  
      def test_unlogined_create_thread_page(self):
          self.check_ajax_error(self.client.post(utils_urls.url('forum:subcategories:create-thread', self.subcategory.id),
                                                 {'caption': 'thread5-caption', 'text': 'thread5-text'}),
                                'common.login_required')
  
      def test_loggined_create_thread_page_in_closed_theme(self):
          self.request_login(self.main_account.email)
          self.check_ajax_error(self.client.post(utils_urls.url('forum:subcategories:create-thread', self.subcategory2.id),
                                                 {'caption': 'thread5-caption', 'text': 'thread5-text'}),
                                'forum.create_thread.no_permissions')
  
      @mock.patch('the_tale.forum.conf.settings.THREAD_DELAY', 0)
      def test_moderator_create_thread_page_in_closed_theme(self):
          self.request_login(self.moderator.email)
          response = self.client.post(utils_urls.url('forum:subcategories:create-thread', self.subcategory2.id),
                                      {'caption': 'thread5-caption', 'text': 'thread5-text'})
  
          thread = models.Thread.objects.all().order_by('-created_at')[0]
  
          self.check_ajax_ok(response, {'thread_id': thread.id,
                                        'thread_url': utils_urls.url('forum:threads:show', thread.id)})
  
  
  class TestModerationShowThreadRequests(TestModeration):
      ###############################
      # thread editing
      ###############################
  
      # button
      def test_unlogined_user_has_edit_theme_button(self):
          self.check_html_ok(self.request_html(utils_urls.url('forum:threads:show', self.thread.id)), texts=[('pgf-change-thread-button', 0)])
  
      def test_main_user_has_edit_theme_button(self):
          self.request_login(self.main_account.email)
          self.check_html_ok(self.request_html(utils_urls.url('forum:threads:show', self.thread.id)), texts=[('pgf-change-thread-button', 1)])
  
      def test_second_user_has_edit_theme_button(self):
          self.request_login(self.second_account.email)
          self.check_html_ok(self.request_html(utils_urls.url('forum:threads:show', self.thread.id)), texts=[('pgf-change-thread-button', 0)])
  
      def test_moderator_user_has_edit_theme_button(self):
          self.request_login(self.moderator.email)
          self.check_html_ok(self.request_html(utils_urls.url('forum:threads:show', self.thread.id)), texts=[('pgf-change-thread-button', 1)])
  
      ###############################
      # thread deletion
      ###############################
  
      def test_main_user_has_remove_thread_button(self):
          self.request_login(self.main_account.email)
          self.check_html_ok(self.request_html(utils_urls.url('forum:threads:show', self.thread.id)), texts=[('pgf-remove-thread-button', 0)])
  
      def test_moderator_has_remove_thread_button(self):
          self.request_login(self.moderator.email)
          self.check_html_ok(self.request_html(utils_urls.url('forum:threads:show', self.thread.id)), texts=[('pgf-remove-thread-button', 2)])
  
      def test_second_user_has_remove_thread_button(self):
          self.request_login(self.second_account.email)
          self.check_html_ok(self.request_html(utils_urls.url('forum:threads:show', self.thread.id)), texts=[('pgf-remove-thread-button', 0)])
  
      ###############################
      # post deletion
      ###############################
  
      def test_main_user_has_remove_post_button(self):
          self.request_login(self.main_account.email)
          self.check_html_ok(self.request_html(utils_urls.url('forum:threads:show', self.thread.id)), texts=[('pgf-remove-post-button', 3)])
          self.check_html_ok(self.request_html(utils_urls.url('forum:threads:show', self.thread2.id)), texts=[('pgf-remove-post-button', 3)])
  
      def test_moderator_has_remove_post_button(self):
          self.request_login(self.moderator.email)
          self.check_html_ok(self.request_html(utils_urls.url('forum:threads:show', self.thread.id)), texts=[('pgf-remove-post-button', 3)])
          self.check_html_ok(self.request_html(utils_urls.url('forum:threads:show', self.thread2.id)), texts=[('pgf-remove-post-button', 3)])
  
      def test_second_user_has_remove_post_button(self):
          self.request_login(self.second_account.email)
          self.check_html_ok(self.request_html(utils_urls.url('forum:threads:show', self.thread.id)), texts=[('pgf-remove-post-button', 0)])
          self.check_html_ok(self.request_html(utils_urls.url('forum:threads:show', self.thread2.id)), texts=[('pgf-remove-post-button', 2)])
  
      ###############################
      # post editing
      ###############################
  
      # button
      def test_main_user_has_edit_post_button(self):
          self.request_login(self.main_account.email)
          self.check_html_ok(self.request_html(utils_urls.url('forum:threads:show', self.thread.id)), texts=[('pgf-change-post-button', 3)])
          self.check_html_ok(self.request_html(utils_urls.url('forum:threads:show', self.thread2.id)), texts=[('pgf-change-post-button', 2)])
  
      def test_moderator_has_edit_post_button(self):
          self.request_login(self.moderator.email)
          self.check_html_ok(self.request_html(utils_urls.url('forum:threads:show', self.thread.id)), texts=[('pgf-change-post-button', 3)])
          self.check_html_ok(self.request_html(utils_urls.url('forum:threads:show', self.thread2.id)), texts=[('pgf-change-post-button', 3)])
  
      def test_second_user_has_edit_post_button(self):
          self.request_login(self.second_account.email)
          self.check_html_ok(self.request_html(utils_urls.url('forum:threads:show', self.thread.id)), texts=[('pgf-change-post-button', 0)])
          self.check_html_ok(self.request_html(utils_urls.url('forum:threads:show', self.thread2.id)), texts=[('pgf-change-post-button', 1)])
          self.check_html_ok(self.request_html(utils_urls.url('forum:threads:show', self.thread3.id)), texts=[('pgf-change-post-button', 1)])
  
  
  class TestModerationEditThreadRequests(TestModeration):
  
      # page
      def test_unlogined_user_edit_theme_page(self):
          request_url = utils_urls.url('forum:threads:edit', self.thread.id)
          self.check_redirect(request_url, accounts_logic.login_page_url(request_url))
  
      @mock.patch('the_tale.accounts.prototypes.AccountPrototype.is_ban_forum', True)
      def test_edit_theme_page__banned(self):
          self.request_login(self.main_account.email)
          self.check_html_ok(self.request_html(utils_urls.url('forum:threads:edit', self.thread.id)), texts=['common.ban_forum'])
  
      def test_main_user_edit_theme_page(self):
          self.request_login(self.main_account.email)
          self.check_html_ok(self.request_html(utils_urls.url('forum:threads:edit', self.thread.id)), texts=[('pgf-edit-thread-form', 2),
                                                                                                            ('pgf-thread-subcategory', 0),
                                                                                                            ('thread-caption', 3),
                                                                                                            ('id_important', 0)])
  
      def test_second_user_edit_theme_button(self):
          self.request_login(self.second_account.email)
          self.check_html_ok(self.request_html(utils_urls.url('forum:threads:edit', self.thread.id)), texts=[('pgf-edit-thread-form', 0),
                                                                                                            ('forum.edit_thread.no_permissions', 1),
                                                                                                            ('pgf-thread-subcategory', 0),
                                                                                                            ('thread-caption', 0),
                                                                                                            ('id_important', 0)])
  
      def test_moderator_user_edit_theme_button(self):
          self.request_login(self.moderator.email)
          self.check_html_ok(self.request_html(utils_urls.url('forum:threads:edit', self.thread.id)), texts=[('pgf-edit-thread-form', 2),
                                                                                                            ('pgf-thread-subcategory', 1),
                                                                                                            ('thread-caption', 3),
                                                                                                            'id_important'])
  
  
  class TestModerationUpdateThreadRequests(TestModeration):
  
      # update request
      def test_unlogined_user_update_theme(self):
          self.check_ajax_error(self.client.post(utils_urls.url('forum:threads:update', self.thread.id), {'caption': 'edited caption'}),
                                'common.login_required')
          self.assertEqual(models.Thread.objects.get(id=self.thread.id).caption, self.thread.caption)
  
      @mock.patch('the_tale.accounts.prototypes.AccountPrototype.is_ban_forum', True)
      def test_update_theme__banned(self):
          self.request_login(self.main_account.email)
          self.check_ajax_error(self.client.post(utils_urls.url('forum:threads:update', self.thread.id), {'caption': 'edited caption'}),
                                'common.ban_forum')
          self.assertEqual(models.Thread.objects.get(id=self.thread.id).caption, self.thread.caption)
  
      def test_main_user_update_theme(self):
          self.request_login(self.main_account.email)
          self.check_ajax_ok(self.client.post(utils_urls.url('forum:threads:update', self.thread.id), {'caption': 'edited caption'}))
          self.assertEqual(models.Thread.objects.get(id=self.thread.id).caption, 'edited caption')
  
      def test_main_user_update_theme_with_subcategory(self):
          self.assertEqual(self.subcategory.posts_count, 5)
          self.assertEqual(self.subcategory.threads_count, 3)
          self.assertEqual(self.subcategory2.posts_count, 0)
          self.assertEqual(self.subcategory2.threads_count, 0)
  
          self.request_login(self.main_account.email)
          self.check_ajax_error(self.client.post(utils_urls.url('forum:threads:update', self.thread.id), {'caption': 'edited caption', 'subcategory': self.subcategory2.id}),
                                'forum.update_thread.no_permissions_to_change_subcategory')
          self.assertEqual(models.Thread.objects.get(id=self.thread.id).caption, self.thread.caption)
  
          self.assertEqual(self.subcategory.posts_count, 5)
          self.assertEqual(self.subcategory.threads_count, 3)
          self.assertEqual(self.subcategory2.posts_count, 0)
          self.assertEqual(self.subcategory2.threads_count, 0)
  
      def test_main_user_update_theme_with_important(self):
          self.assertFalse(self.thread.important)
  
          self.request_login(self.main_account.email)
          self.check_ajax_ok(self.client.post(utils_urls.url('forum:threads:update', self.thread.id), {'caption': 'edited caption', 'important': True}))
  
          self.thread.reload()
          self.assertFalse(self.thread.important)
  
      def test_main_user_update_theme_with_form_errors(self):
          self.request_login(self.main_account.email)
          self.check_ajax_error(self.client.post(utils_urls.url('forum:threads:update', self.thread.id), {'caption': ''}),
                                'forum.update_thread.form_errors')
          thread = models.Thread.objects.get(id=self.thread.id)
          self.assertEqual(thread.caption, self.thread.caption)
          self.assertEqual(thread.subcategory_id, self.subcategory.id)
  
      def test_second_user_update_theme(self):
          self.request_login(self.second_account.email)
          self.check_ajax_error(self.client.post(utils_urls.url('forum:threads:update', self.thread.id), {'caption': 'edited caption'}),
                                'forum.update_thread.no_permissions')
          self.assertEqual(models.Thread.objects.get(id=self.thread.id).caption, self.thread.caption)
  
      def test_moderator_user_update_theme(self):
          self.request_login(self.moderator.email)
          self.check_ajax_ok(self.client.post(utils_urls.url('forum:threads:update', self.thread.id), {'caption': 'edited caption'}))
          self.assertEqual(models.Thread.objects.get(id=self.thread.id).caption, 'edited caption')
  
      def test_moderator_user_update_theme_with_important(self):
          self.assertFalse(self.thread.important)
  
          self.request_login(self.moderator.email)
          self.check_ajax_ok(self.client.post(utils_urls.url('forum:threads:update', self.thread.id), {'caption': 'edited caption', 'important': True}))
  
          self.thread.reload()
          self.assertTrue(self.thread.important)
  
      def test_moderator_user_update_theme_with_subcategory(self):
          self.assertEqual(self.subcategory.posts_count, 5)
          self.assertEqual(self.subcategory.threads_count, 3)
          self.assertEqual(self.subcategory2.posts_count, 0)
          self.assertEqual(self.subcategory2.threads_count, 0)
  
          self.request_login(self.moderator.email)
          self.check_ajax_ok(self.client.post(utils_urls.url('forum:threads:update', self.thread.id), {'caption': 'edited caption', 'subcategory': self.subcategory2.id}))
          thread = models.Thread.objects.get(id=self.thread.id)
          self.assertEqual(thread.caption, 'edited caption')
          self.assertEqual(thread.subcategory_id, self.subcategory2.id)
  
          subcategory = models.SubCategory.objects.get(id=self.subcategory.id)
          subcategory2 = models.SubCategory.objects.get(id=self.subcategory2.id)
  
          self.assertEqual(subcategory.posts_count, 2)
          self.assertEqual(subcategory.threads_count, 2)
          self.assertEqual(subcategory2.posts_count, 3)
          self.assertEqual(subcategory2.threads_count, 1)
  
  
  class TestModerationDeleteThreadRequests(TestModeration):
  
      def test_main_user_remove_thread(self):
          self.request_login(self.main_account.email)
          self.check_ajax_error(self.client.post(utils_urls.url('forum:threads:delete', self.thread.id)), 'forum.delete_thread.no_permissions')
          self.assertEqual(models.Thread.objects.all().count(), 3)
          self.assertEqual(models.Post.objects.all().count(), 8)
  
      def test_main_user_remove_thread_in_closed_subcategory(self):
          self.subcategory._model.closed = True
          self.subcategory.save()
  
          self.request_login(self.main_account.email)
          self.check_ajax_error(self.client.post(utils_urls.url('forum:threads:delete', self.thread.id)), 'forum.delete_thread.no_permissions')
          self.assertEqual(models.Thread.objects.all().count(), 3)
          self.assertEqual(models.Post.objects.all().count(), 8)
  
      def test_moderator_remove_thread(self):
          self.request_login(self.moderator.email)
          self.check_ajax_ok(self.client.post(utils_urls.url('forum:threads:delete', self.thread.id)))
          self.assertEqual(models.Thread.objects.all().count(), 2)
          self.assertEqual(models.Post.objects.all().count(), 4)
  
      def test_second_user_remove_thread(self):
          self.request_login(self.second_account.email)
          self.check_ajax_error(self.client.post(utils_urls.url('forum:threads:delete', self.thread.id)), 'forum.delete_thread.no_permissions')
          self.assertEqual(models.Thread.objects.all().count(), 3)
          self.assertEqual(models.Post.objects.all().count(), 8)
  
      def test_second_user_remove_unlogined(self):
          self.check_ajax_error(self.client.post(utils_urls.url('forum:threads:delete', self.thread.id)), 'common.login_required')
          self.assertEqual(models.Thread.objects.all().count(), 3)
          self.assertEqual(models.Post.objects.all().count(), 8)
  
      def test_second_user_remove_fast_account(self):
          self.request_login(self.main_account.email)
  
          self.main_account.is_fast = True
          self.main_account.save()
  
          self.check_ajax_error(self.client.post(utils_urls.url('forum:threads:delete', self.thread.id)), 'common.fast_account')
          self.assertEqual(models.Thread.objects.all().count(), 3)
          self.assertEqual(models.Post.objects.all().count(), 8)
  
      @mock.patch('the_tale.accounts.prototypes.AccountPrototype.is_ban_forum', True)
      def test_second_user_remove_banned(self):
          self.request_login(self.main_account.email)
          self.check_ajax_error(self.client.post(utils_urls.url('forum:threads:delete', self.thread.id)), 'common.ban_forum')
          self.assertEqual(models.Thread.objects.all().count(), 3)
          self.assertEqual(models.Post.objects.all().count(), 8)
  
  
  class TestModerationDeletePostRequests(TestModeration):
  
      # main user
      def test_main_user_remove_post(self):
          self.request_login(self.main_account.email)
          self.assertEqual(models.Thread.objects.get(id=self.thread.id).posts_count, 3)
          self.assertEqual(models.SubCategory.objects.get(id=self.subcategory.id).posts_count, 5)
  
          self.check_ajax_ok(self.client.post(utils_urls.url('forum:posts:delete', self.post.id)))
          self.assertTrue(prototypes.PostPrototype.get_by_id(self.post.id).is_removed)
  
          # check if edit & remove buttons has dissapeared
          self.check_html_ok(self.request_html(utils_urls.url('forum:threads:show', self.thread.id)), texts=[('pgf-remove-post-button', 2),
                                                                                                            ('pgf-change-post-button', 2)])
  
      def test_main_user_remove_post_of_second_user(self):
          self.assertEqual(self.second_account, self.post4.author)
          self.request_login(self.main_account.email)
          self.check_ajax_ok(self.client.post(utils_urls.url('forum:posts:delete', self.post4.id)))
          self.assertEqual(models.Post.objects.all().count(), 8)
  
      @mock.patch('the_tale.accounts.prototypes.AccountPrototype.is_ban_forum', True)
      def test_banned_main_user_remove_post_of_second_user(self):
          old_posts_count = prototypes.PostPrototype._db_count()
          self.assertEqual(self.second_account, self.post4.author)
          self.request_login(self.main_account.email)
          self.check_ajax_error(self.client.post(utils_urls.url('forum:posts:delete', self.post4.id)), 'common.ban_forum')
          self.assertEqual(old_posts_count, prototypes.PostPrototype._db_count())
  
      def test_main_user_remove_first_post(self):
          self.request_login(self.main_account.email)
          post = models.Post.objects.filter(thread=self.thread.id).order_by('created_at')[0]
          self.check_ajax_error(self.client.post(utils_urls.url('forum:posts:delete', post.id)), 'forum.delete_post.remove_first_post')
          self.assertEqual(models.Post.objects.all().count(), 8)
  
      def test_main_user_remove_moderators_post(self):
          post = prototypes.PostPrototype.create(self.thread, self.moderator, 'moderator-post-text')
          self.request_login(self.main_account.email)
          self.check_ajax_error(self.client.post(utils_urls.url('forum:posts:delete', post.id)), 'forum.delete_post.remove_moderator_post')
          self.assertEqual(models.Post.objects.all().count(), 9)
  
      # moderator
      def test_moderator_remove_post(self):
          self.request_login(self.moderator.email)
          self.check_ajax_ok(self.client.post(utils_urls.url('forum:posts:delete', self.post.id)))
          self.assertEqual(models.Post.objects.all().count(), 8)
  
          # check if edit & remove buttons has dissapeared
          self.check_html_ok(self.request_html(utils_urls.url('forum:threads:show', self.thread.id)), texts=[('pgf-remove-post-button', 2),
                                                                                                            ('pgf-change-post-button', 2)])
  
      def test_moderator_remove_post_of_second_user(self):
          self.assertEqual(self.second_account, self.post4.author)
          self.request_login(self.moderator.email)
          self.check_ajax_ok(self.client.post(utils_urls.url('forum:posts:delete', self.post4.id)))
          self.assertEqual(models.Post.objects.all().count(), 8)
  
      def test_moderator_remove_first_post(self):
          self.request_login(self.moderator.email)
          post = models.Post.objects.filter(thread=self.thread.id).order_by('created_at')[0]
          self.check_ajax_error(self.client.post(utils_urls.url('forum:posts:delete', post.id)), 'forum.delete_post.remove_first_post')
          self.assertEqual(models.Post.objects.all().count(), 8)
  
      # second user
      def test_second_user_remove_post(self):
          self.request_login(self.second_account.email)
          self.check_ajax_error(self.client.post(utils_urls.url('forum:posts:delete', self.post.id)), 'forum.delete_post.no_permissions')
          self.assertEqual(models.Post.objects.all().count(), 8)
  
      def test_second_user_remove_post_of_second_user(self):
          self.assertEqual(self.second_account, self.post4.author)
          self.request_login(self.second_account.email)
          self.check_ajax_ok(self.client.post(utils_urls.url('forum:posts:delete', self.post4.id)))
          self.assertEqual(models.Post.objects.all().count(), 8)
  
      def test_second_user_remove_first_post(self):
          self.request_login(self.second_account.email)
          post = models.Post.objects.filter(thread=self.thread3.id).order_by('created_at')[0]
          self.check_ajax_error(self.client.post(utils_urls.url('forum:posts:delete', post.id)), 'forum.delete_post.remove_first_post')
          self.assertEqual(models.Post.objects.all().count(), 8)
  
  
  class TestModerationEditPostRequests(TestModeration):
  
      # edit post page
      def test_edit_page_unlogined(self):
          request_url = utils_urls.url('forum:posts:edit', self.post.id)
          self.check_redirect(request_url, accounts_logic.login_page_url(request_url))
  
      def test_edit_page_fast_account(self):
          self.request_login(self.main_account.email)
  
          self.main_account.is_fast = True
          self.main_account.save()
  
          self.check_html_ok(self.request_html(utils_urls.url('forum:posts:edit', self.post.id)), texts=['common.fast_account'])
  
      @mock.patch('the_tale.accounts.prototypes.AccountPrototype.is_ban_forum', True)
      def test_edit_page_banned(self):
          self.request_login(self.main_account.email)
          self.check_html_ok(self.request_html(utils_urls.url('forum:posts:edit', self.post.id)), texts=['common.ban_forum'])
  
      def test_edit_page_no_permissions(self):
          self.request_login(self.main_account.email)
          self.check_html_ok(self.request_html(utils_urls.url('forum:posts:edit', self.post4.id)), texts=['forum.edit_thread.no_permissions'])
  
      def test_edit_page_moderator_access(self):
          self.request_login(self.moderator.email)
          self.check_html_ok(self.request_html(utils_urls.url('forum:posts:edit', self.post.id)), texts=[('pgf-change-post-form', 2), ('post-text', 1)])
  
      def test_edit_page_author_access(self):
          self.request_login(self.main_account.email)
          self.check_html_ok(self.request_html(utils_urls.url('forum:posts:edit', self.post.id)), texts=[('pgf-change-post-form', 2), ('post-text', 1)])
  
  
  class TestModerationUpdatePostRequests(TestModeration):
      # update post
  
      def test_update_post_unlogined(self):
          self.check_ajax_error(self.client.post(utils_urls.url('forum:posts:update', self.post.id)), 'common.login_required')
          self.assertEqual(self.post.text, models.Post.objects.get(id=self.post.id).text)
  
      def test_update_post_fast_account(self):
          self.request_login(self.main_account.email)
  
          self.main_account.is_fast = True
          self.main_account.save()
  
          self.check_ajax_error(self.client.post(utils_urls.url('forum:posts:update', self.post.id)), 'common.fast_account')
          self.assertEqual(self.post.text, models.Post.objects.get(id=self.post.id).text)
  
      @mock.patch('the_tale.accounts.prototypes.AccountPrototype.is_ban_forum', True)
      def test_update_post_banned(self):
          self.request_login(self.main_account.email)
          self.check_ajax_error(self.client.post(utils_urls.url('forum:posts:update', self.post.id)), 'common.ban_forum')
          self.assertEqual(self.post.text, models.Post.objects.get(id=self.post.id).text)
  
      def test_update_post_no_permissions(self):
          self.request_login(self.main_account.email)
          self.check_ajax_error(self.client.post(utils_urls.url('forum:posts:update', self.post4.id)), 'forum.update_post.no_permissions')
          self.assertEqual(self.post4.text, models.Post.objects.get(id=self.post4.id).text)
  
      def test_update_post_form_errors(self):
          self.request_login(self.moderator.email)
          self.check_ajax_error(self.client.post(utils_urls.url('forum:posts:update', self.post.id)), 'forum.update_post.form_errors')
  
      def test_update_post_moderator_access(self):
          self.request_login(self.moderator.email)
          self.check_ajax_ok(self.client.post(utils_urls.url('forum:posts:update', self.post.id), {'text': 'new text'}))
          self.assertEqual(models.Post.objects.get(id=self.post.id).text, 'new text')
  
      def test_update_post_author_access(self):
          self.request_login(self.main_account.email)
          self.check_ajax_ok(self.client.post(utils_urls.url('forum:posts:update', self.post.id), {'text': 'new text'}))
          self.assertEqual(models.Post.objects.get(id=self.post.id).text, 'new text')
  