summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorDavid Baker <dave@matrix.org>2015-01-22 17:46:16 +0000
committerDavid Baker <dave@matrix.org>2015-01-22 17:46:16 +0000
commit5c6189ea3eb36409c57cd269a8931dda8f30e6ec (patch)
tree6a6217c76e23359e2edcebd1020b4807f18b3073 /tests
parentOops: second part of commit dc938606 (diff)
parentMerge pull request #30 from matrix-org/client_api_restructure (diff)
downloadsynapse-5c6189ea3eb36409c57cd269a8931dda8f30e6ec.tar.xz
Merge branch 'develop' into pushers
Conflicts:
	synapse/rest/__init__.py
Diffstat (limited to 'tests')
-rw-r--r--tests/handlers/test_presence.py97
-rw-r--r--tests/handlers/test_room.py4
-rw-r--r--tests/rest/__init__.py3
-rw-r--r--tests/rest/client/__init__.py14
-rw-r--r--tests/rest/client/v1/__init__.py15
-rw-r--r--tests/rest/client/v1/test_events.py (renamed from tests/rest/test_events.py)14
-rw-r--r--tests/rest/client/v1/test_presence.py (renamed from tests/rest/test_presence.py)2
-rw-r--r--tests/rest/client/v1/test_profile.py (renamed from tests/rest/test_profile.py)2
-rw-r--r--tests/rest/client/v1/test_rooms.py (renamed from tests/rest/test_rooms.py)18
-rw-r--r--tests/rest/client/v1/test_typing.py (renamed from tests/rest/test_typing.py)6
-rw-r--r--tests/rest/client/v1/utils.py (renamed from tests/rest/utils.py)0
-rw-r--r--tests/storage/TESTS_NEEDED_FOR5
-rw-r--r--tests/storage/test_room.py11
-rw-r--r--tests/utils.py20
14 files changed, 104 insertions, 107 deletions
diff --git a/tests/handlers/test_presence.py b/tests/handlers/test_presence.py
index b85a89052a..c309fbb054 100644
--- a/tests/handlers/test_presence.py
+++ b/tests/handlers/test_presence.py
@@ -59,23 +59,29 @@ class JustPresenceHandlers(object):
     def __init__(self, hs):
         self.presence_handler = PresenceHandler(hs)
 
-class PresenceStateTestCase(unittest.TestCase):
-    """ Tests presence management. """
 
+class PresenceTestCase(unittest.TestCase):
     @defer.inlineCallbacks
     def setUp(self):
         db_pool = SQLiteMemoryDbPool()
         yield db_pool.prepare()
 
+        self.clock = MockClock()
+
         self.mock_config = NonCallableMock()
         self.mock_config.signing_key = [MockKey()]
 
+        self.mock_federation_resource = MockHttpResource()
+
+        self.mock_http_client = Mock(spec=[])
+        self.mock_http_client.put_json = DeferredMockCallable()
+
         hs = HomeServer("test",
-            clock=MockClock(),
+            clock=self.clock,
             db_pool=db_pool,
             handlers=None,
-            resource_for_federation=Mock(),
-            http_client=None,
+            resource_for_federation=self.mock_federation_resource,
+            http_client=self.mock_http_client,
             config=self.mock_config,
             keyring=Mock(),
         )
@@ -92,24 +98,33 @@ class PresenceStateTestCase(unittest.TestCase):
         self.u_banana = hs.parse_userid("@banana:test")
         self.u_clementine = hs.parse_userid("@clementine:test")
 
-        yield self.store.create_presence(self.u_apple.localpart)
+        for u in self.u_apple, self.u_banana, self.u_clementine:
+            yield self.store.create_presence(u.localpart)
+
         yield self.store.set_presence_state(
             self.u_apple.localpart, {"state": ONLINE, "status_msg": "Online"}
         )
 
+        # ID of a local user that does not exist
+        self.u_durian = hs.parse_userid("@durian:test")
+
+        # A remote user
+        self.u_cabbage = hs.parse_userid("@cabbage:elsewhere")
+
         self.handler = hs.get_handlers().presence_handler
 
+        self.room_id = "a-room"
         self.room_members = []
 
         def get_rooms_for_user(user):
             if user in self.room_members:
-                return defer.succeed(["a-room"])
+                return defer.succeed([self.room_id])
             else:
                 return defer.succeed([])
         room_member_handler.get_rooms_for_user = get_rooms_for_user
 
         def get_room_members(room_id):
-            if room_id == "a-room":
+            if room_id == self.room_id:
                 return defer.succeed(self.room_members)
             else:
                 return defer.succeed([])
@@ -128,6 +143,10 @@ class PresenceStateTestCase(unittest.TestCase):
         self.handler.start_polling_presence = self.mock_start
         self.handler.stop_polling_presence = self.mock_stop
 
+
+class PresenceStateTestCase(PresenceTestCase):
+    """ Tests presence management. """
+
     @defer.inlineCallbacks
     def test_get_my_state(self):
         state = yield self.handler.get_state(
@@ -206,57 +225,10 @@ class PresenceStateTestCase(unittest.TestCase):
         self.mock_stop.assert_called_with(self.u_apple)
 
 
-class PresenceInvitesTestCase(unittest.TestCase):
+class PresenceInvitesTestCase(PresenceTestCase):
     """ Tests presence management. """
 
     @defer.inlineCallbacks
-    def setUp(self):
-        self.mock_http_client = Mock(spec=[])
-        self.mock_http_client.put_json = DeferredMockCallable()
-
-        self.mock_federation_resource = MockHttpResource()
-
-        db_pool = SQLiteMemoryDbPool()
-        yield db_pool.prepare()
-
-        self.mock_config = NonCallableMock()
-        self.mock_config.signing_key = [MockKey()]
-
-        hs = HomeServer("test",
-            clock=MockClock(),
-            db_pool=db_pool,
-            handlers=None,
-            resource_for_client=Mock(),
-            resource_for_federation=self.mock_federation_resource,
-            http_client=self.mock_http_client,
-            config=self.mock_config,
-            keyring=Mock(),
-        )
-        hs.handlers = JustPresenceHandlers(hs)
-
-        self.store = hs.get_datastore()
-
-        # Some local users to test with
-        self.u_apple = hs.parse_userid("@apple:test")
-        self.u_banana = hs.parse_userid("@banana:test")
-        yield self.store.create_presence(self.u_apple.localpart)
-        yield self.store.create_presence(self.u_banana.localpart)
-
-        # ID of a local user that does not exist
-        self.u_durian = hs.parse_userid("@durian:test")
-
-        # A remote user
-        self.u_cabbage = hs.parse_userid("@cabbage:elsewhere")
-
-        self.handler = hs.get_handlers().presence_handler
-
-        self.mock_start = Mock()
-        self.mock_stop = Mock()
-
-        self.handler.start_polling_presence = self.mock_start
-        self.handler.stop_polling_presence = self.mock_stop
-
-    @defer.inlineCallbacks
     def test_invite_local(self):
         # TODO(paul): This test will likely break if/when real auth permissions
         # are added; for now the HS will always accept any invite
@@ -558,24 +530,25 @@ class PresencePushTestCase(unittest.TestCase):
         ])
         self.room_member_handler = hs.handlers.room_member_handler
 
+        self.room_id = "a-room"
         self.room_members = []
 
         def get_rooms_for_user(user):
             if user in self.room_members:
-                return defer.succeed(["a-room"])
+                return defer.succeed([self.room_id])
             else:
                 return defer.succeed([])
         self.room_member_handler.get_rooms_for_user = get_rooms_for_user
 
         def get_room_members(room_id):
-            if room_id == "a-room":
+            if room_id == self.room_id:
                 return defer.succeed(self.room_members)
             else:
                 return defer.succeed([])
         self.room_member_handler.get_room_members = get_room_members
 
         def get_room_hosts(room_id):
-            if room_id == "a-room":
+            if room_id == self.room_id:
                 hosts = set([u.domain for u in self.room_members])
                 return defer.succeed(hosts)
             else:
@@ -911,7 +884,7 @@ class PresencePushTestCase(unittest.TestCase):
         )
 
         yield self.distributor.fire("user_joined_room", self.u_clementine,
-            "a-room"
+            self.room_id
         )
 
         self.room_members.append(self.u_clementine)
@@ -974,7 +947,7 @@ class PresencePushTestCase(unittest.TestCase):
         self.room_members = [self.u_apple, self.u_banana]
 
         yield self.distributor.fire("user_joined_room", self.u_potato,
-            "a-room"
+            self.room_id
         )
 
         yield put_json.await_calls()
@@ -1003,7 +976,7 @@ class PresencePushTestCase(unittest.TestCase):
         self.room_members.append(self.u_potato)
 
         yield self.distributor.fire("user_joined_room", self.u_clementine,
-            "a-room"
+            self.room_id
         )
 
         put_json.await_calls()
diff --git a/tests/handlers/test_room.py b/tests/handlers/test_room.py
index 0cb8aa4fbc..d3253b48b8 100644
--- a/tests/handlers/test_room.py
+++ b/tests/handlers/test_room.py
@@ -223,7 +223,7 @@ class RoomMemberHandlerTestCase(unittest.TestCase):
         yield room_handler.change_membership(event, context)
 
         self.federation.handle_new_event.assert_called_once_with(
-            event, None, destinations=set()
+            event, destinations=set()
         )
 
         self.datastore.persist_event.assert_called_once_with(
@@ -301,7 +301,7 @@ class RoomMemberHandlerTestCase(unittest.TestCase):
         yield room_handler.change_membership(event, context)
 
         self.federation.handle_new_event.assert_called_once_with(
-            event, None, destinations=set(['red'])
+            event, destinations=set(['red'])
         )
 
         self.datastore.persist_event.assert_called_once_with(
diff --git a/tests/rest/__init__.py b/tests/rest/__init__.py
index 9bff9ec169..1a84d94cd9 100644
--- a/tests/rest/__init__.py
+++ b/tests/rest/__init__.py
@@ -1,5 +1,5 @@
 # -*- coding: utf-8 -*-
-# Copyright 2014 OpenMarket Ltd
+# Copyright 2015 OpenMarket Ltd
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -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.
-
diff --git a/tests/rest/client/__init__.py b/tests/rest/client/__init__.py
new file mode 100644
index 0000000000..1a84d94cd9
--- /dev/null
+++ b/tests/rest/client/__init__.py
@@ -0,0 +1,14 @@
+# -*- coding: utf-8 -*-
+# Copyright 2015 OpenMarket Ltd
+#
+# 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.
diff --git a/tests/rest/client/v1/__init__.py b/tests/rest/client/v1/__init__.py
new file mode 100644
index 0000000000..9bff9ec169
--- /dev/null
+++ b/tests/rest/client/v1/__init__.py
@@ -0,0 +1,15 @@
+# -*- coding: utf-8 -*-
+# Copyright 2014 OpenMarket Ltd
+#
+# 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.
+
diff --git a/tests/rest/test_events.py b/tests/rest/client/v1/test_events.py
index d3159e2cf4..0384ffbb3d 100644
--- a/tests/rest/test_events.py
+++ b/tests/rest/client/v1/test_events.py
@@ -19,13 +19,13 @@ from tests import unittest
 # twisted imports
 from twisted.internet import defer
 
-import synapse.rest.events
-import synapse.rest.register
-import synapse.rest.room
+import synapse.rest.client.v1.events
+import synapse.rest.client.v1.register
+import synapse.rest.client.v1.room
 
 from synapse.server import HomeServer
 
-from ..utils import MockHttpResource, SQLiteMemoryDbPool, MockKey
+from ....utils import MockHttpResource, SQLiteMemoryDbPool, MockKey
 from .utils import RestTestCase
 
 from mock import Mock, NonCallableMock
@@ -144,9 +144,9 @@ class EventStreamPermissionsTestCase(RestTestCase):
         hs.get_clock().time_msec.return_value = 1000000
         hs.get_clock().time.return_value = 1000
 
-        synapse.rest.register.register_servlets(hs, self.mock_resource)
-        synapse.rest.events.register_servlets(hs, self.mock_resource)
-        synapse.rest.room.register_servlets(hs, self.mock_resource)
+        synapse.rest.client.v1.register.register_servlets(hs, self.mock_resource)
+        synapse.rest.client.v1.events.register_servlets(hs, self.mock_resource)
+        synapse.rest.client.v1.room.register_servlets(hs, self.mock_resource)
 
         # register an account
         self.user_id = "sid1"
diff --git a/tests/rest/test_presence.py b/tests/rest/client/v1/test_presence.py
index 769c7824bc..0b6f7cfccb 100644
--- a/tests/rest/test_presence.py
+++ b/tests/rest/client/v1/test_presence.py
@@ -20,7 +20,7 @@ from twisted.internet import defer
 
 from mock import Mock
 
-from ..utils import MockHttpResource, MockKey
+from ....utils import MockHttpResource, MockKey
 
 from synapse.api.constants import PresenceState
 from synapse.handlers.presence import PresenceHandler
diff --git a/tests/rest/test_profile.py b/tests/rest/client/v1/test_profile.py
index 3a0d1e700a..47cfb10a6d 100644
--- a/tests/rest/test_profile.py
+++ b/tests/rest/client/v1/test_profile.py
@@ -20,7 +20,7 @@ from twisted.internet import defer
 
 from mock import Mock, NonCallableMock
 
-from ..utils import MockHttpResource, MockKey
+from ....utils import MockHttpResource, MockKey
 
 from synapse.api.errors import SynapseError, AuthError
 from synapse.server import HomeServer
diff --git a/tests/rest/test_rooms.py b/tests/rest/client/v1/test_rooms.py
index 8e65ff9a1c..12f8040541 100644
--- a/tests/rest/test_rooms.py
+++ b/tests/rest/client/v1/test_rooms.py
@@ -18,7 +18,7 @@
 # twisted imports
 from twisted.internet import defer
 
-import synapse.rest.room
+import synapse.rest.client.v1.room
 from synapse.api.constants import Membership
 
 from synapse.server import HomeServer
@@ -30,7 +30,7 @@ import json
 import urllib
 import types
 
-from ..utils import MockHttpResource, SQLiteMemoryDbPool, MockKey
+from ....utils import MockHttpResource, SQLiteMemoryDbPool, MockKey
 from .utils import RestTestCase
 
 from mock import Mock, NonCallableMock
@@ -82,7 +82,7 @@ class RoomPermissionsTestCase(RestTestCase):
 
         self.auth_user_id = self.rmcreator_id
 
-        synapse.rest.room.register_servlets(hs, self.mock_resource)
+        synapse.rest.client.v1.room.register_servlets(hs, self.mock_resource)
 
         self.auth = hs.get_auth()
 
@@ -476,7 +476,7 @@ class RoomsMemberListTestCase(RestTestCase):
             return defer.succeed(None)
         hs.get_datastore().insert_client_ip = _insert_client_ip
 
-        synapse.rest.room.register_servlets(hs, self.mock_resource)
+        synapse.rest.client.v1.room.register_servlets(hs, self.mock_resource)
 
     def tearDown(self):
         pass
@@ -565,7 +565,7 @@ class RoomsCreateTestCase(RestTestCase):
             return defer.succeed(None)
         hs.get_datastore().insert_client_ip = _insert_client_ip
 
-        synapse.rest.room.register_servlets(hs, self.mock_resource)
+        synapse.rest.client.v1.room.register_servlets(hs, self.mock_resource)
 
     def tearDown(self):
         pass
@@ -668,7 +668,7 @@ class RoomTopicTestCase(RestTestCase):
             return defer.succeed(None)
         hs.get_datastore().insert_client_ip = _insert_client_ip
 
-        synapse.rest.room.register_servlets(hs, self.mock_resource)
+        synapse.rest.client.v1.room.register_servlets(hs, self.mock_resource)
 
         # create the room
         self.room_id = yield self.create_room_as(self.user_id)
@@ -783,7 +783,7 @@ class RoomMemberStateTestCase(RestTestCase):
             return defer.succeed(None)
         hs.get_datastore().insert_client_ip = _insert_client_ip
 
-        synapse.rest.room.register_servlets(hs, self.mock_resource)
+        synapse.rest.client.v1.room.register_servlets(hs, self.mock_resource)
 
         self.room_id = yield self.create_room_as(self.user_id)
 
@@ -919,7 +919,7 @@ class RoomMessagesTestCase(RestTestCase):
             return defer.succeed(None)
         hs.get_datastore().insert_client_ip = _insert_client_ip
 
-        synapse.rest.room.register_servlets(hs, self.mock_resource)
+        synapse.rest.client.v1.room.register_servlets(hs, self.mock_resource)
 
         self.room_id = yield self.create_room_as(self.user_id)
 
@@ -1023,7 +1023,7 @@ class RoomInitialSyncTestCase(RestTestCase):
             return defer.succeed(None)
         hs.get_datastore().insert_client_ip = _insert_client_ip
 
-        synapse.rest.room.register_servlets(hs, self.mock_resource)
+        synapse.rest.client.v1.room.register_servlets(hs, self.mock_resource)
 
         # Since I'm getting my own presence I need to exist as far as presence
         # is concerned.
diff --git a/tests/rest/test_typing.py b/tests/rest/client/v1/test_typing.py
index 18138af1b5..647bcebfd8 100644
--- a/tests/rest/test_typing.py
+++ b/tests/rest/client/v1/test_typing.py
@@ -18,10 +18,10 @@
 # twisted imports
 from twisted.internet import defer
 
-import synapse.rest.room
+import synapse.rest.client.v1.room
 from synapse.server import HomeServer
 
-from ..utils import MockHttpResource, MockClock, SQLiteMemoryDbPool, MockKey
+from ....utils import MockHttpResource, MockClock, SQLiteMemoryDbPool, MockKey
 from .utils import RestTestCase
 
 from mock import Mock, NonCallableMock
@@ -104,7 +104,7 @@ class RoomTypingTestCase(RestTestCase):
         hs.get_handlers().room_member_handler.fetch_room_distributions_into = (
                 fetch_room_distributions_into)
 
-        synapse.rest.room.register_servlets(hs, self.mock_resource)
+        synapse.rest.client.v1.room.register_servlets(hs, self.mock_resource)
 
         self.room_id = yield self.create_room_as(self.user_id)
         # Need another user to make notifications actually work
diff --git a/tests/rest/utils.py b/tests/rest/client/v1/utils.py
index 579441fb4a..579441fb4a 100644
--- a/tests/rest/utils.py
+++ b/tests/rest/client/v1/utils.py
diff --git a/tests/storage/TESTS_NEEDED_FOR b/tests/storage/TESTS_NEEDED_FOR
deleted file mode 100644
index 8e5d0cbdc4..0000000000
--- a/tests/storage/TESTS_NEEDED_FOR
+++ /dev/null
@@ -1,5 +0,0 @@
-synapse/storage/feedback.py
-synapse/storage/keys.py
-synapse/storage/pdu.py
-synapse/storage/stream.py
-synapse/storage/transactions.py
diff --git a/tests/storage/test_room.py b/tests/storage/test_room.py
index 11761fe29a..e7739776ec 100644
--- a/tests/storage/test_room.py
+++ b/tests/storage/test_room.py
@@ -57,17 +57,6 @@ class RoomStoreTestCase(unittest.TestCase):
         )
 
     @defer.inlineCallbacks
-    def test_store_room_config(self):
-        yield self.store.store_room_config(self.room.to_string(),
-            visibility=False
-        )
-
-        self.assertObjectHasAttributes(
-            {"is_public": False},
-            (yield self.store.get_room(self.room.to_string()))
-        )
-
-    @defer.inlineCallbacks
     def test_get_rooms(self):
         # get_rooms does an INNER JOIN on the room_aliases table :(
 
diff --git a/tests/utils.py b/tests/utils.py
index 731e03f517..97fa8d8181 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -138,7 +138,8 @@ class MockClock(object):
     now = 1000
 
     def __init__(self):
-        # list of tuples of (absolute_time, callback) in no particular order
+        # list of lists of [absolute_time, callback, expired] in no particular
+        # order
         self.timers = []
 
     def time(self):
@@ -154,11 +155,16 @@ class MockClock(object):
             LoggingContext.thread_local.current_context = current_context
             callback()
 
-        t = (self.now + delay, wrapped_callback)
+        t = [self.now + delay, wrapped_callback, False]
         self.timers.append(t)
+
         return t
 
     def cancel_call_later(self, timer):
+        if timer[2]:
+            raise Exception("Cannot cancel an expired timer")
+
+        timer[2] = True
         self.timers = [t for t in self.timers if t != timer]
 
     # For unit testing
@@ -168,11 +174,17 @@ class MockClock(object):
         timers = self.timers
         self.timers = []
 
-        for time, callback in timers:
+        for t in timers:
+            time, callback, expired = t
+
+            if expired:
+                raise Exception("Timer already expired")
+
             if self.now >= time:
+                t[2] = True
                 callback()
             else:
-                self.timers.append((time, callback))
+                self.timers.append(t)
 
 
 class SQLiteMemoryDbPool(ConnectionPool, object):