Merge pull request #590 from matrix-org/markjh/formatting

Fix flake8 warnings for tests
This commit is contained in:
Mark Haines 2016-02-19 15:55:02 +00:00
commit b82d6f70a4
39 changed files with 359 additions and 364 deletions

View file

@ -12,4 +12,3 @@
# 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.

View file

@ -281,9 +281,9 @@ class AuthTestCase(unittest.TestCase):
macaroon.add_first_party_caveat("gen = 1")
macaroon.add_first_party_caveat("type = access")
macaroon.add_first_party_caveat("user_id = %s" % (user,))
macaroon.add_first_party_caveat("time < 1") # ms
macaroon.add_first_party_caveat("time < 1") # ms
self.hs.clock.now = 5000 # seconds
self.hs.clock.now = 5000 # seconds
yield self.auth.get_user_from_macaroon(macaroon.serialize())
# TODO(daniel): Turn on the check that we validate expiration, when we

View file

@ -21,7 +21,6 @@ from tests.utils import (
MockHttpResource, DeferredMockCallable, setup_test_homeserver
)
from synapse.types import UserID
from synapse.api.filtering import Filter
from synapse.events import FrozenEvent
@ -356,7 +355,6 @@ class FilteringTestCase(unittest.TestCase):
"types": ["m.*"]
}
}
user = UserID.from_string("@" + user_localpart + ":test")
filter_id = yield self.datastore.add_user_filter(
user_localpart=user_localpart,
user_filter=user_filter_json,
@ -411,7 +409,6 @@ class FilteringTestCase(unittest.TestCase):
}
}
}
user = UserID.from_string("@" + user_localpart + ":test")
filter_id = yield self.datastore.add_user_filter(
user_localpart=user_localpart,
user_filter=user_filter_json,
@ -440,7 +437,6 @@ class FilteringTestCase(unittest.TestCase):
}
}
}
user = UserID.from_string("@" + user_localpart + ":test")
filter_id = yield self.datastore.add_user_filter(
user_localpart=user_localpart,
user_filter=user_filter_json,
@ -476,12 +472,12 @@ class FilteringTestCase(unittest.TestCase):
)
self.assertEquals(filter_id, 0)
self.assertEquals(user_filter_json,
(yield self.datastore.get_user_filter(
self.assertEquals(user_filter_json, (
yield self.datastore.get_user_filter(
user_localpart=user_localpart,
filter_id=0,
))
)
)
))
@defer.inlineCallbacks
def test_get_filter(self):

View file

@ -2,6 +2,7 @@ from synapse.api.ratelimiting import Ratelimiter
from tests import unittest
class TestRatelimiter(unittest.TestCase):
def test_allowed(self):

View file

@ -14,7 +14,7 @@
# limitations under the License.
from synapse.appservice import ApplicationService
from mock import Mock, PropertyMock
from mock import Mock
from tests import unittest

View file

@ -12,7 +12,7 @@
# 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.
from synapse.appservice import ApplicationServiceState, AppServiceTransaction
from synapse.appservice import ApplicationServiceState
from synapse.appservice.scheduler import (
_ServiceQueuer, _TransactionController, _Recoverer
)
@ -235,7 +235,7 @@ class ApplicationServiceSchedulerQueuerTestCase(unittest.TestCase):
srv_2_event2 = Mock(event_id="srv2b")
send_return_list = [srv_1_defer, srv_2_defer]
self.txn_ctrl.send = Mock(side_effect=lambda x,y: send_return_list.pop(0))
self.txn_ctrl.send = Mock(side_effect=lambda x, y: send_return_list.pop(0))
# send events for different ASes and make sure they are sent
self.queuer.enqueue(srv1, srv_1_event)

View file

@ -12,4 +12,3 @@
# 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.

View file

@ -19,6 +19,7 @@ from .. import unittest
from synapse.events import FrozenEvent
from synapse.events.utils import prune_event
class PruneEventTestCase(unittest.TestCase):
""" Asserts that a new event constructed with `evdict` will look like
`matchdict` when it is redacted. """

View file

@ -129,8 +129,6 @@ class AppServiceHandlerTestCase(unittest.TestCase):
self.assertEquals(result.room_id, room_id)
self.assertEquals(result.servers, servers)
def _mkservice(self, is_interested):
service = Mock()
service.is_interested = Mock(return_value=is_interested)

View file

@ -15,7 +15,6 @@
import pymacaroons
from mock import Mock, NonCallableMock
from synapse.handlers.auth import AuthHandler
from tests import unittest
from tests.utils import setup_test_homeserver

View file

@ -41,8 +41,10 @@ class ProfileTestCase(unittest.TestCase):
])
self.query_handlers = {}
def register_query_handler(query_type, handler):
self.query_handlers[query_type] = handler
self.mock_federation.register_query_handler = register_query_handler
hs = yield setup_test_homeserver(
@ -63,7 +65,7 @@ class ProfileTestCase(unittest.TestCase):
self.store = hs.get_datastore()
self.frank = UserID.from_string("@1234ABCD:test")
self.bob = UserID.from_string("@4567:test")
self.bob = UserID.from_string("@4567:test")
self.alice = UserID.from_string("@alice:remote")
yield self.store.create_profile(self.frank.localpart)
@ -133,8 +135,9 @@ class ProfileTestCase(unittest.TestCase):
@defer.inlineCallbacks
def test_set_my_avatar(self):
yield self.handler.set_avatar_url(self.frank, self.frank,
"http://my.server/pic.gif")
yield self.handler.set_avatar_url(
self.frank, self.frank, "http://my.server/pic.gif"
)
self.assertEquals(
(yield self.store.get_profile_avatar_url(self.frank.localpart)),

View file

@ -138,9 +138,9 @@ class TypingNotificationsTestCase(unittest.TestCase):
self.room_member_handler.get_joined_rooms_for_user = get_joined_rooms_for_user
@defer.inlineCallbacks
def fetch_room_distributions_into(room_id, localusers=None,
remotedomains=None, ignore_user=None):
def fetch_room_distributions_into(
room_id, localusers=None, remotedomains=None, ignore_user=None
):
members = yield get_room_members(room_id)
for member in members:
if ignore_user is not None and member == ignore_user:
@ -153,7 +153,8 @@ class TypingNotificationsTestCase(unittest.TestCase):
if remotedomains is not None:
remotedomains.add(member.domain)
self.room_member_handler.fetch_room_distributions_into = (
fetch_room_distributions_into)
fetch_room_distributions_into
)
def check_joined_room(room_id, user_id):
if user_id not in [u.to_string() for u in self.room_members]:
@ -207,9 +208,12 @@ class TypingNotificationsTestCase(unittest.TestCase):
put_json = self.mock_http_client.put_json
put_json.expect_call_and_return(
call("farm",
call(
"farm",
path="/_matrix/federation/v1/send/1000000/",
data=_expect_edu("farm", "m.typing",
data=_expect_edu(
"farm",
"m.typing",
content={
"room_id": self.room_id,
"user_id": self.u_apple.to_string(),
@ -237,9 +241,12 @@ class TypingNotificationsTestCase(unittest.TestCase):
self.assertEquals(self.event_source.get_current_key(), 0)
yield self.mock_federation_resource.trigger("PUT",
yield self.mock_federation_resource.trigger(
"PUT",
"/_matrix/federation/v1/send/1000000/",
_make_edu_json("farm", "m.typing",
_make_edu_json(
"farm",
"m.typing",
content={
"room_id": self.room_id,
"user_id": self.u_onion.to_string(),
@ -257,16 +264,13 @@ class TypingNotificationsTestCase(unittest.TestCase):
room_ids=[self.room_id],
from_key=0
)
self.assertEquals(
events[0],
[
{"type": "m.typing",
"room_id": self.room_id,
"content": {
"user_ids": [self.u_onion.to_string()],
}},
]
)
self.assertEquals(events[0], [{
"type": "m.typing",
"room_id": self.room_id,
"content": {
"user_ids": [self.u_onion.to_string()],
},
}])
@defer.inlineCallbacks
def test_stopped_typing(self):
@ -274,9 +278,12 @@ class TypingNotificationsTestCase(unittest.TestCase):
put_json = self.mock_http_client.put_json
put_json.expect_call_and_return(
call("farm",
call(
"farm",
path="/_matrix/federation/v1/send/1000000/",
data=_expect_edu("farm", "m.typing",
data=_expect_edu(
"farm",
"m.typing",
content={
"room_id": self.room_id,
"user_id": self.u_apple.to_string(),
@ -317,16 +324,13 @@ class TypingNotificationsTestCase(unittest.TestCase):
room_ids=[self.room_id],
from_key=0,
)
self.assertEquals(
events[0],
[
{"type": "m.typing",
"room_id": self.room_id,
"content": {
"user_ids": [],
}},
]
)
self.assertEquals(events[0], [{
"type": "m.typing",
"room_id": self.room_id,
"content": {
"user_ids": [],
},
}])
@defer.inlineCallbacks
def test_typing_timeout(self):
@ -351,16 +355,13 @@ class TypingNotificationsTestCase(unittest.TestCase):
room_ids=[self.room_id],
from_key=0,
)
self.assertEquals(
events[0],
[
{"type": "m.typing",
"room_id": self.room_id,
"content": {
"user_ids": [self.u_apple.to_string()],
}},
]
)
self.assertEquals(events[0], [{
"type": "m.typing",
"room_id": self.room_id,
"content": {
"user_ids": [self.u_apple.to_string()],
},
}])
self.clock.advance_time(11)
@ -373,16 +374,13 @@ class TypingNotificationsTestCase(unittest.TestCase):
room_ids=[self.room_id],
from_key=1,
)
self.assertEquals(
events[0],
[
{"type": "m.typing",
"room_id": self.room_id,
"content": {
"user_ids": [],
}},
]
)
self.assertEquals(events[0], [{
"type": "m.typing",
"room_id": self.room_id,
"content": {
"user_ids": [],
},
}])
# SYN-230 - see if we can still set after timeout
@ -403,13 +401,10 @@ class TypingNotificationsTestCase(unittest.TestCase):
room_ids=[self.room_id],
from_key=0,
)
self.assertEquals(
events[0],
[
{"type": "m.typing",
"room_id": self.room_id,
"content": {
"user_ids": [self.u_apple.to_string()],
}},
]
)
self.assertEquals(events[0], [{
"type": "m.typing",
"room_id": self.room_id,
"content": {
"user_ids": [self.u_apple.to_string()],
},
}])

View file

@ -12,4 +12,3 @@
# 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.

View file

@ -65,8 +65,9 @@ class ProfileTestCase(unittest.TestCase):
mocked_get = self.mock_handler.get_displayname
mocked_get.return_value = defer.succeed("Frank")
(code, response) = yield self.mock_resource.trigger("GET",
"/profile/%s/displayname" % (myid), None)
(code, response) = yield self.mock_resource.trigger(
"GET", "/profile/%s/displayname" % (myid), None
)
self.assertEquals(200, code)
self.assertEquals({"displayname": "Frank"}, response)
@ -77,9 +78,11 @@ class ProfileTestCase(unittest.TestCase):
mocked_set = self.mock_handler.set_displayname
mocked_set.return_value = defer.succeed(())
(code, response) = yield self.mock_resource.trigger("PUT",
"/profile/%s/displayname" % (myid),
'{"displayname": "Frank Jr."}')
(code, response) = yield self.mock_resource.trigger(
"PUT",
"/profile/%s/displayname" % (myid),
'{"displayname": "Frank Jr."}'
)
self.assertEquals(200, code)
self.assertEquals(mocked_set.call_args[0][0].localpart, "1234ABCD")
@ -91,19 +94,23 @@ class ProfileTestCase(unittest.TestCase):
mocked_set = self.mock_handler.set_displayname
mocked_set.side_effect = AuthError(400, "message")
(code, response) = yield self.mock_resource.trigger("PUT",
"/profile/%s/displayname" % ("@4567:test"), '"Frank Jr."')
(code, response) = yield self.mock_resource.trigger(
"PUT", "/profile/%s/displayname" % ("@4567:test"), '"Frank Jr."'
)
self.assertTrue(400 <= code < 499,
msg="code %d is in the 4xx range" % (code))
self.assertTrue(
400 <= code < 499,
msg="code %d is in the 4xx range" % (code)
)
@defer.inlineCallbacks
def test_get_other_name(self):
mocked_get = self.mock_handler.get_displayname
mocked_get.return_value = defer.succeed("Bob")
(code, response) = yield self.mock_resource.trigger("GET",
"/profile/%s/displayname" % ("@opaque:elsewhere"), None)
(code, response) = yield self.mock_resource.trigger(
"GET", "/profile/%s/displayname" % ("@opaque:elsewhere"), None
)
self.assertEquals(200, code)
self.assertEquals({"displayname": "Bob"}, response)
@ -113,19 +120,23 @@ class ProfileTestCase(unittest.TestCase):
mocked_set = self.mock_handler.set_displayname
mocked_set.side_effect = SynapseError(400, "message")
(code, response) = yield self.mock_resource.trigger("PUT",
"/profile/%s/displayname" % ("@opaque:elsewhere"), None)
(code, response) = yield self.mock_resource.trigger(
"PUT", "/profile/%s/displayname" % ("@opaque:elsewhere"), None
)
self.assertTrue(400 <= code <= 499,
msg="code %d is in the 4xx range" % (code))
self.assertTrue(
400 <= code <= 499,
msg="code %d is in the 4xx range" % (code)
)
@defer.inlineCallbacks
def test_get_my_avatar(self):
mocked_get = self.mock_handler.get_avatar_url
mocked_get.return_value = defer.succeed("http://my.server/me.png")
(code, response) = yield self.mock_resource.trigger("GET",
"/profile/%s/avatar_url" % (myid), None)
(code, response) = yield self.mock_resource.trigger(
"GET", "/profile/%s/avatar_url" % (myid), None
)
self.assertEquals(200, code)
self.assertEquals({"avatar_url": "http://my.server/me.png"}, response)
@ -136,12 +147,13 @@ class ProfileTestCase(unittest.TestCase):
mocked_set = self.mock_handler.set_avatar_url
mocked_set.return_value = defer.succeed(())
(code, response) = yield self.mock_resource.trigger("PUT",
"/profile/%s/avatar_url" % (myid),
'{"avatar_url": "http://my.server/pic.gif"}')
(code, response) = yield self.mock_resource.trigger(
"PUT",
"/profile/%s/avatar_url" % (myid),
'{"avatar_url": "http://my.server/pic.gif"}'
)
self.assertEquals(200, code)
self.assertEquals(mocked_set.call_args[0][0].localpart, "1234ABCD")
self.assertEquals(mocked_set.call_args[0][1].localpart, "1234ABCD")
self.assertEquals(mocked_set.call_args[0][2],
"http://my.server/pic.gif")
self.assertEquals(mocked_set.call_args[0][2], "http://my.server/pic.gif")

View file

@ -82,19 +82,22 @@ class RoomPermissionsTestCase(RestTestCase):
is_public=True)
# send a message in one of the rooms
self.created_rmid_msg_path = ("/rooms/%s/send/m.room.message/a1" %
(self.created_rmid))
self.created_rmid_msg_path = (
"/rooms/%s/send/m.room.message/a1" % (self.created_rmid)
)
(code, response) = yield self.mock_resource.trigger(
"PUT",
self.created_rmid_msg_path,
'{"msgtype":"m.text","body":"test msg"}')
"PUT",
self.created_rmid_msg_path,
'{"msgtype":"m.text","body":"test msg"}'
)
self.assertEquals(200, code, msg=str(response))
# set topic for public room
(code, response) = yield self.mock_resource.trigger(
"PUT",
"/rooms/%s/state/m.room.topic" % self.created_public_rmid,
'{"topic":"Public Room Topic"}')
"PUT",
"/rooms/%s/state/m.room.topic" % self.created_public_rmid,
'{"topic":"Public Room Topic"}'
)
self.assertEquals(200, code, msg=str(response))
# auth as user_id now
@ -103,37 +106,6 @@ class RoomPermissionsTestCase(RestTestCase):
def tearDown(self):
pass
# @defer.inlineCallbacks
# def test_get_message(self):
# # get message in uncreated room, expect 403
# (code, response) = yield self.mock_resource.trigger_get(
# "/rooms/noroom/messages/someid/m1")
# self.assertEquals(403, code, msg=str(response))
#
# # get message in created room not joined (no state), expect 403
# (code, response) = yield self.mock_resource.trigger_get(
# self.created_rmid_msg_path)
# self.assertEquals(403, code, msg=str(response))
#
# # get message in created room and invited, expect 403
# yield self.invite(room=self.created_rmid, src=self.rmcreator_id,
# targ=self.user_id)
# (code, response) = yield self.mock_resource.trigger_get(
# self.created_rmid_msg_path)
# self.assertEquals(403, code, msg=str(response))
#
# # get message in created room and joined, expect 200
# yield self.join(room=self.created_rmid, user=self.user_id)
# (code, response) = yield self.mock_resource.trigger_get(
# self.created_rmid_msg_path)
# self.assertEquals(200, code, msg=str(response))
#
# # get message in created room and left, expect 403
# yield self.leave(room=self.created_rmid, user=self.user_id)
# (code, response) = yield self.mock_resource.trigger_get(
# self.created_rmid_msg_path)
# self.assertEquals(403, code, msg=str(response))
@defer.inlineCallbacks
def test_send_message(self):
msg_content = '{"msgtype":"m.text","body":"hello"}'
@ -195,25 +167,30 @@ class RoomPermissionsTestCase(RestTestCase):
# set/get topic in uncreated room, expect 403
(code, response) = yield self.mock_resource.trigger(
"PUT", "/rooms/%s/state/m.room.topic" % self.uncreated_rmid,
topic_content)
"PUT", "/rooms/%s/state/m.room.topic" % self.uncreated_rmid,
topic_content
)
self.assertEquals(403, code, msg=str(response))
(code, response) = yield self.mock_resource.trigger_get(
"/rooms/%s/state/m.room.topic" % self.uncreated_rmid)
"/rooms/%s/state/m.room.topic" % self.uncreated_rmid
)
self.assertEquals(403, code, msg=str(response))
# set/get topic in created PRIVATE room not joined, expect 403
(code, response) = yield self.mock_resource.trigger(
"PUT", topic_path, topic_content)
"PUT", topic_path, topic_content
)
self.assertEquals(403, code, msg=str(response))
(code, response) = yield self.mock_resource.trigger_get(topic_path)
self.assertEquals(403, code, msg=str(response))
# set topic in created PRIVATE room and invited, expect 403
yield self.invite(room=self.created_rmid, src=self.rmcreator_id,
targ=self.user_id)
yield self.invite(
room=self.created_rmid, src=self.rmcreator_id, targ=self.user_id
)
(code, response) = yield self.mock_resource.trigger(
"PUT", topic_path, topic_content)
"PUT", topic_path, topic_content
)
self.assertEquals(403, code, msg=str(response))
# get topic in created PRIVATE room and invited, expect 403
@ -226,7 +203,8 @@ class RoomPermissionsTestCase(RestTestCase):
# Only room ops can set topic by default
self.auth_user_id = self.rmcreator_id
(code, response) = yield self.mock_resource.trigger(
"PUT", topic_path, topic_content)
"PUT", topic_path, topic_content
)
self.assertEquals(200, code, msg=str(response))
self.auth_user_id = self.user_id
@ -237,30 +215,31 @@ class RoomPermissionsTestCase(RestTestCase):
# set/get topic in created PRIVATE room and left, expect 403
yield self.leave(room=self.created_rmid, user=self.user_id)
(code, response) = yield self.mock_resource.trigger(
"PUT", topic_path, topic_content)
"PUT", topic_path, topic_content
)
self.assertEquals(403, code, msg=str(response))
(code, response) = yield self.mock_resource.trigger_get(topic_path)
self.assertEquals(200, code, msg=str(response))
# get topic in PUBLIC room, not joined, expect 403
(code, response) = yield self.mock_resource.trigger_get(
"/rooms/%s/state/m.room.topic" % self.created_public_rmid)
"/rooms/%s/state/m.room.topic" % self.created_public_rmid
)
self.assertEquals(403, code, msg=str(response))
# set topic in PUBLIC room, not joined, expect 403
(code, response) = yield self.mock_resource.trigger(
"PUT",
"/rooms/%s/state/m.room.topic" % self.created_public_rmid,
topic_content)
"PUT",
"/rooms/%s/state/m.room.topic" % self.created_public_rmid,
topic_content
)
self.assertEquals(403, code, msg=str(response))
@defer.inlineCallbacks
def _test_get_membership(self, room=None, members=[], expect_code=None):
path = "/rooms/%s/state/m.room.member/%s"
for member in members:
(code, response) = yield self.mock_resource.trigger_get(
path %
(room, member))
path = "/rooms/%s/state/m.room.member/%s" % (room, member)
(code, response) = yield self.mock_resource.trigger_get(path)
self.assertEquals(expect_code, code)
@defer.inlineCallbacks
@ -461,20 +440,23 @@ class RoomsMemberListTestCase(RestTestCase):
def test_get_member_list(self):
room_id = yield self.create_room_as(self.user_id)
(code, response) = yield self.mock_resource.trigger_get(
"/rooms/%s/members" % room_id)
"/rooms/%s/members" % room_id
)
self.assertEquals(200, code, msg=str(response))
@defer.inlineCallbacks
def test_get_member_list_no_room(self):
(code, response) = yield self.mock_resource.trigger_get(
"/rooms/roomdoesnotexist/members")
"/rooms/roomdoesnotexist/members"
)
self.assertEquals(403, code, msg=str(response))
@defer.inlineCallbacks
def test_get_member_list_no_permission(self):
room_id = yield self.create_room_as("@some_other_guy:red")
(code, response) = yield self.mock_resource.trigger_get(
"/rooms/%s/members" % room_id)
"/rooms/%s/members" % room_id
)
self.assertEquals(403, code, msg=str(response))
@defer.inlineCallbacks
@ -636,34 +618,41 @@ class RoomTopicTestCase(RestTestCase):
@defer.inlineCallbacks
def test_invalid_puts(self):
# missing keys or invalid json
(code, response) = yield self.mock_resource.trigger("PUT",
self.path, '{}')
(code, response) = yield self.mock_resource.trigger(
"PUT", self.path, '{}'
)
self.assertEquals(400, code, msg=str(response))
(code, response) = yield self.mock_resource.trigger("PUT",
self.path, '{"_name":"bob"}')
(code, response) = yield self.mock_resource.trigger(
"PUT", self.path, '{"_name":"bob"}'
)
self.assertEquals(400, code, msg=str(response))
(code, response) = yield self.mock_resource.trigger("PUT",
self.path, '{"nao')
(code, response) = yield self.mock_resource.trigger(
"PUT", self.path, '{"nao'
)
self.assertEquals(400, code, msg=str(response))
(code, response) = yield self.mock_resource.trigger("PUT",
self.path, '[{"_name":"bob"},{"_name":"jill"}]')
(code, response) = yield self.mock_resource.trigger(
"PUT", self.path, '[{"_name":"bob"},{"_name":"jill"}]'
)
self.assertEquals(400, code, msg=str(response))
(code, response) = yield self.mock_resource.trigger("PUT",
self.path, 'text only')
(code, response) = yield self.mock_resource.trigger(
"PUT", self.path, 'text only'
)
self.assertEquals(400, code, msg=str(response))
(code, response) = yield self.mock_resource.trigger("PUT",
self.path, '')
(code, response) = yield self.mock_resource.trigger(
"PUT", self.path, ''
)
self.assertEquals(400, code, msg=str(response))
# valid key, wrong type
content = '{"topic":["Topic name"]}'
(code, response) = yield self.mock_resource.trigger("PUT",
self.path, content)
(code, response) = yield self.mock_resource.trigger(
"PUT", self.path, content
)
self.assertEquals(400, code, msg=str(response))
@defer.inlineCallbacks
@ -674,8 +663,9 @@ class RoomTopicTestCase(RestTestCase):
# valid put
content = '{"topic":"Topic name"}'
(code, response) = yield self.mock_resource.trigger("PUT",
self.path, content)
(code, response) = yield self.mock_resource.trigger(
"PUT", self.path, content
)
self.assertEquals(200, code, msg=str(response))
# valid get
@ -687,8 +677,9 @@ class RoomTopicTestCase(RestTestCase):
def test_rooms_topic_with_extra_keys(self):
# valid put with extra keys
content = '{"topic":"Seasons","subtopic":"Summer"}'
(code, response) = yield self.mock_resource.trigger("PUT",
self.path, content)
(code, response) = yield self.mock_resource.trigger(
"PUT", self.path, content
)
self.assertEquals(200, code, msg=str(response))
# valid get
@ -740,33 +731,38 @@ class RoomMemberStateTestCase(RestTestCase):
def test_invalid_puts(self):
path = "/rooms/%s/state/m.room.member/%s" % (self.room_id, self.user_id)
# missing keys or invalid json
(code, response) = yield self.mock_resource.trigger("PUT",
path, '{}')
(code, response) = yield self.mock_resource.trigger("PUT", path, '{}')
self.assertEquals(400, code, msg=str(response))
(code, response) = yield self.mock_resource.trigger("PUT",
path, '{"_name":"bob"}')
(code, response) = yield self.mock_resource.trigger(
"PUT", path, '{"_name":"bob"}'
)
self.assertEquals(400, code, msg=str(response))
(code, response) = yield self.mock_resource.trigger("PUT",
path, '{"nao')
(code, response) = yield self.mock_resource.trigger(
"PUT", path, '{"nao'
)
self.assertEquals(400, code, msg=str(response))
(code, response) = yield self.mock_resource.trigger("PUT",
path, '[{"_name":"bob"},{"_name":"jill"}]')
(code, response) = yield self.mock_resource.trigger(
"PUT", path, '[{"_name":"bob"},{"_name":"jill"}]'
)
self.assertEquals(400, code, msg=str(response))
(code, response) = yield self.mock_resource.trigger("PUT",
path, 'text only')
(code, response) = yield self.mock_resource.trigger(
"PUT", path, 'text only'
)
self.assertEquals(400, code, msg=str(response))
(code, response) = yield self.mock_resource.trigger("PUT",
path, '')
(code, response) = yield self.mock_resource.trigger(
"PUT", path, ''
)
self.assertEquals(400, code, msg=str(response))
# valid keys, wrong types
content = ('{"membership":["%s","%s","%s"]}' %
(Membership.INVITE, Membership.JOIN, Membership.LEAVE))
content = ('{"membership":["%s","%s","%s"]}' % (
Membership.INVITE, Membership.JOIN, Membership.LEAVE
))
(code, response) = yield self.mock_resource.trigger("PUT", path, content)
self.assertEquals(400, code, msg=str(response))
@ -813,8 +809,9 @@ class RoomMemberStateTestCase(RestTestCase):
)
# valid invite message with custom key
content = ('{"membership":"%s","invite_text":"%s"}' %
(Membership.INVITE, "Join us!"))
content = ('{"membership":"%s","invite_text":"%s"}' % (
Membership.INVITE, "Join us!"
))
(code, response) = yield self.mock_resource.trigger("PUT", path, content)
self.assertEquals(200, code, msg=str(response))
@ -867,28 +864,34 @@ class RoomMessagesTestCase(RestTestCase):
path = "/rooms/%s/send/m.room.message/mid1" % (
urllib.quote(self.room_id))
# missing keys or invalid json
(code, response) = yield self.mock_resource.trigger("PUT",
path, '{}')
(code, response) = yield self.mock_resource.trigger(
"PUT", path, '{}'
)
self.assertEquals(400, code, msg=str(response))
(code, response) = yield self.mock_resource.trigger("PUT",
path, '{"_name":"bob"}')
(code, response) = yield self.mock_resource.trigger(
"PUT", path, '{"_name":"bob"}'
)
self.assertEquals(400, code, msg=str(response))
(code, response) = yield self.mock_resource.trigger("PUT",
path, '{"nao')
(code, response) = yield self.mock_resource.trigger(
"PUT", path, '{"nao'
)
self.assertEquals(400, code, msg=str(response))
(code, response) = yield self.mock_resource.trigger("PUT",
path, '[{"_name":"bob"},{"_name":"jill"}]')
(code, response) = yield self.mock_resource.trigger(
"PUT", path, '[{"_name":"bob"},{"_name":"jill"}]'
)
self.assertEquals(400, code, msg=str(response))
(code, response) = yield self.mock_resource.trigger("PUT",
path, 'text only')
(code, response) = yield self.mock_resource.trigger(
"PUT", path, 'text only'
)
self.assertEquals(400, code, msg=str(response))
(code, response) = yield self.mock_resource.trigger("PUT",
path, '')
(code, response) = yield self.mock_resource.trigger(
"PUT", path, ''
)
self.assertEquals(400, code, msg=str(response))
@defer.inlineCallbacks
@ -959,7 +962,8 @@ class RoomInitialSyncTestCase(RestTestCase):
@defer.inlineCallbacks
def test_initial_sync(self):
(code, response) = yield self.mock_resource.trigger_get(
"/rooms/%s/initialSync" % self.room_id)
"/rooms/%s/initialSync" % self.room_id
)
self.assertEquals(200, code)
self.assertEquals(self.room_id, response["room_id"])
@ -983,8 +987,8 @@ class RoomInitialSyncTestCase(RestTestCase):
self.assertTrue("presence" in response)
presence_by_user = {e["content"]["user_id"]: e
for e in response["presence"]
presence_by_user = {
e["content"]["user_id"]: e for e in response["presence"]
}
self.assertTrue(self.user_id in presence_by_user)
self.assertEquals("m.presence", presence_by_user[self.user_id]["type"])

View file

@ -81,9 +81,9 @@ class RoomTypingTestCase(RestTestCase):
return defer.succeed([])
@defer.inlineCallbacks
def fetch_room_distributions_into(room_id, localusers=None,
remotedomains=None, ignore_user=None):
def fetch_room_distributions_into(
room_id, localusers=None, remotedomains=None, ignore_user=None
):
members = yield get_room_members(room_id)
for member in members:
if ignore_user is not None and member == ignore_user:
@ -96,7 +96,8 @@ class RoomTypingTestCase(RestTestCase):
if remotedomains is not None:
remotedomains.add(member.domain)
hs.get_handlers().room_member_handler.fetch_room_distributions_into = (
fetch_room_distributions_into)
fetch_room_distributions_into
)
synapse.rest.client.v1.room.register_servlets(hs, self.mock_resource)
@ -109,8 +110,8 @@ class RoomTypingTestCase(RestTestCase):
@defer.inlineCallbacks
def test_set_typing(self):
(code, _) = yield self.mock_resource.trigger("PUT",
"/rooms/%s/typing/%s" % (self.room_id, self.user_id),
(code, _) = yield self.mock_resource.trigger(
"PUT", "/rooms/%s/typing/%s" % (self.room_id, self.user_id),
'{"typing": true, "timeout": 30000}'
)
self.assertEquals(200, code)
@ -120,41 +121,38 @@ class RoomTypingTestCase(RestTestCase):
from_key=0,
room_ids=[self.room_id],
)
self.assertEquals(
events[0],
[
{"type": "m.typing",
"room_id": self.room_id,
"content": {
"user_ids": [self.user_id],
}},
]
)
self.assertEquals(events[0], [{
"type": "m.typing",
"room_id": self.room_id,
"content": {
"user_ids": [self.user_id],
}
}])
@defer.inlineCallbacks
def test_set_not_typing(self):
(code, _) = yield self.mock_resource.trigger("PUT",
"/rooms/%s/typing/%s" % (self.room_id, self.user_id),
(code, _) = yield self.mock_resource.trigger(
"PUT", "/rooms/%s/typing/%s" % (self.room_id, self.user_id),
'{"typing": false}'
)
self.assertEquals(200, code)
@defer.inlineCallbacks
def test_typing_timeout(self):
(code, _) = yield self.mock_resource.trigger("PUT",
"/rooms/%s/typing/%s" % (self.room_id, self.user_id),
(code, _) = yield self.mock_resource.trigger(
"PUT", "/rooms/%s/typing/%s" % (self.room_id, self.user_id),
'{"typing": true, "timeout": 30000}'
)
self.assertEquals(200, code)
self.assertEquals(self.event_source.get_current_key(), 1)
self.clock.advance_time(31);
self.clock.advance_time(31)
self.assertEquals(self.event_source.get_current_key(), 2)
(code, _) = yield self.mock_resource.trigger("PUT",
"/rooms/%s/typing/%s" % (self.room_id, self.user_id),
(code, _) = yield self.mock_resource.trigger(
"PUT", "/rooms/%s/typing/%s" % (self.room_id, self.user_id),
'{"typing": true, "timeout": 30000}'
)
self.assertEquals(200, code)

View file

@ -84,8 +84,9 @@ class RestTestCase(unittest.TestCase):
"membership": membership
}
(code, response) = yield self.mock_resource.trigger("PUT", path,
json.dumps(data))
(code, response) = yield self.mock_resource.trigger(
"PUT", path, json.dumps(data)
)
self.assertEquals(expect_code, code, msg=str(response))
self.auth_user_id = temp_id

View file

@ -55,7 +55,7 @@ class V2AlphaRestTestCase(unittest.TestCase):
r.register_servlets(hs, self.mock_resource)
def make_datastore_mock(self):
store = Mock(spec=[
store = Mock(spec=[
"insert_client_ip",
])
store.get_app_service_by_token = Mock(return_value=None)

View file

@ -15,8 +15,6 @@
from twisted.internet import defer
from mock import Mock
from . import V2AlphaRestTestCase
from synapse.rest.client.v2_alpha import filter
@ -53,9 +51,8 @@ class FilterTestCase(V2AlphaRestTestCase):
@defer.inlineCallbacks
def test_add_filter(self):
(code, response) = yield self.mock_resource.trigger("POST",
"/user/%s/filter" % (self.USER_ID),
'{"type": ["m.*"]}'
(code, response) = yield self.mock_resource.trigger(
"POST", "/user/%s/filter" % (self.USER_ID), '{"type": ["m.*"]}'
)
self.assertEquals(200, code)
self.assertEquals({"filter_id": "0"}, response)
@ -70,8 +67,8 @@ class FilterTestCase(V2AlphaRestTestCase):
{"type": ["m.*"]}
]
(code, response) = yield self.mock_resource.trigger("GET",
"/user/%s/filter/0" % (self.USER_ID), None
(code, response) = yield self.mock_resource.trigger_get(
"/user/%s/filter/0" % (self.USER_ID)
)
self.assertEquals(200, code)
self.assertEquals({"type": ["m.*"]}, response)
@ -82,14 +79,14 @@ class FilterTestCase(V2AlphaRestTestCase):
{"type": ["m.*"]}
]
(code, response) = yield self.mock_resource.trigger("GET",
"/user/%s/filter/2" % (self.USER_ID), None
(code, response) = yield self.mock_resource.trigger_get(
"/user/%s/filter/2" % (self.USER_ID)
)
self.assertEquals(404, code)
@defer.inlineCallbacks
def test_get_filter_no_user(self):
(code, response) = yield self.mock_resource.trigger("GET",
"/user/%s/filter/0" % (self.USER_ID), None
(code, response) = yield self.mock_resource.trigger_get(
"/user/%s/filter/0" % (self.USER_ID)
)
self.assertEquals(404, code)

View file

@ -1,7 +1,7 @@
from synapse.rest.client.v2_alpha.register import RegisterRestServlet
from synapse.api.errors import SynapseError
from twisted.internet import defer
from mock import Mock, MagicMock
from mock import Mock
from tests import unittest
import json
@ -24,7 +24,7 @@ class RegisterRestServletTestCase(unittest.TestCase):
self.auth_result = (False, None, None)
self.auth_handler = Mock(
check_auth=Mock(side_effect=lambda x,y,z: self.auth_result)
check_auth=Mock(side_effect=lambda x, y, z: self.auth_result)
)
self.registration_handler = Mock()
self.identity_handler = Mock()

View file

@ -14,15 +14,9 @@
# limitations under the License.
from tests import unittest
from twisted.internet import defer
from synapse.api.constants import EventTypes, Membership
from synapse.types import UserID, RoomID
from tests.utils import setup_test_homeserver
from mock import Mock
from synapse.api.constants import EventTypes
class EventInjector:

View file

@ -174,11 +174,13 @@ class CacheDecoratorTestCase(unittest.TestCase):
# There must have been at least 2 evictions, meaning if we calculate
# all 12 values again, we must get called at least 2 more times
for k in range(0,12):
for k in range(0, 12):
yield a.func(k)
self.assertTrue(callcount[0] >= 14,
msg="Expected callcount >= 14, got %d" % (callcount[0]))
self.assertTrue(
callcount[0] >= 14,
msg="Expected callcount >= 14, got %d" % (callcount[0])
)
def test_prefill(self):
callcount = [0]

View file

@ -1,13 +1,11 @@
from tests import unittest
from twisted.internet import defer
from synapse.api.constants import EventTypes
from synapse.types import UserID, RoomID, RoomAlias
from tests.utils import setup_test_homeserver
from mock import Mock
class BackgroundUpdateTestCase(unittest.TestCase):
@defer.inlineCallbacks
@ -24,8 +22,8 @@ class BackgroundUpdateTestCase(unittest.TestCase):
@defer.inlineCallbacks
def test_do_background_update(self):
desired_count = 1000;
duration_ms = 42;
desired_count = 1000
duration_ms = 42
@defer.inlineCallbacks
def update(progress, count):

View file

@ -17,7 +17,7 @@
from tests import unittest
from twisted.internet import defer
from mock import Mock, call
from mock import Mock
from collections import OrderedDict
@ -62,13 +62,12 @@ class SQLBaseStoreTestCase(unittest.TestCase):
self.mock_txn.rowcount = 1
yield self.datastore._simple_insert(
table="tablename",
values={"columname": "Value"}
table="tablename",
values={"columname": "Value"}
)
self.mock_txn.execute.assert_called_with(
"INSERT INTO tablename (columname) VALUES(?)",
("Value",)
"INSERT INTO tablename (columname) VALUES(?)", ("Value",)
)
@defer.inlineCallbacks
@ -76,14 +75,14 @@ class SQLBaseStoreTestCase(unittest.TestCase):
self.mock_txn.rowcount = 1
yield self.datastore._simple_insert(
table="tablename",
# Use OrderedDict() so we can assert on the SQL generated
values=OrderedDict([("colA", 1), ("colB", 2), ("colC", 3)])
table="tablename",
# Use OrderedDict() so we can assert on the SQL generated
values=OrderedDict([("colA", 1), ("colB", 2), ("colC", 3)])
)
self.mock_txn.execute.assert_called_with(
"INSERT INTO tablename (colA, colB, colC) VALUES(?, ?, ?)",
(1, 2, 3,)
"INSERT INTO tablename (colA, colB, colC) VALUES(?, ?, ?)",
(1, 2, 3,)
)
@defer.inlineCallbacks
@ -92,15 +91,14 @@ class SQLBaseStoreTestCase(unittest.TestCase):
self.mock_txn.fetchall.return_value = [("Value",)]
value = yield self.datastore._simple_select_one_onecol(
table="tablename",
keyvalues={"keycol": "TheKey"},
retcol="retcol"
table="tablename",
keyvalues={"keycol": "TheKey"},
retcol="retcol"
)
self.assertEquals("Value", value)
self.mock_txn.execute.assert_called_with(
"SELECT retcol FROM tablename WHERE keycol = ?",
["TheKey"]
"SELECT retcol FROM tablename WHERE keycol = ?", ["TheKey"]
)
@defer.inlineCallbacks
@ -109,15 +107,15 @@ class SQLBaseStoreTestCase(unittest.TestCase):
self.mock_txn.fetchone.return_value = (1, 2, 3)
ret = yield self.datastore._simple_select_one(
table="tablename",
keyvalues={"keycol": "TheKey"},
retcols=["colA", "colB", "colC"]
table="tablename",
keyvalues={"keycol": "TheKey"},
retcols=["colA", "colB", "colC"]
)
self.assertEquals({"colA": 1, "colB": 2, "colC": 3}, ret)
self.mock_txn.execute.assert_called_with(
"SELECT colA, colB, colC FROM tablename WHERE keycol = ?",
["TheKey"]
"SELECT colA, colB, colC FROM tablename WHERE keycol = ?",
["TheKey"]
)
@defer.inlineCallbacks
@ -126,32 +124,32 @@ class SQLBaseStoreTestCase(unittest.TestCase):
self.mock_txn.fetchone.return_value = None
ret = yield self.datastore._simple_select_one(
table="tablename",
keyvalues={"keycol": "Not here"},
retcols=["colA"],
allow_none=True
table="tablename",
keyvalues={"keycol": "Not here"},
retcols=["colA"],
allow_none=True
)
self.assertFalse(ret)
@defer.inlineCallbacks
def test_select_list(self):
self.mock_txn.rowcount = 3;
self.mock_txn.rowcount = 3
self.mock_txn.fetchall.return_value = ((1,), (2,), (3,))
self.mock_txn.description = (
("colA", None, None, None, None, None, None),
("colA", None, None, None, None, None, None),
)
ret = yield self.datastore._simple_select_list(
table="tablename",
keyvalues={"keycol": "A set"},
retcols=["colA"],
table="tablename",
keyvalues={"keycol": "A set"},
retcols=["colA"],
)
self.assertEquals([{"colA": 1}, {"colA": 2}, {"colA": 3}], ret)
self.mock_txn.execute.assert_called_with(
"SELECT colA FROM tablename WHERE keycol = ?",
["A set"]
"SELECT colA FROM tablename WHERE keycol = ?",
["A set"]
)
@defer.inlineCallbacks
@ -159,14 +157,14 @@ class SQLBaseStoreTestCase(unittest.TestCase):
self.mock_txn.rowcount = 1
yield self.datastore._simple_update_one(
table="tablename",
keyvalues={"keycol": "TheKey"},
updatevalues={"columnname": "New Value"}
table="tablename",
keyvalues={"keycol": "TheKey"},
updatevalues={"columnname": "New Value"}
)
self.mock_txn.execute.assert_called_with(
"UPDATE tablename SET columnname = ? WHERE keycol = ?",
["New Value", "TheKey"]
"UPDATE tablename SET columnname = ? WHERE keycol = ?",
["New Value", "TheKey"]
)
@defer.inlineCallbacks
@ -174,15 +172,15 @@ class SQLBaseStoreTestCase(unittest.TestCase):
self.mock_txn.rowcount = 1
yield self.datastore._simple_update_one(
table="tablename",
keyvalues=OrderedDict([("colA", 1), ("colB", 2)]),
updatevalues=OrderedDict([("colC", 3), ("colD", 4)])
table="tablename",
keyvalues=OrderedDict([("colA", 1), ("colB", 2)]),
updatevalues=OrderedDict([("colC", 3), ("colD", 4)])
)
self.mock_txn.execute.assert_called_with(
"UPDATE tablename SET colC = ?, colD = ? WHERE " +
"colA = ? AND colB = ?",
[3, 4, 1, 2]
"UPDATE tablename SET colC = ?, colD = ? WHERE"
" colA = ? AND colB = ?",
[3, 4, 1, 2]
)
@defer.inlineCallbacks
@ -190,11 +188,10 @@ class SQLBaseStoreTestCase(unittest.TestCase):
self.mock_txn.rowcount = 1
yield self.datastore._simple_delete_one(
table="tablename",
keyvalues={"keycol": "Go away"},
table="tablename",
keyvalues={"keycol": "Go away"},
)
self.mock_txn.execute.assert_called_with(
"DELETE FROM tablename WHERE keycol = ?",
["Go away"]
"DELETE FROM tablename WHERE keycol = ?", ["Go away"]
)

View file

@ -12,7 +12,6 @@
# 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.
import uuid
from mock import Mock
from synapse.types import RoomID, UserID

View file

@ -55,7 +55,7 @@ class ProfileStoreTestCase(unittest.TestCase):
)
yield self.store.set_profile_avatar_url(
self.u_frank.localpart, "http://my.site/here"
self.u_frank.localpart, "http://my.site/here"
)
self.assertEquals(

View file

@ -33,8 +33,10 @@ class RegistrationStoreTestCase(unittest.TestCase):
self.store = hs.get_datastore()
self.user_id = "@my-user:test"
self.tokens = ["AbCdEfGhIjKlMnOpQrStUvWxYz",
"BcDeFgHiJkLmNoPqRsTuVwXyZa"]
self.tokens = [
"AbCdEfGhIjKlMnOpQrStUvWxYz",
"BcDeFgHiJkLmNoPqRsTuVwXyZa"
]
self.pwhash = "{xx1}123456789"
@defer.inlineCallbacks

View file

@ -37,7 +37,8 @@ class RoomStoreTestCase(unittest.TestCase):
self.alias = RoomAlias.from_string("#a-room-name:test")
self.u_creator = UserID.from_string("@creator:test")
yield self.store.store_room(self.room.to_string(),
yield self.store.store_room(
self.room.to_string(),
room_creator_user_id=self.u_creator.to_string(),
is_public=True
)
@ -45,9 +46,11 @@ class RoomStoreTestCase(unittest.TestCase):
@defer.inlineCallbacks
def test_get_room(self):
self.assertDictContainsSubset(
{"room_id": self.room.to_string(),
"creator": self.u_creator.to_string(),
"is_public": True},
{
"room_id": self.room.to_string(),
"creator": self.u_creator.to_string(),
"is_public": True
},
(yield self.store.get_room(self.room.to_string()))
)
@ -65,7 +68,8 @@ class RoomEventsStoreTestCase(unittest.TestCase):
self.room = RoomID.from_string("!abcde:test")
yield self.store.store_room(self.room.to_string(),
yield self.store.store_room(
self.room.to_string(),
room_creator_user_id="@creator:text",
is_public=True
)

View file

@ -88,8 +88,8 @@ class RoomMemberStoreTestCase(unittest.TestCase):
[m.room_id for m in (
yield self.store.get_rooms_for_user_where_membership_is(
self.u_alice.to_string(), [Membership.JOIN]
))
]
)
)]
)
self.assertFalse(
(yield self.store.user_rooms_intersect(
@ -108,11 +108,11 @@ class RoomMemberStoreTestCase(unittest.TestCase):
yield self.store.get_room_members(self.room.to_string())
)}
)
self.assertTrue(
(yield self.store.user_rooms_intersect(
[self.u_alice.to_string(), self.u_bob.to_string()]
))
)
self.assertTrue((
yield self.store.user_rooms_intersect([
self.u_alice.to_string(), self.u_bob.to_string()
])
))
@defer.inlineCallbacks
def test_room_hosts(self):
@ -136,9 +136,7 @@ class RoomMemberStoreTestCase(unittest.TestCase):
self.assertEquals(
{"test", "elsewhere"},
(yield
self.store.get_joined_hosts_for_room(self.room.to_string())
)
(yield self.store.get_joined_hosts_for_room(self.room.to_string()))
)
# Should still have both hosts
@ -146,9 +144,7 @@ class RoomMemberStoreTestCase(unittest.TestCase):
self.assertEquals(
{"test", "elsewhere"},
(yield
self.store.get_joined_hosts_for_room(self.room.to_string())
)
(yield self.store.get_joined_hosts_for_room(self.room.to_string()))
)
# Should have only one host after other leaves

View file

@ -156,13 +156,13 @@ class StreamStoreTestCase(unittest.TestCase):
self.room1, self.u_bob, Membership.JOIN
)
event1 = yield self.event_injector.inject_room_member(
yield self.event_injector.inject_room_member(
self.room1, self.u_alice, Membership.JOIN
)
start = yield self.store.get_room_events_max_id()
event2 = yield self.event_injector.inject_room_member(
yield self.event_injector.inject_room_member(
self.room1, self.u_alice, Membership.JOIN,
)

View file

@ -44,8 +44,10 @@ class DistributorTestCase(unittest.TestCase):
self.dist.declare("whine")
d_inner = defer.Deferred()
def observer():
return d_inner
self.dist.observe("whine", observer)
d_outer = self.dist.fire("whine")
@ -66,8 +68,8 @@ class DistributorTestCase(unittest.TestCase):
observers[0].side_effect = Exception("Awoogah!")
with patch("synapse.util.distributor.logger",
spec=["warning"]
with patch(
"synapse.util.distributor.logger", spec=["warning"]
) as mock_logger:
d = self.dist.fire("alarm", "Go")
yield d
@ -77,8 +79,9 @@ class DistributorTestCase(unittest.TestCase):
observers[1].assert_called_once_with("Go")
self.assertEquals(mock_logger.warning.call_count, 1)
self.assertIsInstance(mock_logger.warning.call_args[0][0],
str)
self.assertIsInstance(
mock_logger.warning.call_args[0][0], str
)
@defer.inlineCallbacks
def test_signal_catch_no_suppress(self):

View file

@ -17,6 +17,7 @@ from tests import unittest
from tests.utils import MockClock
class MockClockTestCase(unittest.TestCase):
def setUp(self):
@ -60,7 +61,7 @@ class MockClockTestCase(unittest.TestCase):
def _cb1():
invoked[1] = 1
t1 = self.clock.call_later(20, _cb1)
self.clock.call_later(20, _cb1)
self.clock.cancel_call_later(t0)

View file

@ -37,9 +37,12 @@ def around(target):
def _around(code):
name = code.__name__
orig = getattr(target, name)
def new(*args, **kwargs):
return code(orig, *args, **kwargs)
setattr(target, name, new)
return _around
@ -53,9 +56,7 @@ class TestCase(unittest.TestCase):
method = getattr(self, methodName)
level = getattr(method, "loglevel",
getattr(self, "loglevel",
NEVER))
level = getattr(method, "loglevel", getattr(self, "loglevel", NEVER))
@around(self)
def setUp(orig):

View file

@ -12,4 +12,3 @@
# 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.

View file

@ -14,7 +14,6 @@
# limitations under the License.
from twisted.internet import defer
from tests import unittest
from synapse.util.caches.dictionary_cache import DictionaryCache

View file

@ -19,6 +19,7 @@ from .. import unittest
from synapse.util.caches.snapshot_cache import SnapshotCache
from twisted.internet.defer import Deferred
class SnapshotCacheTestCase(unittest.TestCase):
def setUp(self):

View file

@ -18,6 +18,7 @@ from .. import unittest
from synapse.util.caches.treecache import TreeCache
class TreeCacheTestCase(unittest.TestCase):
def test_get_set_onelevel(self):
cache = TreeCache()

View file

@ -152,7 +152,7 @@ class MockHttpResource(HttpServer):
mock_request.getClientIP.return_value = "-"
mock_request.requestHeaders.getRawHeaders.return_value=[
mock_request.requestHeaders.getRawHeaders.return_value = [
"X-Matrix origin=test,key=,sig="
]
@ -360,13 +360,12 @@ class MemoryDataStore(object):
def get_rooms_for_user_where_membership_is(self, user_id, membership_list):
return [
self.members[r].get(user_id) for r in self.members
if user_id in self.members[r] and
self.members[r][user_id].membership in membership_list
m[user_id] for m in self.members.values()
if user_id in m and m[user_id].membership in membership_list
]
def get_room_events_stream(self, user_id=None, from_key=None, to_key=None,
limit=0, with_feedback=False):
limit=0, with_feedback=False):
return ([], from_key) # TODO
def get_joined_hosts_for_room(self, room_id):
@ -376,7 +375,6 @@ class MemoryDataStore(object):
if event.type == EventTypes.Member:
room_id = event.room_id
user = event.state_key
membership = event.membership
self.members.setdefault(room_id, {})[user] = event
if hasattr(event, "state_key"):
@ -456,9 +454,9 @@ class DeferredMockCallable(object):
d.callback(None)
return result
failure = AssertionError("Was not expecting call(%s)" %
failure = AssertionError("Was not expecting call(%s)" % (
_format_call(args, kwargs)
)
))
for _, _, d in self.expectations:
try:
@ -479,14 +477,12 @@ class DeferredMockCallable(object):
)
timer = reactor.callLater(
timeout/1000,
timeout / 1000,
deferred.errback,
AssertionError(
"%d pending calls left: %s"% (
len([e for e in self.expectations if not e[2].called]),
[e for e in self.expectations if not e[2].called]
)
)
AssertionError("%d pending calls left: %s" % (
len([e for e in self.expectations if not e[2].called]),
[e for e in self.expectations if not e[2].called]
))
)
yield deferred
@ -500,8 +496,8 @@ class DeferredMockCallable(object):
calls = self.calls
self.calls = []
raise AssertionError("Expected not to received any calls, got:\n" +
"\n".join([
raise AssertionError(
"Expected not to received any calls, got:\n" + "\n".join([
"call(%s)" % _format_call(c[0], c[1]) for c in calls
])
)

View file

@ -26,4 +26,4 @@ skip_install = True
basepython = python2.7
deps =
flake8
commands = /bin/bash -c "flake8 synapse {env:PEP8SUFFIX:}"
commands = /bin/bash -c "flake8 synapse tests {env:PEP8SUFFIX:}"