2016-09-13 23:45:39 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
from __future__ import absolute_import
|
|
|
|
from __future__ import print_function
|
|
|
|
|
|
|
|
from django.http import HttpResponse
|
2017-04-15 04:03:56 +02:00
|
|
|
from django.utils.timezone import now as timezone_now
|
2017-03-02 09:52:17 +01:00
|
|
|
from mock import mock
|
2016-09-13 23:45:39 +02:00
|
|
|
|
|
|
|
from typing import Any, Dict
|
2017-02-11 08:38:16 +01:00
|
|
|
from zerver.lib.actions import do_deactivate_user
|
2016-09-13 23:45:39 +02:00
|
|
|
from zerver.lib.test_helpers import (
|
|
|
|
make_client,
|
|
|
|
queries_captured,
|
2016-11-10 19:30:09 +01:00
|
|
|
)
|
|
|
|
from zerver.lib.test_classes import (
|
2016-09-13 23:45:39 +02:00
|
|
|
ZulipTestCase,
|
|
|
|
)
|
2017-03-02 09:52:17 +01:00
|
|
|
from zerver.lib.timestamp import datetime_to_timestamp
|
2016-09-13 23:45:39 +02:00
|
|
|
from zerver.models import (
|
2016-11-11 21:13:30 +01:00
|
|
|
email_to_domain,
|
2016-09-13 23:45:39 +02:00
|
|
|
Client,
|
|
|
|
UserActivity,
|
|
|
|
UserProfile,
|
2017-02-19 16:43:32 +01:00
|
|
|
UserPresence,
|
2017-03-31 08:31:18 +02:00
|
|
|
flush_per_request_caches,
|
2016-09-13 23:45:39 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
import datetime
|
|
|
|
import ujson
|
|
|
|
|
|
|
|
class ActivityTest(ZulipTestCase):
|
|
|
|
def test_activity(self):
|
|
|
|
# type: () -> None
|
2017-05-25 01:40:26 +02:00
|
|
|
self.login(self.example_email("hamlet"))
|
2016-09-13 23:45:39 +02:00
|
|
|
client, _ = Client.objects.get_or_create(name='website')
|
|
|
|
query = '/json/users/me/pointer'
|
2017-04-15 04:03:56 +02:00
|
|
|
last_visit = timezone_now()
|
2016-11-28 23:29:01 +01:00
|
|
|
count = 150
|
2016-09-13 23:45:39 +02:00
|
|
|
for user_profile in UserProfile.objects.all():
|
|
|
|
UserActivity.objects.get_or_create(
|
|
|
|
user_profile=user_profile,
|
|
|
|
client=client,
|
|
|
|
query=query,
|
|
|
|
count=count,
|
|
|
|
last_visit=last_visit
|
|
|
|
)
|
2017-03-31 08:31:18 +02:00
|
|
|
flush_per_request_caches()
|
2016-09-13 23:45:39 +02:00
|
|
|
with queries_captured() as queries:
|
|
|
|
self.client_get('/activity')
|
|
|
|
|
2017-03-31 08:31:18 +02:00
|
|
|
self.assert_length(queries, 2)
|
2016-09-13 23:45:39 +02:00
|
|
|
|
2017-03-08 12:53:26 +01:00
|
|
|
class TestClientModel(ZulipTestCase):
|
|
|
|
def test_client_stringification(self):
|
|
|
|
# type: () -> None
|
|
|
|
'''
|
|
|
|
This test is designed to cover __unicode__ method for Client.
|
|
|
|
'''
|
|
|
|
client = make_client('some_client')
|
|
|
|
self.assertEqual(str(client), u'<Client: some_client>')
|
|
|
|
|
2017-02-19 16:43:32 +01:00
|
|
|
class UserPresenceModelTests(ZulipTestCase):
|
|
|
|
def test_date_logic(self):
|
|
|
|
# type: () -> None
|
|
|
|
UserPresence.objects.all().delete()
|
|
|
|
|
2017-05-07 19:39:30 +02:00
|
|
|
user_profile = self.example_user('hamlet')
|
|
|
|
email = user_profile.email
|
2017-02-19 16:43:32 +01:00
|
|
|
presence_dct = UserPresence.get_status_dict_by_realm(user_profile.realm_id)
|
|
|
|
self.assertEqual(len(presence_dct), 0)
|
|
|
|
|
|
|
|
self.login(email)
|
|
|
|
result = self.client_post("/json/users/me/presence", {'status': 'active'})
|
|
|
|
self.assert_json_success(result)
|
|
|
|
|
|
|
|
presence_dct = UserPresence.get_status_dict_by_realm(user_profile.realm_id)
|
|
|
|
self.assertEqual(len(presence_dct), 1)
|
|
|
|
self.assertEqual(presence_dct[email]['website']['status'], 'active')
|
|
|
|
|
|
|
|
def back_date(num_weeks):
|
|
|
|
# type: (int) -> None
|
|
|
|
user_presence = UserPresence.objects.filter(user_profile=user_profile)[0]
|
2017-04-15 04:03:56 +02:00
|
|
|
user_presence.timestamp = timezone_now() - datetime.timedelta(weeks=num_weeks)
|
2017-02-19 16:43:32 +01:00
|
|
|
user_presence.save()
|
|
|
|
|
|
|
|
# Simulate the presence being a week old first. Nothing should change.
|
|
|
|
back_date(num_weeks=1)
|
|
|
|
presence_dct = UserPresence.get_status_dict_by_realm(user_profile.realm_id)
|
|
|
|
self.assertEqual(len(presence_dct), 1)
|
|
|
|
|
|
|
|
# If the UserPresence row is three weeks old, we ignore it.
|
|
|
|
back_date(num_weeks=3)
|
|
|
|
presence_dct = UserPresence.get_status_dict_by_realm(user_profile.realm_id)
|
|
|
|
self.assertEqual(len(presence_dct), 0)
|
|
|
|
|
2016-09-13 23:45:39 +02:00
|
|
|
class UserPresenceTests(ZulipTestCase):
|
|
|
|
def test_invalid_presence(self):
|
|
|
|
# type: () -> None
|
2017-05-25 01:40:26 +02:00
|
|
|
email = self.example_email("hamlet")
|
2016-09-13 23:45:39 +02:00
|
|
|
self.login(email)
|
|
|
|
result = self.client_post("/json/users/me/presence", {'status': 'foo'})
|
2017-01-29 00:08:08 +01:00
|
|
|
self.assert_json_error(result, 'Invalid status: foo')
|
2016-09-13 23:45:39 +02:00
|
|
|
|
|
|
|
def test_set_idle(self):
|
|
|
|
# type: () -> None
|
2017-05-25 01:40:26 +02:00
|
|
|
email = self.example_email("hamlet")
|
2016-09-13 23:45:39 +02:00
|
|
|
self.login(email)
|
|
|
|
client = 'website'
|
|
|
|
|
|
|
|
result = self.client_post("/json/users/me/presence", {'status': 'idle'})
|
2016-09-27 18:28:40 +02:00
|
|
|
self.assert_json_success(result)
|
|
|
|
json = ujson.loads(result.content)
|
|
|
|
self.assertEqual(json['presences'][email][client]['status'], 'idle')
|
|
|
|
self.assertIn('timestamp', json['presences'][email][client])
|
|
|
|
self.assertIsInstance(json['presences'][email][client]['timestamp'], int)
|
2017-05-25 01:40:26 +02:00
|
|
|
self.assertEqual(list(json['presences'].keys()), [self.example_email("hamlet")])
|
2016-09-27 18:28:40 +02:00
|
|
|
timestamp = json['presences'][email][client]['timestamp']
|
2016-09-13 23:45:39 +02:00
|
|
|
|
2017-05-25 02:08:35 +02:00
|
|
|
email = self.example_email("othello")
|
2016-09-13 23:45:39 +02:00
|
|
|
self.login(email)
|
2016-09-27 18:28:40 +02:00
|
|
|
result = self.client_post("/json/users/me/presence", {'status': 'idle'})
|
2016-09-13 23:45:39 +02:00
|
|
|
json = ujson.loads(result.content)
|
|
|
|
self.assertEqual(json['presences'][email][client]['status'], 'idle')
|
2017-05-25 01:40:26 +02:00
|
|
|
self.assertEqual(json['presences'][self.example_email("hamlet")][client]['status'], 'idle')
|
2017-05-25 02:08:35 +02:00
|
|
|
self.assertEqual(sorted(json['presences'].keys()), [self.example_email("hamlet"), self.example_email("othello")])
|
2016-09-13 23:45:39 +02:00
|
|
|
newer_timestamp = json['presences'][email][client]['timestamp']
|
|
|
|
self.assertGreaterEqual(newer_timestamp, timestamp)
|
|
|
|
|
|
|
|
def test_set_active(self):
|
|
|
|
# type: () -> None
|
2017-05-25 01:40:26 +02:00
|
|
|
self.login(self.example_email("hamlet"))
|
2016-09-13 23:45:39 +02:00
|
|
|
client = 'website'
|
|
|
|
|
2016-09-27 18:28:40 +02:00
|
|
|
result = self.client_post("/json/users/me/presence", {'status': 'idle'})
|
2016-09-13 23:45:39 +02:00
|
|
|
|
|
|
|
self.assert_json_success(result)
|
|
|
|
json = ujson.loads(result.content)
|
2017-05-25 01:40:26 +02:00
|
|
|
self.assertEqual(json['presences'][self.example_email("hamlet")][client]['status'], 'idle')
|
2016-09-13 23:45:39 +02:00
|
|
|
|
2017-05-25 02:08:35 +02:00
|
|
|
email = self.example_email("othello")
|
|
|
|
self.login(self.example_email("othello"))
|
2016-09-27 18:28:40 +02:00
|
|
|
result = self.client_post("/json/users/me/presence", {'status': 'idle'})
|
2016-09-13 23:45:39 +02:00
|
|
|
self.assert_json_success(result)
|
|
|
|
json = ujson.loads(result.content)
|
|
|
|
self.assertEqual(json['presences'][email][client]['status'], 'idle')
|
2017-05-25 01:40:26 +02:00
|
|
|
self.assertEqual(json['presences'][self.example_email("hamlet")][client]['status'], 'idle')
|
2016-09-13 23:45:39 +02:00
|
|
|
|
2016-09-27 18:28:40 +02:00
|
|
|
result = self.client_post("/json/users/me/presence", {'status': 'active'})
|
2016-09-13 23:45:39 +02:00
|
|
|
self.assert_json_success(result)
|
|
|
|
json = ujson.loads(result.content)
|
|
|
|
self.assertEqual(json['presences'][email][client]['status'], 'active')
|
2017-05-25 01:40:26 +02:00
|
|
|
self.assertEqual(json['presences'][self.example_email("hamlet")][client]['status'], 'idle')
|
2016-09-13 23:45:39 +02:00
|
|
|
|
|
|
|
def test_no_mit(self):
|
|
|
|
# type: () -> None
|
|
|
|
"""Zephyr mirror realms such as MIT never get a list of users"""
|
2017-05-24 21:21:35 +02:00
|
|
|
self.login(self.mit_email("espuser"))
|
2016-09-13 23:45:39 +02:00
|
|
|
result = self.client_post("/json/users/me/presence", {'status': 'idle'})
|
|
|
|
self.assert_json_success(result)
|
|
|
|
json = ujson.loads(result.content)
|
|
|
|
self.assertEqual(json['presences'], {})
|
|
|
|
|
|
|
|
def test_mirror_presence(self):
|
|
|
|
# type: () -> None
|
|
|
|
"""Zephyr mirror realms find out the status of their mirror bot"""
|
2017-05-23 03:28:23 +02:00
|
|
|
user_profile = self.mit_user('espuser')
|
|
|
|
email = user_profile.email
|
2016-09-13 23:45:39 +02:00
|
|
|
self.login(email)
|
|
|
|
|
|
|
|
def post_presence():
|
|
|
|
# type: () -> Dict[str, Any]
|
|
|
|
result = self.client_post("/json/users/me/presence", {'status': 'idle'})
|
|
|
|
self.assert_json_success(result)
|
|
|
|
json = ujson.loads(result.content)
|
|
|
|
return json
|
|
|
|
|
|
|
|
json = post_presence()
|
|
|
|
self.assertEqual(json['zephyr_mirror_active'], False)
|
|
|
|
|
|
|
|
self._simulate_mirror_activity_for_user(user_profile)
|
|
|
|
json = post_presence()
|
|
|
|
self.assertEqual(json['zephyr_mirror_active'], True)
|
|
|
|
|
|
|
|
def _simulate_mirror_activity_for_user(self, user_profile):
|
|
|
|
# type: (UserProfile) -> None
|
2017-04-15 04:03:56 +02:00
|
|
|
last_visit = timezone_now()
|
2016-09-13 23:45:39 +02:00
|
|
|
client = make_client('zephyr_mirror')
|
|
|
|
|
|
|
|
UserActivity.objects.get_or_create(
|
|
|
|
user_profile=user_profile,
|
|
|
|
client=client,
|
|
|
|
query='get_events_backend',
|
|
|
|
count=2,
|
|
|
|
last_visit=last_visit
|
|
|
|
)
|
|
|
|
|
|
|
|
def test_same_realm(self):
|
|
|
|
# type: () -> None
|
2017-05-24 21:21:35 +02:00
|
|
|
self.login(self.mit_email("espuser"))
|
2016-09-13 23:45:39 +02:00
|
|
|
self.client_post("/json/users/me/presence", {'status': 'idle'})
|
2017-04-18 03:23:32 +02:00
|
|
|
self.logout()
|
2016-09-13 23:45:39 +02:00
|
|
|
|
|
|
|
# Ensure we don't see hamlet@zulip.com information leakage
|
2017-05-25 01:40:26 +02:00
|
|
|
self.login(self.example_email("hamlet"))
|
2016-09-13 23:45:39 +02:00
|
|
|
result = self.client_post("/json/users/me/presence", {'status': 'idle'})
|
|
|
|
self.assert_json_success(result)
|
|
|
|
json = ujson.loads(result.content)
|
2017-05-25 01:40:26 +02:00
|
|
|
self.assertEqual(json['presences'][self.example_email("hamlet")]["website"]['status'], 'idle')
|
2016-09-13 23:45:39 +02:00
|
|
|
# We only want @zulip.com emails
|
|
|
|
for email in json['presences'].keys():
|
2016-11-11 21:13:30 +01:00
|
|
|
self.assertEqual(email_to_domain(email), 'zulip.com')
|
2017-02-11 08:38:16 +01:00
|
|
|
|
|
|
|
class SingleUserPresenceTests(ZulipTestCase):
|
|
|
|
def test_single_user_get(self):
|
|
|
|
# type: () -> None
|
|
|
|
|
|
|
|
# First, we setup the test with some data
|
2017-05-25 02:08:35 +02:00
|
|
|
email = self.example_email("othello")
|
|
|
|
self.login(self.example_email("othello"))
|
2017-02-11 08:38:16 +01:00
|
|
|
result = self.client_post("/json/users/me/presence", {'status': 'active'})
|
|
|
|
result = self.client_post("/json/users/me/presence", {'status': 'active'},
|
|
|
|
HTTP_USER_AGENT="ZulipDesktop/1.0")
|
|
|
|
result = self.client_post("/api/v1/users/me/presence", {'status': 'idle'},
|
|
|
|
HTTP_USER_AGENT="ZulipAndroid/1.0",
|
|
|
|
**self.api_auth(email))
|
|
|
|
self.assert_json_success(result)
|
|
|
|
|
|
|
|
# Check some error conditions
|
|
|
|
result = self.client_get("/json/users/nonexistence@zulip.com/presence")
|
|
|
|
self.assert_json_error(result, "No such user")
|
|
|
|
|
|
|
|
result = self.client_get("/json/users/cordelia@zulip.com/presence")
|
|
|
|
self.assert_json_error(result, "No presence data for cordelia@zulip.com")
|
|
|
|
|
2017-05-07 17:21:26 +02:00
|
|
|
do_deactivate_user(self.example_user('cordelia'))
|
2017-02-11 08:38:16 +01:00
|
|
|
result = self.client_get("/json/users/cordelia@zulip.com/presence")
|
|
|
|
self.assert_json_error(result, "No such user")
|
|
|
|
|
|
|
|
result = self.client_get("/json/users/new-user-bot@zulip.com/presence")
|
2017-04-12 20:50:23 +02:00
|
|
|
self.assert_json_error(result, "Presence is not supported for bot users.")
|
2017-02-11 08:38:16 +01:00
|
|
|
|
2017-05-24 21:21:35 +02:00
|
|
|
self.login(self.mit_email("sipbtest"))
|
2017-02-11 08:38:16 +01:00
|
|
|
result = self.client_get("/json/users/othello@zulip.com/presence")
|
|
|
|
self.assert_json_error(result, "No such user")
|
|
|
|
|
|
|
|
# Then, we check everything works
|
2017-05-25 01:40:26 +02:00
|
|
|
self.login(self.example_email("hamlet"))
|
2017-02-11 08:38:16 +01:00
|
|
|
result = self.client_get("/json/users/othello@zulip.com/presence")
|
|
|
|
result_dict = ujson.loads(result.content)
|
2017-03-02 09:52:17 +01:00
|
|
|
self.assertEqual(
|
|
|
|
set(result_dict['presence'].keys()),
|
|
|
|
{"ZulipAndroid", "website", "aggregated"})
|
2017-02-11 08:38:16 +01:00
|
|
|
self.assertEqual(set(result_dict['presence']['website'].keys()), {"status", "timestamp"})
|
2017-03-02 09:52:17 +01:00
|
|
|
|
2017-03-31 01:46:45 +02:00
|
|
|
def test_ping_only(self):
|
|
|
|
# type: () -> None
|
|
|
|
|
2017-05-25 02:08:35 +02:00
|
|
|
self.login(self.example_email("othello"))
|
2017-03-31 01:46:45 +02:00
|
|
|
req = dict(
|
|
|
|
status='active',
|
|
|
|
ping_only='true',
|
|
|
|
)
|
|
|
|
result = self.client_post("/json/users/me/presence", req)
|
|
|
|
self.assertEqual(result.json()['msg'], '')
|
2017-03-02 09:52:17 +01:00
|
|
|
|
|
|
|
class UserPresenceAggregationTests(ZulipTestCase):
|
|
|
|
def _send_presence_for_aggregated_tests(self, email, status, validate_time):
|
|
|
|
# type: (str, str, datetime.datetime) -> Dict[str, Dict[str, Any]]
|
|
|
|
self.login(email)
|
2017-04-16 21:32:57 +02:00
|
|
|
timezone_util = 'zerver.views.presence.timezone_now'
|
2017-03-02 09:52:17 +01:00
|
|
|
with mock.patch(timezone_util, return_value=validate_time - datetime.timedelta(seconds=5)):
|
|
|
|
self.client_post("/json/users/me/presence", {'status': status})
|
|
|
|
with mock.patch(timezone_util, return_value=validate_time - datetime.timedelta(seconds=2)):
|
|
|
|
self.client_post("/api/v1/users/me/presence", {'status': status},
|
|
|
|
HTTP_USER_AGENT="ZulipAndroid/1.0",
|
|
|
|
**self.api_auth(email))
|
|
|
|
with mock.patch(timezone_util, return_value=validate_time - datetime.timedelta(seconds=7)):
|
2017-03-18 10:41:57 +01:00
|
|
|
latest_result = self.client_post("/api/v1/users/me/presence", {'status': status},
|
|
|
|
HTTP_USER_AGENT="ZulipIOS/1.0",
|
|
|
|
**self.api_auth(email))
|
|
|
|
latest_result_dict = latest_result.json()
|
|
|
|
self.assertDictEqual(
|
|
|
|
latest_result_dict['presences'][email]['aggregated'],
|
|
|
|
{
|
|
|
|
'status': status,
|
|
|
|
'timestamp': datetime_to_timestamp(validate_time - datetime.timedelta(seconds=2)),
|
|
|
|
'client': 'ZulipAndroid'
|
|
|
|
}
|
|
|
|
)
|
2017-03-02 09:52:17 +01:00
|
|
|
result = self.client_get("/json/users/%s/presence" % (email,))
|
|
|
|
return result.json()
|
|
|
|
|
2017-03-18 10:41:57 +01:00
|
|
|
def test_aggregated_info(self):
|
|
|
|
# type: () -> None
|
2017-05-25 02:08:35 +02:00
|
|
|
email = self.example_email("othello")
|
2017-04-15 04:03:56 +02:00
|
|
|
validate_time = timezone_now()
|
2017-05-25 02:08:35 +02:00
|
|
|
self._send_presence_for_aggregated_tests(str(self.example_email("othello")), 'active', validate_time)
|
2017-04-16 21:32:57 +02:00
|
|
|
with mock.patch('zerver.views.presence.timezone_now',
|
2017-03-18 10:41:57 +01:00
|
|
|
return_value=validate_time - datetime.timedelta(seconds=1)):
|
|
|
|
result = self.client_post("/api/v1/users/me/presence", {'status': 'active'},
|
|
|
|
HTTP_USER_AGENT="ZulipTestDev/1.0",
|
|
|
|
**self.api_auth(email))
|
|
|
|
result_dict = result.json()
|
|
|
|
self.assertDictEqual(
|
|
|
|
result_dict['presences'][email]['aggregated'],
|
|
|
|
{
|
|
|
|
'status': 'active',
|
|
|
|
'timestamp': datetime_to_timestamp(validate_time - datetime.timedelta(seconds=1)),
|
|
|
|
'client': 'ZulipTestDev'
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2017-03-02 09:52:17 +01:00
|
|
|
def test_aggregated_presense_active(self):
|
|
|
|
# type: () -> None
|
2017-04-15 04:03:56 +02:00
|
|
|
validate_time = timezone_now()
|
2017-05-25 02:08:35 +02:00
|
|
|
result_dict = self._send_presence_for_aggregated_tests(str(self.example_email("othello")), 'active',
|
2017-03-02 09:52:17 +01:00
|
|
|
validate_time)
|
|
|
|
self.assertDictEqual(
|
|
|
|
result_dict['presence']['aggregated'],
|
|
|
|
{
|
|
|
|
"status": "active",
|
|
|
|
"timestamp": datetime_to_timestamp(validate_time - datetime.timedelta(seconds=2))
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
def test_aggregated_presense_idle(self):
|
|
|
|
# type: () -> None
|
2017-04-15 04:03:56 +02:00
|
|
|
validate_time = timezone_now()
|
2017-05-25 02:08:35 +02:00
|
|
|
result_dict = self._send_presence_for_aggregated_tests(str(self.example_email("othello")), 'idle',
|
2017-03-02 09:52:17 +01:00
|
|
|
validate_time)
|
|
|
|
self.assertDictEqual(
|
|
|
|
result_dict['presence']['aggregated'],
|
|
|
|
{
|
|
|
|
"status": "idle",
|
|
|
|
"timestamp": datetime_to_timestamp(validate_time - datetime.timedelta(seconds=2))
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
def test_aggregated_presense_mixed(self):
|
|
|
|
# type: () -> None
|
2017-05-25 02:08:35 +02:00
|
|
|
email = self.example_email("othello")
|
2017-03-02 09:52:17 +01:00
|
|
|
self.login(email)
|
2017-04-15 04:03:56 +02:00
|
|
|
validate_time = timezone_now()
|
2017-04-16 21:32:57 +02:00
|
|
|
with mock.patch('zerver.views.presence.timezone_now',
|
2017-03-02 09:52:17 +01:00
|
|
|
return_value=validate_time - datetime.timedelta(seconds=3)):
|
|
|
|
self.client_post("/api/v1/users/me/presence", {'status': 'active'},
|
|
|
|
HTTP_USER_AGENT="ZulipTestDev/1.0",
|
|
|
|
**self.api_auth(email))
|
2017-05-25 02:08:35 +02:00
|
|
|
result_dict = self._send_presence_for_aggregated_tests(str(email), 'idle', validate_time)
|
2017-03-02 09:52:17 +01:00
|
|
|
self.assertDictEqual(
|
|
|
|
result_dict['presence']['aggregated'],
|
|
|
|
{
|
|
|
|
"status": "idle",
|
|
|
|
"timestamp": datetime_to_timestamp(validate_time - datetime.timedelta(seconds=2))
|
|
|
|
}
|
|
|
|
)
|
2017-03-06 12:25:37 +01:00
|
|
|
|
|
|
|
def test_aggregated_presense_offline(self):
|
|
|
|
# type: () -> None
|
2017-05-25 02:08:35 +02:00
|
|
|
email = self.example_email("othello")
|
2017-03-06 12:25:37 +01:00
|
|
|
self.login(email)
|
2017-04-15 04:03:56 +02:00
|
|
|
validate_time = timezone_now()
|
2017-03-06 12:25:37 +01:00
|
|
|
with self.settings(OFFLINE_THRESHOLD_SECS=1):
|
2017-05-25 02:08:35 +02:00
|
|
|
result_dict = self._send_presence_for_aggregated_tests(str(email), 'idle', validate_time)
|
2017-03-06 12:25:37 +01:00
|
|
|
self.assertDictEqual(
|
|
|
|
result_dict['presence']['aggregated'],
|
|
|
|
{
|
|
|
|
"status": "offline",
|
|
|
|
"timestamp": datetime_to_timestamp(validate_time - datetime.timedelta(seconds=2))
|
|
|
|
}
|
|
|
|
)
|