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_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_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_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 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 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 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)