コード例 #1
0
    def test_set(self):
        """set allows for changing count of threads"""
        session = {}
        counter = NewThreadsCount(self.user, session)
        counter.set(128)

        self.assertEqual(int(counter), 128)
        self.assertEqual(session[counter.name]['threads'], 128)
コード例 #2
0
    def test_cast_to_bool(self):
        """counter is castable to bool"""
        counter = NewThreadsCount(self.user, {})
        self.assertFalse(counter)

        threads = [testutils.post_thread(self.forum) for t in xrange(42)]
        counter = NewThreadsCount(self.user, {})
        self.assertTrue(counter)
コード例 #3
0
    def test_decrease_zero(self):
        """decrease is not allowing for negative threads counts"""
        session = {}
        counter = NewThreadsCount(self.user, session)
        counter.decrease()

        self.assertEqual(int(counter), 0)
        self.assertEqual(session[counter.name]['threads'], 0)
コード例 #4
0
    def test_cast_to_int(self):
        """counter is castable to int"""
        counter = NewThreadsCount(self.user, {})
        self.assertEqual(int(counter), 0)

        threads = [testutils.post_thread(self.forum) for t in xrange(42)]
        counter = NewThreadsCount(self.user, {})
        self.assertEqual(int(counter), 42)
コード例 #5
0
ファイル: test_counters.py プロジェクト: hwy801207/Misago
    def test_set(self):
        """set allows for changing count of threads"""
        session = {}
        counter = NewThreadsCount(self.user, session)
        counter.set(128)

        self.assertEqual(int(counter), 128)
        self.assertEqual(session[counter.name]['threads'], 128)
コード例 #6
0
ファイル: test_counters.py プロジェクト: hwy801207/Misago
    def test_decrease_zero(self):
        """decrease is not allowing for negative threads counts"""
        session = {}
        counter = NewThreadsCount(self.user, session)
        counter.decrease()

        self.assertEqual(int(counter), 0)
        self.assertEqual(session[counter.name]['threads'], 0)
コード例 #7
0
ファイル: test_counters.py プロジェクト: hwy801207/Misago
    def test_get_real_count(self):
        """get_real_count returns valid count of new threads"""
        counter = NewThreadsCount(self.user, {})
        self.assertEqual(counter.count, 0)
        self.assertEqual(counter.get_real_count()['threads'], 0)

        # create 10 new threads
        threads = [testutils.post_thread(self.forum) for t in xrange(10)]
        self.assertEqual(counter.get_real_count()['threads'], 10)

        # create new counter
        counter = NewThreadsCount(self.user, {})
        self.assertEqual(counter.count, 10)
        self.assertEqual(counter.get_real_count()['threads'], 10)
コード例 #8
0
ファイル: middleware.py プロジェクト: David1119/Misago
 def process_request(self, request):
     if request.user.is_authenticated():
         if request.user.acl['moderated_forums']:
             request.user.moderated_content = ModeratedCount(
                 request.user, request.session)
         request.user.new_threads = NewThreadsCount(request.user,
                                                    request.session)
         request.user.unread_threads = UnreadThreadsCount(
             request.user, request.session)
コード例 #9
0
    def test_is_cache_valid(self):
        """is_cache_valid returns valid value for different caches"""
        counter = NewThreadsCount(self.user, {})

        self.assertTrue(counter.is_cache_valid({
            'expires': time() + 15,
            'user': self.user.pk
        }))

        self.assertFalse(counter.is_cache_valid({
            'expires': time() - 15,
            'user': self.user.pk
        }))

        self.assertFalse(counter.is_cache_valid({
            'expires': time() + 15,
            'user': self.user.pk + 1
        }))
コード例 #10
0
    def test_is_cache_valid(self):
        """is_cache_valid returns valid value for different caches"""
        counter = NewThreadsCount(self.user, {})

        self.assertTrue(
            counter.is_cache_valid({
                'expires': time() + 15,
                'user': self.user.pk
            }))

        self.assertFalse(
            counter.is_cache_valid({
                'expires': time() - 15,
                'user': self.user.pk
            }))

        self.assertFalse(
            counter.is_cache_valid({
                'expires': time() + 15,
                'user': self.user.pk + 1
            }))
コード例 #11
0
    def process_request(self, request):
        if request.user.is_authenticated():
            if request.user.acl['can_review_moderated_content']:
                request.user.moderated_content = ModeratedCount(
                    request.user, request.session)
            request.user.new_threads = NewThreadsCount(request.user,
                                                       request.session)
            request.user.unread_threads = UnreadThreadsCount(
                request.user, request.session)

            if request.user.acl['can_use_private_threads']:
                # special case: count unread threads
                sync_user_unread_private_threads_count(request.user)
コード例 #12
0
    def test_get_current_count_dict(self):
        """get_current_count_dict returns valid count of new threads"""
        counter = NewThreadsCount(self.user, {})
        self.assertEqual(counter.count, 0)
        self.assertEqual(counter.get_current_count_dict()['threads'], 0)

        # create 10 new threads
        threads = [testutils.post_thread(self.forum) for t in xrange(10)]
        self.assertEqual(counter.get_current_count_dict()['threads'], 10)

        # create new counter
        counter = NewThreadsCount(self.user, {})
        self.assertEqual(counter.count, 10)
        self.assertEqual(counter.get_current_count_dict()['threads'], 10)
コード例 #13
0
 def test_get_expiration_timestamp(self):
     """get_expiration_timestamp returns greater time than current one"""
     counter = NewThreadsCount(self.user, {})
     self.assertTrue(counter.get_expiration_timestamp() > time())
コード例 #14
0
ファイル: test_counters.py プロジェクト: hwy801207/Misago
 def test_get_expiration_timestamp(self):
     """get_expiration_timestamp returns greater time than current one"""
     counter = NewThreadsCount(self.user, {})
     self.assertTrue(counter.get_expiration_timestamp() > time())
コード例 #15
0
 def process_request(self, request):
     if request.user.is_authenticated():
         request.user.new_threads = NewThreadsCount(request.user,
                                                    request.session)
         request.user.unread_threads = UnreadThreadsCount(
             request.user, request.session)