Merge branch 'client_server_url_rename' into develop
This commit is contained in:
commit
0e7a41dc99
|
@ -99,7 +99,6 @@ class FederationTestCase(unittest.TestCase):
|
||||||
new_event = mem_handler.change_membership.call_args[0][0]
|
new_event = mem_handler.change_membership.call_args[0][0]
|
||||||
self.assertEquals(RoomMemberEvent.TYPE, new_event.type)
|
self.assertEquals(RoomMemberEvent.TYPE, new_event.type)
|
||||||
self.assertEquals(room_id, new_event.room_id)
|
self.assertEquals(room_id, new_event.room_id)
|
||||||
self.assertEquals(user_id, new_event.target_user_id)
|
|
||||||
self.assertEquals(user_id, new_event.state_key)
|
self.assertEquals(user_id, new_event.state_key)
|
||||||
self.assertEquals(Membership.JOIN, new_event.membership)
|
self.assertEquals(Membership.JOIN, new_event.membership)
|
||||||
|
|
||||||
|
|
|
@ -85,7 +85,7 @@ class RoomMemberHandlerTestCase(unittest.TestCase):
|
||||||
event = self.hs.get_event_factory().create_event(
|
event = self.hs.get_event_factory().create_event(
|
||||||
etype=RoomMemberEvent.TYPE,
|
etype=RoomMemberEvent.TYPE,
|
||||||
user_id=user_id,
|
user_id=user_id,
|
||||||
target_user_id=target_user_id,
|
state_key=target_user_id,
|
||||||
room_id=room_id,
|
room_id=room_id,
|
||||||
membership=Membership.INVITE,
|
membership=Membership.INVITE,
|
||||||
content=content,
|
content=content,
|
||||||
|
@ -133,7 +133,7 @@ class RoomMemberHandlerTestCase(unittest.TestCase):
|
||||||
event = self.hs.get_event_factory().create_event(
|
event = self.hs.get_event_factory().create_event(
|
||||||
etype=RoomMemberEvent.TYPE,
|
etype=RoomMemberEvent.TYPE,
|
||||||
user_id=user_id,
|
user_id=user_id,
|
||||||
target_user_id=target_user_id,
|
state_key=target_user_id,
|
||||||
room_id=room_id,
|
room_id=room_id,
|
||||||
membership=Membership.JOIN,
|
membership=Membership.JOIN,
|
||||||
content=content,
|
content=content,
|
||||||
|
@ -359,7 +359,7 @@ class RoomCreationTest(unittest.TestCase):
|
||||||
self.assertEquals(RoomMemberEvent.TYPE, join_event.type)
|
self.assertEquals(RoomMemberEvent.TYPE, join_event.type)
|
||||||
self.assertEquals(room_id, join_event.room_id)
|
self.assertEquals(room_id, join_event.room_id)
|
||||||
self.assertEquals(user_id, join_event.user_id)
|
self.assertEquals(user_id, join_event.user_id)
|
||||||
self.assertEquals(user_id, join_event.target_user_id)
|
self.assertEquals(user_id, join_event.state_key)
|
||||||
|
|
||||||
self.assertTrue(self.state_handler.handle_new_event.called)
|
self.assertTrue(self.state_handler.handle_new_event.called)
|
||||||
|
|
||||||
|
|
|
@ -94,7 +94,7 @@ class RoomPermissionsTestCase(RestTestCase):
|
||||||
# set topic for public room
|
# set topic for public room
|
||||||
(code, response) = yield self.mock_resource.trigger(
|
(code, response) = yield self.mock_resource.trigger(
|
||||||
"PUT",
|
"PUT",
|
||||||
"/rooms/%s/topic" % self.created_public_rmid,
|
"/rooms/%s/state/m.room.topic" % self.created_public_rmid,
|
||||||
'{"topic":"Public Room Topic"}')
|
'{"topic":"Public Room Topic"}')
|
||||||
self.assertEquals(200, code, msg=str(response))
|
self.assertEquals(200, code, msg=str(response))
|
||||||
|
|
||||||
|
@ -175,15 +175,15 @@ class RoomPermissionsTestCase(RestTestCase):
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def test_topic_perms(self):
|
def test_topic_perms(self):
|
||||||
topic_content = '{"topic":"My Topic Name"}'
|
topic_content = '{"topic":"My Topic Name"}'
|
||||||
topic_path = "/rooms/%s/topic" % self.created_rmid
|
topic_path = "/rooms/%s/state/m.room.topic" % self.created_rmid
|
||||||
|
|
||||||
# set/get topic in uncreated room, expect 403
|
# set/get topic in uncreated room, expect 403
|
||||||
(code, response) = yield self.mock_resource.trigger(
|
(code, response) = yield self.mock_resource.trigger(
|
||||||
"PUT", "/rooms/%s/topic" % self.uncreated_rmid,
|
"PUT", "/rooms/%s/state/m.room.topic" % self.uncreated_rmid,
|
||||||
topic_content)
|
topic_content)
|
||||||
self.assertEquals(403, code, msg=str(response))
|
self.assertEquals(403, code, msg=str(response))
|
||||||
(code, response) = yield self.mock_resource.trigger_get(
|
(code, response) = yield self.mock_resource.trigger_get(
|
||||||
"/rooms/%s/topic" % self.uncreated_rmid)
|
"/rooms/%s/state/m.room.topic" % self.uncreated_rmid)
|
||||||
self.assertEquals(403, code, msg=str(response))
|
self.assertEquals(403, code, msg=str(response))
|
||||||
|
|
||||||
# set/get topic in created PRIVATE room not joined, expect 403
|
# set/get topic in created PRIVATE room not joined, expect 403
|
||||||
|
@ -223,19 +223,19 @@ class RoomPermissionsTestCase(RestTestCase):
|
||||||
|
|
||||||
# get topic in PUBLIC room, not joined, expect 200 (or 404)
|
# get topic in PUBLIC room, not joined, expect 200 (or 404)
|
||||||
(code, response) = yield self.mock_resource.trigger_get(
|
(code, response) = yield self.mock_resource.trigger_get(
|
||||||
"/rooms/%s/topic" % self.created_public_rmid)
|
"/rooms/%s/state/m.room.topic" % self.created_public_rmid)
|
||||||
self.assertEquals(200, code, msg=str(response))
|
self.assertEquals(200, code, msg=str(response))
|
||||||
|
|
||||||
# set topic in PUBLIC room, not joined, expect 403
|
# set topic in PUBLIC room, not joined, expect 403
|
||||||
(code, response) = yield self.mock_resource.trigger(
|
(code, response) = yield self.mock_resource.trigger(
|
||||||
"PUT",
|
"PUT",
|
||||||
"/rooms/%s/topic" % self.created_public_rmid,
|
"/rooms/%s/state/m.room.topic" % self.created_public_rmid,
|
||||||
topic_content)
|
topic_content)
|
||||||
self.assertEquals(403, code, msg=str(response))
|
self.assertEquals(403, code, msg=str(response))
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def _test_get_membership(self, room=None, members=[], expect_code=None):
|
def _test_get_membership(self, room=None, members=[], expect_code=None):
|
||||||
path = "/rooms/%s/members/%s/state"
|
path = "/rooms/%s/state/m.room.member/%s"
|
||||||
for member in members:
|
for member in members:
|
||||||
(code, response) = yield self.mock_resource.trigger_get(
|
(code, response) = yield self.mock_resource.trigger_get(
|
||||||
path %
|
path %
|
||||||
|
@ -291,12 +291,12 @@ class RoomPermissionsTestCase(RestTestCase):
|
||||||
def test_membership_public_room_perms(self):
|
def test_membership_public_room_perms(self):
|
||||||
room = self.created_public_rmid
|
room = self.created_public_rmid
|
||||||
# get membership of self, get membership of other, public room + invite
|
# get membership of self, get membership of other, public room + invite
|
||||||
# expect all 403s
|
# expect all 200s - public rooms, you can see who is in them.
|
||||||
yield self.invite(room=room, src=self.rmcreator_id,
|
yield self.invite(room=room, src=self.rmcreator_id,
|
||||||
targ=self.user_id)
|
targ=self.user_id)
|
||||||
yield self._test_get_membership(
|
yield self._test_get_membership(
|
||||||
members=[self.user_id, self.rmcreator_id],
|
members=[self.user_id, self.rmcreator_id],
|
||||||
room=room, expect_code=403)
|
room=room, expect_code=200)
|
||||||
|
|
||||||
# get membership of self, get membership of other, public room + joined
|
# get membership of self, get membership of other, public room + joined
|
||||||
# expect all 200s
|
# expect all 200s
|
||||||
|
@ -306,11 +306,11 @@ class RoomPermissionsTestCase(RestTestCase):
|
||||||
room=room, expect_code=200)
|
room=room, expect_code=200)
|
||||||
|
|
||||||
# get membership of self, get membership of other, public room + left
|
# get membership of self, get membership of other, public room + left
|
||||||
# expect all 403s
|
# expect all 200s - public rooms, you can always see who is in them.
|
||||||
yield self.leave(room=room, user=self.user_id)
|
yield self.leave(room=room, user=self.user_id)
|
||||||
yield self._test_get_membership(
|
yield self._test_get_membership(
|
||||||
members=[self.user_id, self.rmcreator_id],
|
members=[self.user_id, self.rmcreator_id],
|
||||||
room=room, expect_code=403)
|
room=room, expect_code=200)
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def test_invited_permissions(self):
|
def test_invited_permissions(self):
|
||||||
|
@ -614,7 +614,7 @@ class RoomTopicTestCase(RestTestCase):
|
||||||
self.mock_resource = MockHttpResource(prefix=PATH_PREFIX)
|
self.mock_resource = MockHttpResource(prefix=PATH_PREFIX)
|
||||||
self.auth_user_id = self.user_id
|
self.auth_user_id = self.user_id
|
||||||
self.room_id = "!rid1:test"
|
self.room_id = "!rid1:test"
|
||||||
self.path = "/rooms/%s/topic" % self.room_id
|
self.path = "/rooms/%s/state/m.room.topic" % self.room_id
|
||||||
|
|
||||||
state_handler = Mock(spec=["handle_new_event"])
|
state_handler = Mock(spec=["handle_new_event"])
|
||||||
state_handler.handle_new_event.return_value = True
|
state_handler.handle_new_event.return_value = True
|
||||||
|
@ -749,7 +749,7 @@ class RoomMemberStateTestCase(RestTestCase):
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def test_invalid_puts(self):
|
def test_invalid_puts(self):
|
||||||
path = "/rooms/%s/members/%s/state" % (self.room_id, self.user_id)
|
path = "/rooms/%s/state/m.room.member/%s" % (self.room_id, self.user_id)
|
||||||
# missing keys or invalid json
|
# missing keys or invalid json
|
||||||
(code, response) = yield self.mock_resource.trigger("PUT",
|
(code, response) = yield self.mock_resource.trigger("PUT",
|
||||||
path, '{}')
|
path, '{}')
|
||||||
|
@ -783,7 +783,7 @@ class RoomMemberStateTestCase(RestTestCase):
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def test_rooms_members_self(self):
|
def test_rooms_members_self(self):
|
||||||
path = "/rooms/%s/members/%s/state" % (
|
path = "/rooms/%s/state/m.room.member/%s" % (
|
||||||
urllib.quote(self.room_id), self.user_id
|
urllib.quote(self.room_id), self.user_id
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -804,7 +804,7 @@ class RoomMemberStateTestCase(RestTestCase):
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def test_rooms_members_other(self):
|
def test_rooms_members_other(self):
|
||||||
self.other_id = "@zzsid1:red"
|
self.other_id = "@zzsid1:red"
|
||||||
path = "/rooms/%s/members/%s/state" % (
|
path = "/rooms/%s/state/m.room.member/%s" % (
|
||||||
urllib.quote(self.room_id), self.other_id
|
urllib.quote(self.room_id), self.other_id
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -820,7 +820,7 @@ class RoomMemberStateTestCase(RestTestCase):
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def test_rooms_members_other_custom_keys(self):
|
def test_rooms_members_other_custom_keys(self):
|
||||||
self.other_id = "@zzsid1:red"
|
self.other_id = "@zzsid1:red"
|
||||||
path = "/rooms/%s/members/%s/state" % (
|
path = "/rooms/%s/state/m.room.member/%s" % (
|
||||||
urllib.quote(self.room_id), self.other_id
|
urllib.quote(self.room_id), self.other_id
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@ from twisted.trial import unittest
|
||||||
|
|
||||||
from synapse.api.constants import Membership
|
from synapse.api.constants import Membership
|
||||||
|
|
||||||
|
import json
|
||||||
import time
|
import time
|
||||||
|
|
||||||
class RestTestCase(unittest.TestCase):
|
class RestTestCase(unittest.TestCase):
|
||||||
|
@ -71,23 +72,22 @@ class RestTestCase(unittest.TestCase):
|
||||||
expect_code=expect_code)
|
expect_code=expect_code)
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def change_membership(self, room=None, src=None, targ=None,
|
def change_membership(self, room, src, targ, membership, tok=None,
|
||||||
membership=None, expect_code=200, tok=None):
|
expect_code=200):
|
||||||
temp_id = self.auth_user_id
|
temp_id = self.auth_user_id
|
||||||
self.auth_user_id = src
|
self.auth_user_id = src
|
||||||
|
|
||||||
path = "/rooms/%s/members/%s/state" % (room, targ)
|
path = "/rooms/%s/state/m.room.member/%s" % (room, targ)
|
||||||
if tok:
|
if tok:
|
||||||
path = path + "?access_token=%s" % tok
|
path = path + "?access_token=%s" % tok
|
||||||
|
|
||||||
if membership == Membership.LEAVE:
|
data = {
|
||||||
(code, response) = yield self.mock_resource.trigger("DELETE", path,
|
"membership": membership
|
||||||
None)
|
}
|
||||||
self.assertEquals(expect_code, code, msg=str(response))
|
|
||||||
else:
|
(code, response) = yield self.mock_resource.trigger("PUT", path,
|
||||||
(code, response) = yield self.mock_resource.trigger("PUT", path,
|
json.dumps(data))
|
||||||
'{"membership":"%s"}' % membership)
|
self.assertEquals(expect_code, code, msg=str(response))
|
||||||
self.assertEquals(expect_code, code, msg=str(response))
|
|
||||||
|
|
||||||
self.auth_user_id = temp_id
|
self.auth_user_id = temp_id
|
||||||
|
|
||||||
|
|
|
@ -183,7 +183,7 @@ class MemoryDataStore(object):
|
||||||
def persist_event(self, event):
|
def persist_event(self, event):
|
||||||
if event.type == RoomMemberEvent.TYPE:
|
if event.type == RoomMemberEvent.TYPE:
|
||||||
room_id = event.room_id
|
room_id = event.room_id
|
||||||
user = event.target_user_id
|
user = event.state_key
|
||||||
membership = event.membership
|
membership = event.membership
|
||||||
self.members.setdefault(room_id, {})[user] = event
|
self.members.setdefault(room_id, {})[user] = event
|
||||||
|
|
||||||
|
@ -196,7 +196,9 @@ class MemoryDataStore(object):
|
||||||
def get_current_state(self, room_id, event_type=None, state_key=""):
|
def get_current_state(self, room_id, event_type=None, state_key=""):
|
||||||
if event_type:
|
if event_type:
|
||||||
key = (room_id, event_type, state_key)
|
key = (room_id, event_type, state_key)
|
||||||
return self.current_state.get(key)
|
if self.current_state.get(key):
|
||||||
|
return [self.current_state.get(key)]
|
||||||
|
return None
|
||||||
else:
|
else:
|
||||||
return [
|
return [
|
||||||
e for e in self.current_state
|
e for e in self.current_state
|
||||||
|
|
Loading…
Reference in New Issue