2014-08-12 08:10:52 -06:00
|
|
|
# -*- coding: utf-8 -*-
|
2016-01-06 21:26:29 -07:00
|
|
|
# Copyright 2014-2016 OpenMarket Ltd
|
2014-08-12 20:32:18 -06:00
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
|
2014-08-12 08:10:52 -06:00
|
|
|
"""Tests REST events for /presence paths."""
|
2014-09-12 11:24:53 -06:00
|
|
|
from tests import unittest
|
2014-08-12 08:10:52 -06:00
|
|
|
from twisted.internet import defer
|
|
|
|
|
|
|
|
from mock import Mock
|
|
|
|
|
2015-02-11 04:37:30 -07:00
|
|
|
from ....utils import MockHttpResource, setup_test_homeserver
|
2014-08-12 08:10:52 -06:00
|
|
|
|
|
|
|
from synapse.api.constants import PresenceState
|
2014-08-18 09:52:29 -06:00
|
|
|
from synapse.handlers.presence import PresenceHandler
|
2015-01-23 03:37:38 -07:00
|
|
|
from synapse.rest.client.v1 import presence
|
|
|
|
from synapse.rest.client.v1 import events
|
2016-01-11 08:29:57 -07:00
|
|
|
from synapse.types import Requester, UserID
|
2015-05-13 06:42:21 -06:00
|
|
|
from synapse.util.async import run_on_reactor
|
2014-08-12 08:10:52 -06:00
|
|
|
|
2015-05-21 08:23:40 -06:00
|
|
|
from collections import namedtuple
|
|
|
|
|
2014-08-12 08:10:52 -06:00
|
|
|
|
|
|
|
OFFLINE = PresenceState.OFFLINE
|
2014-08-13 07:31:48 -06:00
|
|
|
UNAVAILABLE = PresenceState.UNAVAILABLE
|
2014-08-12 08:10:52 -06:00
|
|
|
ONLINE = PresenceState.ONLINE
|
|
|
|
|
|
|
|
|
|
|
|
myid = "@apple:test"
|
2014-08-31 07:51:37 -06:00
|
|
|
PATH_PREFIX = "/_matrix/client/api/v1"
|
2014-08-12 08:10:52 -06:00
|
|
|
|
|
|
|
|
2015-09-22 11:33:34 -06:00
|
|
|
class NullSource(object):
|
|
|
|
"""This event source never yields any events and its token remains at
|
|
|
|
zero. It may be useful for unit-testing."""
|
|
|
|
def __init__(self, hs):
|
|
|
|
pass
|
|
|
|
|
2015-11-05 07:32:26 -07:00
|
|
|
def get_new_events(
|
|
|
|
self,
|
|
|
|
user,
|
|
|
|
from_key,
|
|
|
|
room_ids=None,
|
|
|
|
limit=None,
|
|
|
|
is_guest=None
|
|
|
|
):
|
2015-09-22 11:33:34 -06:00
|
|
|
return defer.succeed(([], from_key))
|
|
|
|
|
|
|
|
def get_current_key(self, direction='f'):
|
|
|
|
return defer.succeed(0)
|
|
|
|
|
|
|
|
def get_pagination_rows(self, user, pagination_config, key):
|
|
|
|
return defer.succeed(([], pagination_config.from_key))
|
|
|
|
|
|
|
|
|
2014-08-18 09:52:29 -06:00
|
|
|
class JustPresenceHandlers(object):
|
|
|
|
def __init__(self, hs):
|
|
|
|
self.presence_handler = PresenceHandler(hs)
|
|
|
|
|
|
|
|
|
2014-08-12 08:10:52 -06:00
|
|
|
class PresenceStateTestCase(unittest.TestCase):
|
|
|
|
|
2015-02-11 04:37:30 -07:00
|
|
|
@defer.inlineCallbacks
|
2014-08-12 08:10:52 -06:00
|
|
|
def setUp(self):
|
2014-08-18 07:03:07 -06:00
|
|
|
self.mock_resource = MockHttpResource(prefix=PATH_PREFIX)
|
2015-02-11 04:37:30 -07:00
|
|
|
hs = yield setup_test_homeserver(
|
2014-08-18 09:52:29 -06:00
|
|
|
datastore=Mock(spec=[
|
|
|
|
"get_presence_state",
|
|
|
|
"set_presence_state",
|
2014-09-26 09:36:24 -06:00
|
|
|
"insert_client_ip",
|
2014-08-18 09:52:29 -06:00
|
|
|
]),
|
2014-08-12 08:10:52 -06:00
|
|
|
http_client=None,
|
2014-08-18 07:03:07 -06:00
|
|
|
resource_for_client=self.mock_resource,
|
|
|
|
resource_for_federation=self.mock_resource,
|
2014-08-12 08:10:52 -06:00
|
|
|
)
|
2014-08-18 09:52:29 -06:00
|
|
|
hs.handlers = JustPresenceHandlers(hs)
|
|
|
|
|
|
|
|
self.datastore = hs.get_datastore()
|
2015-02-09 07:14:15 -07:00
|
|
|
self.datastore.get_app_service_by_token = Mock(return_value=None)
|
2014-08-18 09:52:29 -06:00
|
|
|
|
|
|
|
def get_presence_list(*a, **kw):
|
|
|
|
return defer.succeed([])
|
|
|
|
self.datastore.get_presence_list = get_presence_list
|
2014-08-12 08:10:52 -06:00
|
|
|
|
2015-11-04 10:29:07 -07:00
|
|
|
def _get_user_by_access_token(token=None, allow_guest=False):
|
2014-09-29 08:35:57 -06:00
|
|
|
return {
|
2015-09-01 05:41:16 -06:00
|
|
|
"user": UserID.from_string(myid),
|
2015-01-28 09:58:23 -07:00
|
|
|
"token_id": 1,
|
2015-11-04 10:29:07 -07:00
|
|
|
"is_guest": False,
|
2014-09-29 08:35:57 -06:00
|
|
|
}
|
2014-08-12 08:10:52 -06:00
|
|
|
|
2015-08-26 06:22:23 -06:00
|
|
|
hs.get_v1auth()._get_user_by_access_token = _get_user_by_access_token
|
2014-08-12 08:10:52 -06:00
|
|
|
|
2014-08-18 09:52:29 -06:00
|
|
|
room_member_handler = hs.handlers.room_member_handler = Mock(
|
|
|
|
spec=[
|
2015-03-09 11:01:11 -06:00
|
|
|
"get_joined_rooms_for_user",
|
2014-08-18 09:52:29 -06:00
|
|
|
]
|
|
|
|
)
|
|
|
|
|
|
|
|
def get_rooms_for_user(user):
|
|
|
|
return defer.succeed([])
|
2015-03-09 11:01:11 -06:00
|
|
|
room_member_handler.get_joined_rooms_for_user = get_rooms_for_user
|
2014-08-12 08:10:52 -06:00
|
|
|
|
2015-01-23 03:37:38 -07:00
|
|
|
presence.register_servlets(hs, self.mock_resource)
|
2014-08-12 08:10:52 -06:00
|
|
|
|
2015-01-23 04:47:15 -07:00
|
|
|
self.u_apple = UserID.from_string(myid)
|
2014-08-12 08:10:52 -06:00
|
|
|
|
|
|
|
@defer.inlineCallbacks
|
|
|
|
def test_get_my_status(self):
|
2014-08-18 09:52:29 -06:00
|
|
|
mocked_get = self.datastore.get_presence_state
|
2014-08-12 08:10:52 -06:00
|
|
|
mocked_get.return_value = defer.succeed(
|
2014-08-18 09:52:29 -06:00
|
|
|
{"state": ONLINE, "status_msg": "Available"}
|
|
|
|
)
|
2014-08-12 08:10:52 -06:00
|
|
|
|
2014-08-18 07:03:07 -06:00
|
|
|
(code, response) = yield self.mock_resource.trigger("GET",
|
2014-08-12 08:10:52 -06:00
|
|
|
"/presence/%s/status" % (myid), None)
|
|
|
|
|
|
|
|
self.assertEquals(200, code)
|
2014-09-01 07:45:35 -06:00
|
|
|
self.assertEquals(
|
2014-09-03 08:37:10 -06:00
|
|
|
{"presence": ONLINE, "status_msg": "Available"},
|
2014-09-01 07:45:35 -06:00
|
|
|
response
|
|
|
|
)
|
2014-08-18 09:52:29 -06:00
|
|
|
mocked_get.assert_called_with("apple")
|
2014-08-12 08:10:52 -06:00
|
|
|
|
|
|
|
@defer.inlineCallbacks
|
|
|
|
def test_set_my_status(self):
|
2014-08-18 09:52:29 -06:00
|
|
|
mocked_set = self.datastore.set_presence_state
|
|
|
|
mocked_set.return_value = defer.succeed({"state": OFFLINE})
|
2014-08-12 08:10:52 -06:00
|
|
|
|
2014-08-18 07:03:07 -06:00
|
|
|
(code, response) = yield self.mock_resource.trigger("PUT",
|
2014-08-12 08:10:52 -06:00
|
|
|
"/presence/%s/status" % (myid),
|
2014-09-01 07:45:35 -06:00
|
|
|
'{"presence": "unavailable", "status_msg": "Away"}')
|
2014-08-12 08:10:52 -06:00
|
|
|
|
|
|
|
self.assertEquals(200, code)
|
2014-08-18 09:52:29 -06:00
|
|
|
mocked_set.assert_called_with("apple",
|
2014-09-03 08:37:10 -06:00
|
|
|
{"state": UNAVAILABLE, "status_msg": "Away"}
|
|
|
|
)
|
2014-08-12 08:10:52 -06:00
|
|
|
|
|
|
|
|
|
|
|
class PresenceListTestCase(unittest.TestCase):
|
|
|
|
|
2015-02-11 04:37:30 -07:00
|
|
|
@defer.inlineCallbacks
|
2014-08-12 08:10:52 -06:00
|
|
|
def setUp(self):
|
2014-08-18 07:03:07 -06:00
|
|
|
self.mock_resource = MockHttpResource(prefix=PATH_PREFIX)
|
2014-08-12 08:10:52 -06:00
|
|
|
|
2015-02-11 04:37:30 -07:00
|
|
|
hs = yield setup_test_homeserver(
|
2014-08-18 09:52:29 -06:00
|
|
|
datastore=Mock(spec=[
|
|
|
|
"has_presence_state",
|
|
|
|
"get_presence_state",
|
|
|
|
"allow_presence_visible",
|
|
|
|
"is_presence_visible",
|
|
|
|
"add_presence_list_pending",
|
|
|
|
"set_presence_list_accepted",
|
|
|
|
"del_presence_list",
|
|
|
|
"get_presence_list",
|
2014-09-26 09:36:24 -06:00
|
|
|
"insert_client_ip",
|
2014-08-18 09:52:29 -06:00
|
|
|
]),
|
2014-08-12 08:10:52 -06:00
|
|
|
http_client=None,
|
2014-08-18 07:03:07 -06:00
|
|
|
resource_for_client=self.mock_resource,
|
2014-09-24 10:25:41 -06:00
|
|
|
resource_for_federation=self.mock_resource,
|
2014-08-12 08:10:52 -06:00
|
|
|
)
|
2014-08-18 09:52:29 -06:00
|
|
|
hs.handlers = JustPresenceHandlers(hs)
|
|
|
|
|
|
|
|
self.datastore = hs.get_datastore()
|
2015-02-09 07:14:15 -07:00
|
|
|
self.datastore.get_app_service_by_token = Mock(return_value=None)
|
2014-08-18 09:52:29 -06:00
|
|
|
|
|
|
|
def has_presence_state(user_localpart):
|
|
|
|
return defer.succeed(
|
|
|
|
user_localpart in ("apple", "banana",)
|
|
|
|
)
|
|
|
|
self.datastore.has_presence_state = has_presence_state
|
2014-08-12 08:10:52 -06:00
|
|
|
|
2015-11-04 10:29:07 -07:00
|
|
|
def _get_user_by_access_token(token=None, allow_guest=False):
|
2014-09-29 08:35:57 -06:00
|
|
|
return {
|
2015-09-01 05:41:16 -06:00
|
|
|
"user": UserID.from_string(myid),
|
2015-01-28 09:58:23 -07:00
|
|
|
"token_id": 1,
|
2015-11-04 10:29:07 -07:00
|
|
|
"is_guest": False,
|
2014-09-29 08:35:57 -06:00
|
|
|
}
|
2014-08-12 08:10:52 -06:00
|
|
|
|
2015-01-23 04:47:15 -07:00
|
|
|
hs.handlers.room_member_handler = Mock(
|
2014-08-18 09:52:29 -06:00
|
|
|
spec=[
|
2015-03-09 11:01:11 -06:00
|
|
|
"get_joined_rooms_for_user",
|
2014-08-18 09:52:29 -06:00
|
|
|
]
|
|
|
|
)
|
2014-08-12 08:10:52 -06:00
|
|
|
|
2015-08-26 06:22:23 -06:00
|
|
|
hs.get_v1auth()._get_user_by_access_token = _get_user_by_access_token
|
2014-08-12 08:10:52 -06:00
|
|
|
|
2015-01-23 03:37:38 -07:00
|
|
|
presence.register_servlets(hs, self.mock_resource)
|
2014-08-12 08:10:52 -06:00
|
|
|
|
2015-01-23 04:47:15 -07:00
|
|
|
self.u_apple = UserID.from_string("@apple:test")
|
|
|
|
self.u_banana = UserID.from_string("@banana:test")
|
2014-08-12 08:10:52 -06:00
|
|
|
|
|
|
|
@defer.inlineCallbacks
|
|
|
|
def test_get_my_list(self):
|
2014-08-18 09:52:29 -06:00
|
|
|
self.datastore.get_presence_list.return_value = defer.succeed(
|
2015-05-22 09:22:54 -06:00
|
|
|
[{"observed_user_id": "@banana:test", "accepted": True}],
|
2014-08-12 08:10:52 -06:00
|
|
|
)
|
|
|
|
|
2014-08-18 07:03:07 -06:00
|
|
|
(code, response) = yield self.mock_resource.trigger("GET",
|
2014-08-27 04:37:53 -06:00
|
|
|
"/presence/list/%s" % (myid), None)
|
2014-08-12 08:10:52 -06:00
|
|
|
|
|
|
|
self.assertEquals(200, code)
|
2014-09-01 07:45:35 -06:00
|
|
|
self.assertEquals([
|
2015-05-22 09:22:54 -06:00
|
|
|
{"user_id": "@banana:test", "presence": OFFLINE, "accepted": True},
|
2014-09-01 07:45:35 -06:00
|
|
|
], response)
|
2014-08-18 09:52:29 -06:00
|
|
|
|
|
|
|
self.datastore.get_presence_list.assert_called_with(
|
|
|
|
"apple", accepted=True
|
|
|
|
)
|
2014-08-12 08:10:52 -06:00
|
|
|
|
|
|
|
@defer.inlineCallbacks
|
|
|
|
def test_invite(self):
|
2014-08-18 09:52:29 -06:00
|
|
|
self.datastore.add_presence_list_pending.return_value = (
|
|
|
|
defer.succeed(())
|
|
|
|
)
|
|
|
|
self.datastore.is_presence_visible.return_value = defer.succeed(
|
|
|
|
True
|
|
|
|
)
|
2014-08-12 08:10:52 -06:00
|
|
|
|
2014-08-18 07:03:07 -06:00
|
|
|
(code, response) = yield self.mock_resource.trigger("POST",
|
2014-08-27 04:37:53 -06:00
|
|
|
"/presence/list/%s" % (myid),
|
2014-08-18 09:52:29 -06:00
|
|
|
"""{"invite": ["@banana:test"]}"""
|
|
|
|
)
|
2014-08-12 08:10:52 -06:00
|
|
|
|
|
|
|
self.assertEquals(200, code)
|
|
|
|
|
2014-08-18 09:52:29 -06:00
|
|
|
self.datastore.add_presence_list_pending.assert_called_with(
|
|
|
|
"apple", "@banana:test"
|
|
|
|
)
|
|
|
|
self.datastore.set_presence_list_accepted.assert_called_with(
|
|
|
|
"apple", "@banana:test"
|
|
|
|
)
|
2014-08-12 08:10:52 -06:00
|
|
|
|
|
|
|
@defer.inlineCallbacks
|
|
|
|
def test_drop(self):
|
2014-08-18 09:52:29 -06:00
|
|
|
self.datastore.del_presence_list.return_value = (
|
|
|
|
defer.succeed(())
|
|
|
|
)
|
2014-08-12 08:10:52 -06:00
|
|
|
|
2014-08-18 07:03:07 -06:00
|
|
|
(code, response) = yield self.mock_resource.trigger("POST",
|
2014-08-27 04:37:53 -06:00
|
|
|
"/presence/list/%s" % (myid),
|
2014-08-18 09:52:29 -06:00
|
|
|
"""{"drop": ["@banana:test"]}"""
|
|
|
|
)
|
2014-08-12 08:10:52 -06:00
|
|
|
|
|
|
|
self.assertEquals(200, code)
|
|
|
|
|
2014-08-18 09:52:29 -06:00
|
|
|
self.datastore.del_presence_list.assert_called_with(
|
|
|
|
"apple", "@banana:test"
|
|
|
|
)
|
2014-08-12 08:10:52 -06:00
|
|
|
|
|
|
|
|
|
|
|
class PresenceEventStreamTestCase(unittest.TestCase):
|
2015-02-11 04:37:30 -07:00
|
|
|
@defer.inlineCallbacks
|
2014-08-12 08:10:52 -06:00
|
|
|
def setUp(self):
|
2014-08-18 07:03:07 -06:00
|
|
|
self.mock_resource = MockHttpResource(prefix=PATH_PREFIX)
|
2014-08-12 08:10:52 -06:00
|
|
|
|
|
|
|
# HIDEOUS HACKERY
|
|
|
|
# TODO(paul): This should be injected in via the HomeServer DI system
|
2014-08-27 11:29:45 -06:00
|
|
|
from synapse.streams.events import (
|
2015-09-22 11:33:34 -06:00
|
|
|
PresenceEventSource, EventSources
|
2014-08-27 11:29:45 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
old_SOURCE_TYPES = EventSources.SOURCE_TYPES
|
|
|
|
def tearDown():
|
|
|
|
EventSources.SOURCE_TYPES = old_SOURCE_TYPES
|
|
|
|
self.tearDown = tearDown
|
|
|
|
|
|
|
|
EventSources.SOURCE_TYPES = {
|
|
|
|
k: NullSource for k in old_SOURCE_TYPES.keys()
|
|
|
|
}
|
2014-08-29 10:09:15 -06:00
|
|
|
EventSources.SOURCE_TYPES["presence"] = PresenceEventSource
|
2014-08-12 08:10:52 -06:00
|
|
|
|
2015-02-11 04:37:30 -07:00
|
|
|
hs = yield setup_test_homeserver(
|
2014-08-12 08:10:52 -06:00
|
|
|
http_client=None,
|
2014-08-18 07:03:07 -06:00
|
|
|
resource_for_client=self.mock_resource,
|
|
|
|
resource_for_federation=self.mock_resource,
|
2014-08-12 08:10:52 -06:00
|
|
|
datastore=Mock(spec=[
|
|
|
|
"set_presence_state",
|
|
|
|
"get_presence_list",
|
2015-05-13 06:42:21 -06:00
|
|
|
"get_rooms_for_user",
|
2014-08-12 08:10:52 -06:00
|
|
|
]),
|
|
|
|
clock=Mock(spec=[
|
|
|
|
"call_later",
|
|
|
|
"cancel_call_later",
|
|
|
|
"time_msec",
|
2015-05-13 09:54:02 -06:00
|
|
|
"looping_call",
|
2014-08-12 08:10:52 -06:00
|
|
|
]),
|
|
|
|
)
|
|
|
|
|
|
|
|
hs.get_clock().time_msec.return_value = 1000000
|
|
|
|
|
2015-11-04 10:29:07 -07:00
|
|
|
def _get_user_by_req(req=None, allow_guest=False):
|
2016-01-11 08:29:57 -07:00
|
|
|
return Requester(UserID.from_string(myid), "", False)
|
2014-08-12 08:10:52 -06:00
|
|
|
|
2015-03-24 12:56:51 -06:00
|
|
|
hs.get_v1auth().get_user_by_req = _get_user_by_req
|
2014-08-12 08:10:52 -06:00
|
|
|
|
2015-01-23 03:37:38 -07:00
|
|
|
presence.register_servlets(hs, self.mock_resource)
|
|
|
|
events.register_servlets(hs, self.mock_resource)
|
2014-08-12 08:10:52 -06:00
|
|
|
|
2014-09-02 09:29:04 -06:00
|
|
|
hs.handlers.room_member_handler = Mock(spec=[])
|
|
|
|
|
|
|
|
self.room_members = []
|
|
|
|
|
|
|
|
def get_rooms_for_user(user):
|
|
|
|
if user in self.room_members:
|
|
|
|
return ["a-room"]
|
|
|
|
else:
|
|
|
|
return []
|
2015-03-09 11:01:11 -06:00
|
|
|
hs.handlers.room_member_handler.get_joined_rooms_for_user = get_rooms_for_user
|
2015-05-20 06:22:18 -06:00
|
|
|
hs.handlers.room_member_handler.get_room_members = (
|
|
|
|
lambda r: self.room_members if r == "a-room" else []
|
|
|
|
)
|
2015-11-12 09:45:28 -07:00
|
|
|
hs.handlers.room_member_handler._filter_events_for_client = (
|
|
|
|
lambda user_id, events, **kwargs: events
|
|
|
|
)
|
2014-08-12 08:10:52 -06:00
|
|
|
|
|
|
|
self.mock_datastore = hs.get_datastore()
|
2015-02-09 07:14:15 -07:00
|
|
|
self.mock_datastore.get_app_service_by_token = Mock(return_value=None)
|
2015-02-27 02:46:38 -07:00
|
|
|
self.mock_datastore.get_app_service_by_user_id = Mock(
|
|
|
|
return_value=defer.succeed(None)
|
|
|
|
)
|
2015-05-13 06:42:21 -06:00
|
|
|
self.mock_datastore.get_rooms_for_user = (
|
2015-05-21 08:23:40 -06:00
|
|
|
lambda u: [
|
|
|
|
namedtuple("Room", "room_id")(r)
|
|
|
|
for r in get_rooms_for_user(UserID.from_string(u))
|
|
|
|
]
|
2015-05-13 06:42:21 -06:00
|
|
|
)
|
2014-08-29 12:12:22 -06:00
|
|
|
|
|
|
|
def get_profile_displayname(user_id):
|
|
|
|
return defer.succeed("Frank")
|
|
|
|
self.mock_datastore.get_profile_displayname = get_profile_displayname
|
|
|
|
|
|
|
|
def get_profile_avatar_url(user_id):
|
|
|
|
return defer.succeed(None)
|
|
|
|
self.mock_datastore.get_profile_avatar_url = get_profile_avatar_url
|
|
|
|
|
2014-09-02 09:29:04 -06:00
|
|
|
def user_rooms_intersect(user_list):
|
|
|
|
room_member_ids = map(lambda u: u.to_string(), self.room_members)
|
|
|
|
|
|
|
|
shared = all(map(lambda i: i in room_member_ids, user_list))
|
|
|
|
return defer.succeed(shared)
|
|
|
|
self.mock_datastore.user_rooms_intersect = user_rooms_intersect
|
|
|
|
|
|
|
|
def get_joined_hosts_for_room(room_id):
|
|
|
|
return []
|
|
|
|
self.mock_datastore.get_joined_hosts_for_room = get_joined_hosts_for_room
|
|
|
|
|
2014-08-12 08:10:52 -06:00
|
|
|
self.presence = hs.get_handlers().presence_handler
|
|
|
|
|
2015-01-23 04:47:15 -07:00
|
|
|
self.u_apple = UserID.from_string("@apple:test")
|
|
|
|
self.u_banana = UserID.from_string("@banana:test")
|
2014-08-12 08:10:52 -06:00
|
|
|
|
|
|
|
@defer.inlineCallbacks
|
|
|
|
def test_shortpoll(self):
|
2014-09-02 09:29:04 -06:00
|
|
|
self.room_members = [self.u_apple, self.u_banana]
|
|
|
|
|
2014-08-12 08:10:52 -06:00
|
|
|
self.mock_datastore.set_presence_state.return_value = defer.succeed(
|
2014-09-03 08:37:10 -06:00
|
|
|
{"state": ONLINE}
|
|
|
|
)
|
2014-08-12 08:10:52 -06:00
|
|
|
self.mock_datastore.get_presence_list.return_value = defer.succeed(
|
2014-09-03 08:37:10 -06:00
|
|
|
[]
|
|
|
|
)
|
2014-08-12 08:10:52 -06:00
|
|
|
|
2014-08-18 07:03:07 -06:00
|
|
|
(code, response) = yield self.mock_resource.trigger("GET",
|
2014-08-12 08:10:52 -06:00
|
|
|
"/events?timeout=0", None)
|
|
|
|
|
|
|
|
self.assertEquals(200, code)
|
|
|
|
|
|
|
|
# We've forced there to be only one data stream so the tokens will
|
|
|
|
# all be ours
|
|
|
|
|
|
|
|
# I'll already get my own presence state change
|
2015-10-30 10:38:35 -06:00
|
|
|
self.assertEquals({"start": "0_1_0_0_0", "end": "0_1_0_0_0", "chunk": []},
|
2014-08-29 10:39:33 -06:00
|
|
|
response
|
|
|
|
)
|
2014-08-12 08:10:52 -06:00
|
|
|
|
|
|
|
self.mock_datastore.set_presence_state.return_value = defer.succeed(
|
2014-09-03 08:37:10 -06:00
|
|
|
{"state": ONLINE}
|
|
|
|
)
|
2015-05-13 06:42:21 -06:00
|
|
|
self.mock_datastore.get_presence_list.return_value = defer.succeed([])
|
2014-08-12 08:10:52 -06:00
|
|
|
|
|
|
|
yield self.presence.set_state(self.u_banana, self.u_banana,
|
2014-09-01 07:45:35 -06:00
|
|
|
state={"presence": ONLINE}
|
|
|
|
)
|
2014-08-12 08:10:52 -06:00
|
|
|
|
2015-05-13 06:42:21 -06:00
|
|
|
yield run_on_reactor()
|
|
|
|
|
2014-08-18 07:03:07 -06:00
|
|
|
(code, response) = yield self.mock_resource.trigger("GET",
|
2015-05-13 06:42:21 -06:00
|
|
|
"/events?from=s0_1_0&timeout=0", None)
|
2014-08-12 08:10:52 -06:00
|
|
|
|
|
|
|
self.assertEquals(200, code)
|
2015-10-30 10:38:35 -06:00
|
|
|
self.assertEquals({"start": "s0_1_0_0_0", "end": "s0_2_0_0_0", "chunk": [
|
2014-08-12 08:10:52 -06:00
|
|
|
{"type": "m.presence",
|
2014-08-13 12:18:55 -06:00
|
|
|
"content": {
|
|
|
|
"user_id": "@banana:test",
|
2014-09-01 07:45:35 -06:00
|
|
|
"presence": ONLINE,
|
2014-08-29 12:12:22 -06:00
|
|
|
"displayname": "Frank",
|
2014-09-01 08:38:37 -06:00
|
|
|
"last_active_ago": 0,
|
2014-08-13 12:18:55 -06:00
|
|
|
}},
|
2014-08-12 08:10:52 -06:00
|
|
|
]}, response)
|