def test_read_thread__unexisted_info(self): self.assertEqual(ThreadReadInfoPrototype._db_count(), 0) read_info = ThreadReadInfoPrototype.read_thread(self.thread, self.account) self.assertEqual(ThreadReadInfoPrototype._db_count(), 1) self.assertEqual(read_info.thread_id, self.thread.id) self.assertEqual(read_info.account_id, self.account.id) self.assertTrue(read_info.read_at > datetime.datetime.now() - datetime.timedelta(seconds=1))
def create_post(self): new_post_delay = PostPrototype.get_new_post_delay(self.account) if new_post_delay > 0: error_message = ( u'Создавать новые сообщения можно не чаще раза в %d секунд. <br/>Задержка увеличивается для игроков, только начинающих общаться на форуме.<br/> Вы сможете создать новое сообщение через %d сек.' % (forum_settings.POST_DELAY, int(new_post_delay))) return self.json_error('forum.create_post.delay', error_message) new_post_form = forms.NewPostForm(self.request.POST) if not new_post_form.is_valid(): return self.json_error('forum.create_post.form_errors', new_post_form.errors) post = PostPrototype.create(self.thread, self.account, new_post_form.c.text) if self.account.is_authenticated(): ThreadReadInfoPrototype.read_thread(self.thread, self.account) return self.json_ok( data={ 'next_url': url('forum:threads:show', self.thread.id, page=self.thread.paginator.pages_count) + ('#m%d' % post.id) })
def test_read_thread__unexisted_info(self): self.assertEqual(ThreadReadInfoPrototype._db_count(), 0) read_info = ThreadReadInfoPrototype.read_thread(self.thread, self.account) self.assertEqual(ThreadReadInfoPrototype._db_count(), 1) self.assertEqual(read_info.thread_id, self.thread.id) self.assertEqual(read_info.account_id, self.account.id) self.assertTrue(read_info.read_at > datetime.datetime.now() - datetime.timedelta(seconds=1))
def test_thread_is_new_messages__thread_read(self): read_state = self.get_read_state() self.assertTrue(read_state.thread_is_new(self.thread)) ThreadReadInfoPrototype.read_thread(self.thread, self.account) read_state = self.get_read_state() self.assertFalse(read_state.thread_is_new(self.thread))
def test_thread_is_new_messages__thread_read(self): read_state = self.get_read_state() self.assertTrue(read_state.thread_is_new(self.thread)) ThreadReadInfoPrototype.read_thread(self.thread, self.account) read_state = self.get_read_state() self.assertFalse(read_state.thread_is_new(self.thread))
def test_thread_has_new_messages__read(self): ThreadReadInfoPrototype.read_thread(self.thread, self.account) read_state = self.get_read_state() self.assertFalse(read_state.thread_has_new_messages(self.thread)) self.thread._model.updated_at = datetime.datetime.now() self.thread.save() self.assertTrue(read_state.thread_has_new_messages(self.thread))
def handle(self, *args, **options): from the_tale.common.postponed_tasks.prototypes import PostponedTaskPrototype from the_tale.forum.prototypes import SubCategoryReadInfoPrototype, ThreadReadInfoPrototype from the_tale.post_service.prototypes import MessagePrototype PostponedTaskPrototype.remove_old_tasks() ThreadReadInfoPrototype.remove_old_infos() SubCategoryReadInfoPrototype.remove_old_infos() MessagePrototype.remove_old_messages()
def test_thread_has_new_messages__read(self): ThreadReadInfoPrototype.read_thread(self.thread, self.account) read_state = self.get_read_state() self.assertFalse(read_state.thread_has_new_messages(self.thread)) self.thread._model.updated_at = datetime.datetime.now() self.thread.save() self.assertTrue(read_state.thread_has_new_messages(self.thread))
def handle(self, *args, **options): from the_tale.common.postponed_tasks.prototypes import PostponedTaskPrototype from the_tale.forum.prototypes import SubCategoryReadInfoPrototype, ThreadReadInfoPrototype from the_tale.post_service.prototypes import MessagePrototype PostponedTaskPrototype.remove_old_tasks() ThreadReadInfoPrototype.remove_old_infos() SubCategoryReadInfoPrototype.remove_old_infos() MessagePrototype.remove_old_messages()
def test_create_post_success(self): self.assertEqual(ThreadReadInfoPrototype._db_count(), 0) response = self.client.post(url('forum:threads:create-post', self.thread3.id), {'text': 'thread3-test-post'}) post = PostPrototype._db_get_object(4) self.check_ajax_ok(response, data={'next_url': url('forum:threads:show', self.thread3.id) + ('?page=1#m%d' % post.id)}) self.assertEqual(Post.objects.all().count(), 5) self.assertEqual(ThreadReadInfoPrototype._db_count(), 1) self.assertEqual(ThreadReadInfoPrototype._db_get_object(0).thread_id, self.thread3.id)
def get_thread(self, page=1): thread_data = ThreadPageData() if not thread_data.initialize(account=self.account, thread=self.thread, page=page): return self.redirect(thread_data.paginator.last_page_url, permanent=False) if self.account.is_authenticated: ThreadReadInfoPrototype.read_thread(self.thread, self.account) return self.template('forum/thread.html', {'category': self.category, 'thread': self.thread, 'thread_data': thread_data} )
def test_create_post_success(self): self.assertEqual(ThreadReadInfoPrototype._db_count(), 0) response = self.client.post(url('forum:threads:create-post', self.thread3.id), {'text': 'thread3-test-post'}) post = PostPrototype._db_get_object(4) self.check_ajax_ok(response, data={'next_url': url('forum:threads:show', self.thread3.id) + ('?page=1#m%d' % post.id)}) self.assertEqual(Post.objects.all().count(), 5) self.assertEqual(ThreadReadInfoPrototype._db_count(), 1) self.assertEqual(ThreadReadInfoPrototype._db_get_object(0).thread_id, self.thread3.id)
def get_thread(self, page=1): thread_data = ThreadPageData() if not thread_data.initialize( account=self.account, thread=self.thread, page=page): return self.redirect(thread_data.paginator.last_page_url, permanent=False) if self.account.is_authenticated(): ThreadReadInfoPrototype.read_thread(self.thread, self.account) return self.template( 'forum/thread.html', { 'category': self.category, 'thread': self.thread, 'thread_data': thread_data })
def create_post(self): new_post_delay = PostPrototype.get_new_post_delay(self.account) if new_post_delay > 0: error_message = ('Создавать новые сообщения можно не чаще раза в %d секунд. <br/>Задержка увеличивается для игроков, только начинающих общаться на форуме.<br/> Вы сможете создать новое сообщение через %d сек.' % ( forum_settings.POST_DELAY, int(new_post_delay))) return self.json_error('forum.create_post.delay', error_message) new_post_form = forms.NewPostForm(self.request.POST) if not new_post_form.is_valid(): return self.json_error('forum.create_post.form_errors', new_post_form.errors) post = PostPrototype.create(self.thread, self.account, new_post_form.c.text) if self.account.is_authenticated: ThreadReadInfoPrototype.read_thread(self.thread, self.account) return self.json_ok(data={'next_url': url('forum:threads:show', self.thread.id, page=self.thread.paginator.pages_count) + ('#m%d' % post.id)})
def test_remove_old_infos(self): read_info_1 = ThreadReadInfoPrototype.read_thread(self.thread, self.account) read_info_2 = ThreadReadInfoPrototype.read_thread(self.thread, self.account_2) removed_time = datetime.datetime.now() - datetime.timedelta(seconds=forum_settings.UNREAD_STATE_EXPIRE_TIME) ThreadReadInfoPrototype._model_class.objects.filter(id=read_info_2.id).update(read_at=removed_time) self.assertEqual(ThreadReadInfoPrototype._db_count(), 2) ThreadReadInfoPrototype.remove_old_infos() self.assertEqual(ThreadReadInfoPrototype._db_count(), 1) self.assertEqual(ThreadReadInfoPrototype._db_get_object(0).id, read_info_1.id)
def test_remove_old_infos(self): read_info_1 = ThreadReadInfoPrototype.read_thread(self.thread, self.account) read_info_2 = ThreadReadInfoPrototype.read_thread(self.thread, self.account_2) removed_time = datetime.datetime.now() - datetime.timedelta(seconds=forum_settings.UNREAD_STATE_EXPIRE_TIME) ThreadReadInfoPrototype._model_class.objects.filter(id=read_info_2.id).update(read_at=removed_time) self.assertEqual(ThreadReadInfoPrototype._db_count(), 2) ThreadReadInfoPrototype.remove_old_infos() self.assertEqual(ThreadReadInfoPrototype._db_count(), 1) self.assertEqual(ThreadReadInfoPrototype._db_get_object(0).id, read_info_1.id)
def test_subcategory_has_new_messages__unread_but_thread_read(self): SubCategoryReadInfoPrototype.read_subcategory(subcategory=self.subcategory, account=self.account) self.subcategory._model.updated_at = datetime.datetime.now() self.subcategory.save() self.assertTrue(self.get_read_state().subcategory_has_new_messages(self.subcategory)) ThreadReadInfoPrototype.read_thread(self.thread, self.account) ThreadReadInfoPrototype.read_thread(self.thread_2, self.account) ThreadReadInfoPrototype.read_thread(self.thread_3, self.account) self.assertFalse(self.get_read_state().subcategory_has_new_messages(self.subcategory))
def test_subcategory_has_new_messages__unread_but_thread_read(self): SubCategoryReadInfoPrototype.read_subcategory( subcategory=self.subcategory, account=self.account) self.subcategory._model.updated_at = datetime.datetime.now() self.subcategory.save() self.assertTrue(self.get_read_state().subcategory_has_new_messages( self.subcategory)) ThreadReadInfoPrototype.read_thread(self.thread, self.account) ThreadReadInfoPrototype.read_thread(self.thread_2, self.account) ThreadReadInfoPrototype.read_thread(self.thread_3, self.account) self.assertFalse(self.get_read_state().subcategory_has_new_messages( self.subcategory))
def test_get_thread_unlogined(self): self.request_logout() self.check_html_ok(self.request_html(url('forum:threads:show', self.thread1.id)), texts=(('pgf-new-post-form', 0), self.fixture.clan_1.abbr)) self.assertEqual(ThreadReadInfoPrototype._db_count(), 0)
def test_get_thread(self): self.assertEqual(ThreadReadInfoPrototype._db_count(), 0) self.check_html_ok(self.request_html(url('forum:threads:show', self.thread1.id)), texts=('pgf-new-post-form',)) self.assertEqual(ThreadReadInfoPrototype._db_count(), 1)
def test_get_thread_unlogined(self): self.request_logout() self.check_html_ok(self.request_html(url('forum:threads:show', self.thread1.id)), texts=(('pgf-new-post-form', 0), self.fixture.clan_1.abbr)) self.assertEqual(ThreadReadInfoPrototype._db_count(), 0)
def test_get_thread(self): self.assertEqual(ThreadReadInfoPrototype._db_count(), 0) self.check_html_ok(self.request_html(url('forum:threads:show', self.thread1.id)), texts=('pgf-new-post-form',)) self.assertEqual(ThreadReadInfoPrototype._db_count(), 1)
def get_threads_read_info(self): if not self._account.is_authenticated(): return {} return ThreadReadInfoPrototype.get_threads_info(account_id=self._account.id)
def get_threads_read_info(self): if not self._account.is_authenticated: return {} return ThreadReadInfoPrototype.get_threads_info( account_id=self._account.id)