summary refs log tree commit diff
path: root/tests/handlers/test_presence.py
diff options
context:
space:
mode:
authorPaul "LeoNerd" Evans <paul@matrix.org>2015-01-21 16:58:16 +0000
committerPaul "LeoNerd" Evans <paul@matrix.org>2015-01-21 16:58:16 +0000
commitdbe71e670c9f7068591b61f0975fdf5225a2cf3f (patch)
tree5b1a6fbd682ea74ceb18f0b0512aecc046713c2c /tests/handlers/test_presence.py
parentOnly start the notifier timeout once we've had a chance to check for updates.... (diff)
downloadsynapse-dbe71e670c9f7068591b61f0975fdf5225a2cf3f.tar.xz
Use common base class for two Presence unit-tests, avoiding boilerplate copypasta
Diffstat (limited to '')
-rw-r--r--tests/handlers/test_presence.py79
1 files changed, 25 insertions, 54 deletions
diff --git a/tests/handlers/test_presence.py b/tests/handlers/test_presence.py
index b85a89052a..e96b73f977 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,11 +98,19 @@ 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_members = []
@@ -128,6 +142,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 +224,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