summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMark Haines <mjark@negativecurvature.net>2016-01-04 14:50:58 +0000
committerMark Haines <mjark@negativecurvature.net>2016-01-04 14:50:58 +0000
commit2c402214a9fe51677adf05424cca7918b91c7949 (patch)
treedc5312558565f8ac01264be21d388e563a5c8c58 /tests
parent869573fb8f2b89c411b16ab30c114342593b1946 (diff)
Imported Upstream version 0.12.0
Diffstat (limited to 'tests')
-rw-r--r--tests/handlers/test_presence.py6
-rw-r--r--tests/storage/test_events.py2
-rw-r--r--tests/util/test_snapshot_cache.py60
-rw-r--r--tests/utils.py5
4 files changed, 67 insertions, 6 deletions
diff --git a/tests/handlers/test_presence.py b/tests/handlers/test_presence.py
index 1172ceae..c42b5b80 100644
--- a/tests/handlers/test_presence.py
+++ b/tests/handlers/test_presence.py
@@ -365,7 +365,7 @@ class PresenceInvitesTestCase(PresenceTestCase):
# TODO(paul): This test will likely break if/when real auth permissions
# are added; for now the HS will always accept any invite
- yield self.handler.send_invite(
+ yield self.handler.send_presence_invite(
observer_user=self.u_apple, observed_user=self.u_banana)
self.assertEquals(
@@ -384,7 +384,7 @@ class PresenceInvitesTestCase(PresenceTestCase):
@defer.inlineCallbacks
def test_invite_local_nonexistant(self):
- yield self.handler.send_invite(
+ yield self.handler.send_presence_invite(
observer_user=self.u_apple, observed_user=self.u_durian)
self.assertEquals(
@@ -414,7 +414,7 @@ class PresenceInvitesTestCase(PresenceTestCase):
defer.succeed((200, "OK"))
)
- yield self.handler.send_invite(
+ yield self.handler.send_presence_invite(
observer_user=self.u_apple, observed_user=u_rocket)
self.assertEquals(
diff --git a/tests/storage/test_events.py b/tests/storage/test_events.py
index 31301300..946cd3e9 100644
--- a/tests/storage/test_events.py
+++ b/tests/storage/test_events.py
@@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import uuid
-from mock.mock import Mock
+from mock import Mock
from synapse.types import RoomID, UserID
from tests import unittest
diff --git a/tests/util/test_snapshot_cache.py b/tests/util/test_snapshot_cache.py
new file mode 100644
index 00000000..f58576c9
--- /dev/null
+++ b/tests/util/test_snapshot_cache.py
@@ -0,0 +1,60 @@
+# -*- 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.
+
+
+from .. import unittest
+
+from synapse.util.caches.snapshot_cache import SnapshotCache
+from twisted.internet.defer import Deferred
+
+class SnapshotCacheTestCase(unittest.TestCase):
+
+ def setUp(self):
+ self.cache = SnapshotCache()
+ self.cache.DURATION_MS = 1
+
+ def test_get_set(self):
+ # Check that getting a missing key returns None
+ self.assertEquals(self.cache.get(0, "key"), None)
+
+ # Check that setting a key with a deferred returns
+ # a deferred that resolves when the initial deferred does
+ d = Deferred()
+ set_result = self.cache.set(0, "key", d)
+ self.assertIsNotNone(set_result)
+ self.assertFalse(set_result.called)
+
+ # Check that getting the key before the deferred has resolved
+ # returns a deferred that resolves when the initial deferred does.
+ get_result_at_10 = self.cache.get(10, "key")
+ self.assertIsNotNone(get_result_at_10)
+ self.assertFalse(get_result_at_10.called)
+
+ # Check that the returned deferreds resolve when the initial deferred
+ # does.
+ d.callback("v")
+ self.assertTrue(set_result.called)
+ self.assertTrue(get_result_at_10.called)
+
+ # Check that getting the key after the deferred has resolved
+ # before the cache expires returns a resolved deferred.
+ get_result_at_11 = self.cache.get(11, "key")
+ self.assertIsNotNone(get_result_at_11)
+ self.assertTrue(get_result_at_11.called)
+
+ # Check that getting the key after the deferred has resolved
+ # after the cache expires returns None
+ get_result_at_12 = self.cache.get(12, "key")
+ self.assertIsNone(get_result_at_12)
diff --git a/tests/utils.py b/tests/utils.py
index 91040c2e..aee69b1c 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -168,8 +168,9 @@ class MockHttpResource(HttpServer):
raise KeyError("No event can handle %s" % path)
- def register_path(self, method, path_pattern, callback):
- self.callbacks.append((method, path_pattern, callback))
+ def register_paths(self, method, path_patterns, callback):
+ for path_pattern in path_patterns:
+ self.callbacks.append((method, path_pattern, callback))
class MockKey(object):