summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorDavid Baker <dave@matrix.org>2015-01-13 13:15:51 +0000
committerDavid Baker <dave@matrix.org>2015-01-13 13:15:51 +0000
commitc06a9063e1d838f776edfd79cfc8ab29c748d794 (patch)
treebcfa472e65d4dacbab666d5787eff9293e5ccc41 /tests
parentSplit out function to decide whether to notify or a given event (diff)
parentMerge branch 'hotfixes-v0.6.1b' of github.com:matrix-org/synapse into develop (diff)
downloadsynapse-c06a9063e1d838f776edfd79cfc8ab29c748d794.tar.xz
Merge branch 'develop' into pushers
Diffstat (limited to 'tests')
-rw-r--r--tests/federation/test_federation.py2
-rw-r--r--tests/handlers/test_presencelike.py11
-rw-r--r--tests/handlers/test_profile.py9
-rw-r--r--tests/handlers/test_typing.py26
-rw-r--r--tests/rest/test_rooms.py2
-rw-r--r--tests/rest/test_typing.py51
-rw-r--r--tests/test_distributor.py27
-rw-r--r--tests/unittest.py2
8 files changed, 116 insertions, 14 deletions
diff --git a/tests/federation/test_federation.py b/tests/federation/test_federation.py
index 79ac1ce10d..3e484cd303 100644
--- a/tests/federation/test_federation.py
+++ b/tests/federation/test_federation.py
@@ -52,6 +52,7 @@ class FederationTestCase(unittest.TestCase):
             "get_received_txn_response",
             "set_received_txn_response",
             "get_destination_retry_timings",
+            "get_auth_chain",
         ])
         self.mock_persistence.get_received_txn_response.return_value = (
             defer.succeed(None)
@@ -59,6 +60,7 @@ class FederationTestCase(unittest.TestCase):
         self.mock_persistence.get_destination_retry_timings.return_value = (
             defer.succeed(DestinationsTable.EntryType("", 0, 0))
         )
+        self.mock_persistence.get_auth_chain.return_value = []
         self.mock_config = Mock()
         self.mock_config.signing_key = [MockKey()]
         self.clock = MockClock()
diff --git a/tests/handlers/test_presencelike.py b/tests/handlers/test_presencelike.py
index 532ecf0f2c..0584e4c8b9 100644
--- a/tests/handlers/test_presencelike.py
+++ b/tests/handlers/test_presencelike.py
@@ -19,7 +19,7 @@ presence and profiles; namely, the displayname and avatar_url."""
 from tests import unittest
 from twisted.internet import defer
 
-from mock import Mock, call, ANY
+from mock import Mock, call, ANY, NonCallableMock
 
 from ..utils import MockClock, MockKey
 
@@ -75,8 +75,13 @@ class PresenceProfilelikeDataTestCase(unittest.TestCase):
                 resource_for_federation=Mock(),
                 http_client=None,
                 replication_layer=MockReplication(),
-                config=self.mock_config,
-            )
+                ratelimiter=NonCallableMock(spec_set=[
+                "send_message",
+                ]),
+                config=self.mock_config
+        )
+        self.ratelimiter = hs.get_ratelimiter()
+        self.ratelimiter.send_message.return_value = (True, 0)
         hs.handlers = PresenceAndProfileHandlers(hs)
 
         self.datastore = hs.get_datastore()
diff --git a/tests/handlers/test_profile.py b/tests/handlers/test_profile.py
index 1660e7e928..25b172aa5e 100644
--- a/tests/handlers/test_profile.py
+++ b/tests/handlers/test_profile.py
@@ -17,7 +17,7 @@
 from tests import unittest
 from twisted.internet import defer
 
-from mock import Mock
+from mock import Mock, NonCallableMock
 
 from synapse.api.errors import AuthError
 from synapse.server import HomeServer
@@ -59,7 +59,14 @@ class ProfileTestCase(unittest.TestCase):
                 resource_for_federation=Mock(),
                 replication_layer=self.mock_federation,
                 config=self.mock_config,
+                ratelimiter=NonCallableMock(spec_set=[
+                    "send_message",
+                ])
             )
+
+        self.ratelimiter = hs.get_ratelimiter()
+        self.ratelimiter.send_message.return_value = (True, 0)
+
         hs.handlers = ProfileHandlers(hs)
 
         self.store = hs.get_datastore()
diff --git a/tests/handlers/test_typing.py b/tests/handlers/test_typing.py
index 0d4b368a43..6a498b23a4 100644
--- a/tests/handlers/test_typing.py
+++ b/tests/handlers/test_typing.py
@@ -352,3 +352,29 @@ class TypingNotificationsTestCase(unittest.TestCase):
                 }},
             ]
         )
+
+        # SYN-230 - see if we can still set after timeout
+
+        yield self.handler.started_typing(
+            target_user=self.u_apple,
+            auth_user=self.u_apple,
+            room_id=self.room_id,
+            timeout=10000,
+        )
+
+        self.on_new_user_event.assert_has_calls([
+            call(rooms=[self.room_id]),
+        ])
+        self.on_new_user_event.reset_mock()
+
+        self.assertEquals(self.event_source.get_current_key(), 3)
+        self.assertEquals(
+            self.event_source.get_new_events_for_user(self.u_apple, 0, None)[0],
+            [
+                {"type": "m.typing",
+                 "room_id": self.room_id,
+                 "content": {
+                     "user_ids": [self.u_apple.to_string()],
+                }},
+            ]
+        )
diff --git a/tests/rest/test_rooms.py b/tests/rest/test_rooms.py
index 84fd730afc..8e65ff9a1c 100644
--- a/tests/rest/test_rooms.py
+++ b/tests/rest/test_rooms.py
@@ -294,7 +294,7 @@ class RoomPermissionsTestCase(RestTestCase):
         # set [invite/join/left] of self, set [invite/join/left] of other,
         # expect all 403s
         for usr in [self.user_id, self.rmcreator_id]:
-            yield self.join(room=room, user=usr, expect_code=403)
+            yield self.join(room=room, user=usr, expect_code=404)
             yield self.leave(room=room, user=usr, expect_code=403)
 
     @defer.inlineCallbacks
diff --git a/tests/rest/test_typing.py b/tests/rest/test_typing.py
index c550294d59..18138af1b5 100644
--- a/tests/rest/test_typing.py
+++ b/tests/rest/test_typing.py
@@ -21,7 +21,7 @@ from twisted.internet import defer
 import synapse.rest.room
 from synapse.server import HomeServer
 
-from ..utils import MockHttpResource, SQLiteMemoryDbPool, MockKey
+from ..utils import MockHttpResource, MockClock, SQLiteMemoryDbPool, MockKey
 from .utils import RestTestCase
 
 from mock import Mock, NonCallableMock
@@ -36,6 +36,8 @@ class RoomTypingTestCase(RestTestCase):
 
     @defer.inlineCallbacks
     def setUp(self):
+        self.clock = MockClock()
+
         self.mock_resource = MockHttpResource(prefix=PATH_PREFIX)
         self.auth_user_id = self.user_id
 
@@ -47,6 +49,7 @@ class RoomTypingTestCase(RestTestCase):
 
         hs = HomeServer(
             "red",
+            clock=self.clock,
             db_pool=db_pool,
             http_client=None,
             replication_layer=Mock(),
@@ -77,6 +80,30 @@ class RoomTypingTestCase(RestTestCase):
             return defer.succeed(None)
         hs.get_datastore().insert_client_ip = _insert_client_ip
 
+        def get_room_members(room_id):
+            if room_id == self.room_id:
+                return defer.succeed([hs.parse_userid(self.user_id)])
+            else:
+                return defer.succeed([])
+
+        @defer.inlineCallbacks
+        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:
+                    continue
+
+                if hs.is_mine(member):
+                    if localusers is not None:
+                        localusers.add(member)
+                else:
+                    if remotedomains is not None:
+                        remotedomains.add(member.domain)
+        hs.get_handlers().room_member_handler.fetch_room_distributions_into = (
+                fetch_room_distributions_into)
+
         synapse.rest.room.register_servlets(hs, self.mock_resource)
 
         self.room_id = yield self.create_room_as(self.user_id)
@@ -113,3 +140,25 @@ class RoomTypingTestCase(RestTestCase):
             '{"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),
+            '{"typing": true, "timeout": 30000}'
+        )
+        self.assertEquals(200, code)
+
+        self.assertEquals(self.event_source.get_current_key(), 1)
+
+        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),
+            '{"typing": true, "timeout": 30000}'
+        )
+        self.assertEquals(200, code)
+
+        self.assertEquals(self.event_source.get_current_key(), 3)
diff --git a/tests/test_distributor.py b/tests/test_distributor.py
index 39c5b8dff2..6a0095d850 100644
--- a/tests/test_distributor.py
+++ b/tests/test_distributor.py
@@ -13,12 +13,13 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-from tests import unittest
+from . import unittest
 from twisted.internet import defer
 
 from mock import Mock, patch
 
 from synapse.util.distributor import Distributor
+from synapse.util.async import run_on_reactor
 
 
 class DistributorTestCase(unittest.TestCase):
@@ -26,6 +27,7 @@ class DistributorTestCase(unittest.TestCase):
     def setUp(self):
         self.dist = Distributor()
 
+    @defer.inlineCallbacks
     def test_signal_dispatch(self):
         self.dist.declare("alert")
 
@@ -33,10 +35,11 @@ class DistributorTestCase(unittest.TestCase):
         self.dist.observe("alert", observer)
 
         d = self.dist.fire("alert", 1, 2, 3)
-
+        yield d
         self.assertTrue(d.called)
         observer.assert_called_with(1, 2, 3)
 
+    @defer.inlineCallbacks
     def test_signal_dispatch_deferred(self):
         self.dist.declare("whine")
 
@@ -50,8 +53,10 @@ class DistributorTestCase(unittest.TestCase):
         self.assertFalse(d_outer.called)
 
         d_inner.callback(None)
+        yield d_outer
         self.assertTrue(d_outer.called)
 
+    @defer.inlineCallbacks
     def test_signal_catch(self):
         self.dist.declare("alarm")
 
@@ -65,6 +70,7 @@ class DistributorTestCase(unittest.TestCase):
                 spec=["warning"]
         ) as mock_logger:
             d = self.dist.fire("alarm", "Go")
+            yield d
             self.assertTrue(d.called)
 
             observers[0].assert_called_once("Go")
@@ -81,23 +87,28 @@ class DistributorTestCase(unittest.TestCase):
 
         self.dist.declare("whail")
 
-        observer = Mock()
-        observer.return_value = defer.fail(
-            Exception("Oopsie")
-        )
+        class MyException(Exception):
+            pass
+
+        @defer.inlineCallbacks
+        def observer():
+            yield run_on_reactor()
+            raise MyException("Oopsie")
 
         self.dist.observe("whail", observer)
 
         d = self.dist.fire("whail")
 
-        yield self.assertFailure(d, Exception)
+        yield self.assertFailure(d, MyException)
+        self.dist.suppress_failures = True
 
+    @defer.inlineCallbacks
     def test_signal_prereg(self):
         observer = Mock()
         self.dist.observe("flare", observer)
 
         self.dist.declare("flare")
-        self.dist.fire("flare", 4, 5)
+        yield self.dist.fire("flare", 4, 5)
 
         observer.assert_called_with(4, 5)
 
diff --git a/tests/unittest.py b/tests/unittest.py
index a9c0e05541..fe26b7574f 100644
--- a/tests/unittest.py
+++ b/tests/unittest.py
@@ -69,6 +69,8 @@ class TestCase(unittest.TestCase):
                     return ret
 
             logging.getLogger().setLevel(level)
+            # Don't set SQL logging
+            logging.getLogger("synapse.storage").setLevel(old_level)
             return orig()
 
     def assertObjectHasAttributes(self, attrs, obj):