コード例 #1
0
ファイル: test_home.py プロジェクト: alihaskar/zulip
    def test_furthest_read_time(self) -> None:
        msg_id = self.send_test_message("hello!", sender_name="iago")

        hamlet = self.example_user('hamlet')
        self.login_user(hamlet)
        self.client_post("/json/messages/flags", {
            "messages": ujson.dumps([msg_id]),
            "op": "add",
            "flag": "read"
        })

        # Manually process the UserActivity
        now = timezone_now()
        activity_time = calendar.timegm(now.timetuple())
        user_activity_event = {
            'user_profile_id': hamlet.id,
            'client': 'test-client',
            'query': 'update_message_flags',
            'time': activity_time
        }

        yesterday = now - timedelta(days=1)
        activity_time_2 = calendar.timegm(yesterday.timetuple())
        user_activity_event_2 = {
            'user_profile_id': hamlet.id,
            'client': 'test-client-2',
            'query': 'update_message_flags',
            'time': activity_time_2
        }
        UserActivityWorker().consume_batch(
            [user_activity_event, user_activity_event_2])

        # verify furthest_read_time is last activity time, irrespective of client
        furthest_read_time = get_furthest_read_time(hamlet)
        self.assertGreaterEqual(furthest_read_time, activity_time)

        # Check when user has no activity
        UserActivity.objects.filter(user_profile=hamlet).delete()
        furthest_read_time = get_furthest_read_time(hamlet)
        self.assertIsNone(furthest_read_time)

        # Check no user profile handling
        furthest_read_time = get_furthest_read_time(None)
        self.assertIsNotNone(furthest_read_time)