示例#1
0
文件: tests.py 项目: slok/dwarf
    def test_achievement_notification_count_range(self):
        achieves = Achievement.objects.all()[:5]
        notifs = []
        user = User.objects.get(id=1)
        r = get_redis_connection()

        for i in achieves:
            notif = AchievementNotification(achievement=i, user=user)
            time.sleep(1)

            if random.randrange(100) % 2:
                key = Notification.STORE_KEY_UNREAD_FORMAT.format(user.id)
            else:
                key = Notification.STORE_KEY_READ_FORMAT.format(user.id)

            r.zadd(key, notif.date, notif.to_json())
            notifs.append(notif)

        achieves = achieves[2:5]  # 2, 3 and 4 only
        a_len = len(achieves)

        lowerbound = notifs[2].date
        upperbound = notifs[4].date

        result = AchievementNotification.count(user,
                                               lowerbound,
                                               upperbound,
                                               mode=2)
        self.assertEquals(a_len, result)
示例#2
0
文件: tests.py 项目: slok/dwarf
    def test_achievement_notification_get_range(self):
        achieves = Achievement.objects.all()[:5]
        notifs = []
        user = User.objects.get(id=1)
        r = get_redis_connection()

        for i in achieves:
            notif = AchievementNotification(achievement=i, user=user)
            time.sleep(1)

            if random.randrange(100) % 2:
                key = Notification.STORE_KEY_UNREAD_FORMAT.format(user.id)
            else:
                key = Notification.STORE_KEY_READ_FORMAT.format(user.id)

            r.zadd(key, notif.date, notif.to_json())
            notifs.append(notif)

        achieves = achieves[2:5]  # 2, 3 and 4 only
        a_len = len(achieves)

        # Get notifications
        res = Notification.time_range(user,
                                      lowerbound=notifs[2].date,
                                      upperbound=notifs[4].date,
                                      desc=False,
                                      mode=2)

        self.assertEquals(a_len, len(res))

        for i in range(len(res)):
            before = achieves[i]
            after = res[i]

            self.assertEquals(before.id, after.achievement_id)
示例#3
0
文件: tests.py 项目: slok/dwarf
    def test_achievement_notification_find_all_with_limits(self):
        achieves = Achievement.objects.all()[:5]
        user = User.objects.get(id=1)
        r = get_redis_connection()

        for i in achieves:
            notif = AchievementNotification(achievement=i, user=user)
            time.sleep(1)

            if random.randrange(100) % 2:
                key = Notification.STORE_KEY_UNREAD_FORMAT.format(user.id)
            else:
                key = Notification.STORE_KEY_READ_FORMAT.format(user.id)

            r.zadd(key, notif.date, notif.to_json())

        # Get notifications
        res = Notification.find(user, offset=2, limit=3, desc=False, mode=2)

        achieves = achieves[2:4]  # 2 and 3 only
        a_len = len(achieves)

        self.assertEquals(a_len, len(res))

        for i in range(len(res)):
            before = achieves[i]
            after = res[i]

            self.assertEquals(before.id, after.achievement_id)
示例#4
0
文件: tests.py 项目: slok/dwarf
    def test_achievement_notification_get_all_asc(self):
        #with three we have enought to test
        achieves = Achievement.objects.all()
        user = User.objects.get(id=1)
        r = get_redis_connection()

        a_len = len(achieves)

        for i in achieves:
            notif = AchievementNotification(achievement=i, user=user)
            time.sleep(1)

            if random.randrange(100) % 2:
                key = Notification.STORE_KEY_UNREAD_FORMAT.format(user.id)
            else:
                key = Notification.STORE_KEY_READ_FORMAT.format(user.id)

            r.zadd(key, notif.date, notif.to_json())

        # Get notifications
        res = Notification.all(user, desc=False)

        self.assertEquals(a_len, len(res))

        for i in range(len(res)):
            before = achieves[i]
            after = res[i]

            self.assertEquals(before.id, after.achievement_id)
示例#5
0
文件: tests.py 项目: slok/dwarf
    def test_achievement_notification_count(self):
        achieves = Achievement.objects.all()
        user = User.objects.get(id=1)
        r = get_redis_connection()

        for i in achieves:
            notif = AchievementNotification(achievement=i, user=user)

            if random.randrange(100) % 2:
                key = Notification.STORE_KEY_UNREAD_FORMAT.format(user.id)
            else:
                key = Notification.STORE_KEY_READ_FORMAT.format(user.id)

            r.zadd(key, notif.date, notif.to_json())

        a_len = len(achieves)

        self.assertEquals(a_len, AchievementNotification.count(user, mode=2))
示例#6
0
文件: tests.py 项目: slok/dwarf
    def test_achievement_notification_get_unread(self):
        #with three we have enought to test
        achieves = Achievement.objects.all()[:3]
        user = User.objects.get(id=1)
        r = get_redis_connection()

        a_len = len(achieves)

        for i in achieves:
            notif = AchievementNotification(achievement=i, user=user)
            time.sleep(1)
            key = Notification.STORE_KEY_UNREAD_FORMAT.format(user.id)
            r.zadd(key, notif.date, notif.to_json())

        # Get notifications
        res = Notification.unreads(user)[::-1]

        self.assertEquals(a_len, len(res))

        for i in range(len(res)):
            before = achieves[i]
            after = res[i]

            self.assertEquals(before.id, after.achievement_id)