summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2014-09-01 18:21:29 +0100
committerErik Johnston <erik@matrix.org>2014-09-01 18:21:29 +0100
commit3faa2ae78c7ce2330ed7699ffe3fd08306055da9 (patch)
treee97b09a70586b58cdc9f2533dae1d071167b4b71 /tests
parentAdd beginnings of ban support. (diff)
parentFollow API renaming. state -> presence. mtime_ago -> last_active_ago (diff)
downloadsynapse-3faa2ae78c7ce2330ed7699ffe3fd08306055da9.tar.xz
Merge branch 'develop' of github.com:matrix-org/synapse into room_config
Diffstat (limited to 'tests')
-rw-r--r--tests/handlers/test_presence.py149
-rw-r--r--tests/handlers/test_presencelike.py39
-rw-r--r--tests/rest/test_presence.py20
-rw-r--r--tests/rest/test_rooms.py12
-rw-r--r--tests/utils.py5
5 files changed, 143 insertions, 82 deletions
diff --git a/tests/handlers/test_presence.py b/tests/handlers/test_presence.py
index 451e1eaa22..844c4e3fb7 100644
--- a/tests/handlers/test_presence.py
+++ b/tests/handlers/test_presence.py
@@ -35,8 +35,6 @@ ONLINE = PresenceState.ONLINE
 
 
 logging.getLogger().addHandler(logging.NullHandler())
-#logging.getLogger().addHandler(logging.StreamHandler())
-#logging.getLogger().setLevel(logging.DEBUG)
 
 
 def _expect_edu(destination, edu_type, content, origin="test"):
@@ -141,7 +139,8 @@ class PresenceStateTestCase(unittest.TestCase):
             target_user=self.u_apple, auth_user=self.u_apple
         )
 
-        self.assertEquals({"state": ONLINE, "status_msg": "Online"},
+        self.assertEquals(
+            {"state": ONLINE, "presence": ONLINE, "status_msg": "Online"},
             state
         )
         mocked_get.assert_called_with("apple")
@@ -157,7 +156,8 @@ class PresenceStateTestCase(unittest.TestCase):
             target_user=self.u_apple, auth_user=self.u_banana
         )
 
-        self.assertEquals({"state": ONLINE, "status_msg": "Online"},
+        self.assertEquals(
+            {"state": ONLINE, "presence": ONLINE, "status_msg": "Online"},
             state
         )
         mocked_get.assert_called_with("apple")
@@ -175,7 +175,10 @@ class PresenceStateTestCase(unittest.TestCase):
             target_user=self.u_apple, auth_user=self.u_clementine
         )
 
-        self.assertEquals({"state": ONLINE, "status_msg": "Online"}, state)
+        self.assertEquals(
+            {"state": ONLINE, "presence": ONLINE, "status_msg": "Online"},
+            state
+        )
 
     @defer.inlineCallbacks
     def test_get_disallowed_state(self):
@@ -202,20 +205,20 @@ class PresenceStateTestCase(unittest.TestCase):
 
         yield self.handler.set_state(
                 target_user=self.u_apple, auth_user=self.u_apple,
-                state={"state": UNAVAILABLE, "status_msg": "Away"})
+                state={"presence": UNAVAILABLE, "status_msg": "Away"})
 
         mocked_set.assert_called_with("apple",
                 {"state": UNAVAILABLE, "status_msg": "Away"})
         self.mock_start.assert_called_with(self.u_apple,
                 state={
-                    "state": UNAVAILABLE,
+                    "presence": UNAVAILABLE,
                     "status_msg": "Away",
-                    "mtime": 1000000, # MockClock
+                    "last_active": 1000000, # MockClock
                 })
 
         yield self.handler.set_state(
                 target_user=self.u_apple, auth_user=self.u_apple,
-                state={"state": OFFLINE})
+                state={"presence": OFFLINE})
 
         self.mock_stop.assert_called_with(self.u_apple)
 
@@ -449,28 +452,35 @@ class PresenceInvitesTestCase(unittest.TestCase):
     @defer.inlineCallbacks
     def test_get_presence_list(self):
         self.datastore.get_presence_list.return_value = defer.succeed(
-                [{"observed_user_id": "@banana:test"}]
+            [{"observed_user_id": "@banana:test"}]
         )
 
         presence = yield self.handler.get_presence_list(
                 observer_user=self.u_apple)
 
-        self.assertEquals([{"observed_user": self.u_banana,
-                            "state": OFFLINE}], presence)
+        self.assertEquals([
+            {"observed_user": self.u_banana,
+             "presence": OFFLINE,
+             "state": OFFLINE},
+        ], presence)
 
         self.datastore.get_presence_list.assert_called_with("apple",
-                accepted=None)
-
+            accepted=None
+        )
 
         self.datastore.get_presence_list.return_value = defer.succeed(
-                [{"observed_user_id": "@banana:test"}]
+            [{"observed_user_id": "@banana:test"}]
         )
 
         presence = yield self.handler.get_presence_list(
-                observer_user=self.u_apple, accepted=True)
+            observer_user=self.u_apple, accepted=True
+        )
 
-        self.assertEquals([{"observed_user": self.u_banana,
-                            "state": OFFLINE}], presence)
+        self.assertEquals([
+            {"observed_user": self.u_banana,
+             "presence": OFFLINE,
+             "state": OFFLINE},
+        ], presence)
 
         self.datastore.get_presence_list.assert_called_with("apple",
                 accepted=True)
@@ -611,6 +621,9 @@ class PresencePushTestCase(unittest.TestCase):
 
         # TODO(paul): Gut-wrenching
         self.handler._user_cachemap[self.u_apple] = UserPresenceCache()
+        self.handler._user_cachemap[self.u_apple].update(
+            {"presence": OFFLINE}, serial=0
+        )
         apple_set = self.handler._local_pushmap.setdefault("apple", set())
         apple_set.add(self.u_banana)
         apple_set.add(self.u_clementine)
@@ -618,7 +631,8 @@ class PresencePushTestCase(unittest.TestCase):
         self.assertEquals(self.event_source.get_current_key(), 0)
 
         yield self.handler.set_state(self.u_apple, self.u_apple,
-                {"state": ONLINE})
+            {"presence": ONLINE}
+        )
 
         self.assertEquals(self.event_source.get_current_key(), 1)
         self.assertEquals(
@@ -627,8 +641,9 @@ class PresencePushTestCase(unittest.TestCase):
                 {"type": "m.presence",
                  "content": {
                     "user_id": "@apple:test",
+                    "presence": ONLINE,
                     "state": ONLINE,
-                    "mtime_age": 0,
+                    "last_active_ago": 0,
                 }},
             ],
         )
@@ -636,13 +651,21 @@ class PresencePushTestCase(unittest.TestCase):
         presence = yield self.handler.get_presence_list(
                 observer_user=self.u_apple, accepted=True)
 
-        self.assertEquals([
-                {"observed_user": self.u_banana, "state": OFFLINE},
-                {"observed_user": self.u_clementine, "state": OFFLINE}],
-            presence)
+        self.assertEquals(
+            [
+                {"observed_user": self.u_banana, 
+                 "presence": OFFLINE,
+                 "state": OFFLINE},
+                {"observed_user": self.u_clementine,
+                 "presence": OFFLINE,
+                 "state": OFFLINE},
+            ],
+            presence
+        )
 
         yield self.handler.set_state(self.u_banana, self.u_banana,
-                {"state": ONLINE})
+            {"presence": ONLINE}
+        )
 
         self.clock.advance_time(2)
 
@@ -651,9 +674,11 @@ class PresencePushTestCase(unittest.TestCase):
 
         self.assertEquals([
                 {"observed_user": self.u_banana,
+                 "presence": ONLINE,
                  "state": ONLINE,
-                 "mtime_age": 2000},
+                 "last_active_ago": 2000},
                 {"observed_user": self.u_clementine,
+                 "presence": OFFLINE,
                  "state": OFFLINE},
         ], presence)
 
@@ -666,8 +691,9 @@ class PresencePushTestCase(unittest.TestCase):
                 {"type": "m.presence",
                  "content": {
                      "user_id": "@banana:test",
+                     "presence": ONLINE,
                      "state": ONLINE,
-                     "mtime_age": 2000
+                     "last_active_ago": 2000
                 }},
             ]
         )
@@ -682,8 +708,9 @@ class PresencePushTestCase(unittest.TestCase):
                     content={
                         "push": [
                             {"user_id": "@apple:test",
+                             "presence": u"online",
                              "state": u"online",
-                             "mtime_age": 0},
+                             "last_active_ago": 0},
                         ],
                     }
                 )
@@ -699,11 +726,14 @@ class PresencePushTestCase(unittest.TestCase):
 
         # TODO(paul): Gut-wrenching
         self.handler._user_cachemap[self.u_apple] = UserPresenceCache()
+        self.handler._user_cachemap[self.u_apple].update(
+            {"presence": OFFLINE}, serial=0
+        )
         apple_set = self.handler._remote_sendmap.setdefault("apple", set())
         apple_set.add(self.u_potato.domain)
 
         yield self.handler.set_state(self.u_apple, self.u_apple,
-            {"state": ONLINE}
+            {"presence": ONLINE}
         )
 
         yield put_json.await_calls()
@@ -726,7 +756,7 @@ class PresencePushTestCase(unittest.TestCase):
                     "push": [
                         {"user_id": "@potato:remote",
                          "state": "online",
-                         "mtime_age": 1000},
+                         "last_active_ago": 1000},
                     ],
                 }
             )
@@ -741,8 +771,9 @@ class PresencePushTestCase(unittest.TestCase):
                 {"type": "m.presence",
                  "content": {
                      "user_id": "@potato:remote",
+                     "presence": ONLINE,
                      "state": ONLINE,
-                     "mtime_age": 1000,
+                     "last_active_ago": 1000,
                 }}
             ]
         )
@@ -751,7 +782,10 @@ class PresencePushTestCase(unittest.TestCase):
 
         state = yield self.handler.get_state(self.u_potato, self.u_apple)
 
-        self.assertEquals({"state": ONLINE, "mtime_age": 3000}, state)
+        self.assertEquals(
+            {"state": ONLINE, "presence": ONLINE, "last_active_ago": 3000},
+            state
+        )
 
     @defer.inlineCallbacks
     def test_join_room_local(self):
@@ -763,8 +797,8 @@ class PresencePushTestCase(unittest.TestCase):
         self.handler._user_cachemap[self.u_clementine] = UserPresenceCache()
         self.handler._user_cachemap[self.u_clementine].update(
             {
-                "state": PresenceState.ONLINE,
-                "mtime": self.clock.time_msec(),
+                "presence": PresenceState.ONLINE,
+                "last_active": self.clock.time_msec(),
             }, self.u_clementine
         )
 
@@ -781,8 +815,9 @@ class PresencePushTestCase(unittest.TestCase):
                 {"type": "m.presence",
                  "content": {
                      "user_id": "@clementine:test",
+                     "presence": ONLINE,
                      "state": ONLINE,
-                     "mtime_age": 0,
+                     "last_active_ago": 0,
                 }}
             ]
         )
@@ -798,7 +833,8 @@ class PresencePushTestCase(unittest.TestCase):
                     content={
                         "push": [
                             {"user_id": "@apple:test",
-                            "state": "online"},
+                             "presence": "online",
+                             "state": "online"},
                         ],
                     }
                 ),
@@ -812,7 +848,8 @@ class PresencePushTestCase(unittest.TestCase):
                     content={
                         "push": [
                             {"user_id": "@banana:test",
-                            "state": "offline"},
+                             "presence": "offline",
+                             "state": "offline"},
                         ],
                     }
                 ),
@@ -823,7 +860,7 @@ class PresencePushTestCase(unittest.TestCase):
         # TODO(paul): Gut-wrenching
         self.handler._user_cachemap[self.u_apple] = UserPresenceCache()
         self.handler._user_cachemap[self.u_apple].update(
-                {"state": PresenceState.ONLINE}, self.u_apple)
+                {"presence": PresenceState.ONLINE}, self.u_apple)
         self.room_members = [self.u_apple, self.u_banana]
 
         yield self.distributor.fire("user_joined_room", self.u_potato,
@@ -841,7 +878,8 @@ class PresencePushTestCase(unittest.TestCase):
                     content={
                         "push": [
                             {"user_id": "@clementine:test",
-                            "state": "online"},
+                             "presence": "online",
+                             "state": "online"},
                         ],
                     }
                 ),
@@ -851,7 +889,7 @@ class PresencePushTestCase(unittest.TestCase):
 
         self.handler._user_cachemap[self.u_clementine] = UserPresenceCache()
         self.handler._user_cachemap[self.u_clementine].update(
-                {"state": ONLINE}, self.u_clementine)
+                {"presence": ONLINE}, self.u_clementine)
         self.room_members.append(self.u_potato)
 
         yield self.distributor.fire("user_joined_room", self.u_clementine,
@@ -935,7 +973,8 @@ class PresencePollingTestCase(unittest.TestCase):
         def get_presence_state(user_localpart):
             return defer.succeed(
                     {"state": self.current_user_state[user_localpart],
-                     "status_msg": None}
+                     "status_msg": None,
+                     "mtime": 123456000}
             )
         self.datastore.get_presence_state = get_presence_state
 
@@ -969,7 +1008,7 @@ class PresencePollingTestCase(unittest.TestCase):
         # apple goes online
         yield self.handler.set_state(
             target_user=self.u_apple, auth_user=self.u_apple,
-            state={"state": ONLINE}
+            state={"presence": ONLINE}
         )
 
         # apple should see both banana and clementine currently offline
@@ -992,8 +1031,9 @@ class PresencePollingTestCase(unittest.TestCase):
 
         # banana goes online
         yield self.handler.set_state(
-                target_user=self.u_banana, auth_user=self.u_banana,
-                state={"state": ONLINE})
+            target_user=self.u_banana, auth_user=self.u_banana,
+            state={"presence": ONLINE}
+        )
 
         # apple and banana should now both see each other online
         self.mock_update_client.assert_has_calls([
@@ -1013,8 +1053,9 @@ class PresencePollingTestCase(unittest.TestCase):
 
         # apple goes offline
         yield self.handler.set_state(
-                target_user=self.u_apple, auth_user=self.u_apple,
-                state={"state": OFFLINE})
+            target_user=self.u_apple, auth_user=self.u_apple,
+            state={"presence": OFFLINE}
+        )
 
         # banana should now be told apple is offline
         self.mock_update_client.assert_has_calls([
@@ -1027,7 +1068,6 @@ class PresencePollingTestCase(unittest.TestCase):
         self.assertFalse("banana" in self.handler._local_pushmap)
         self.assertFalse("clementine" in self.handler._local_pushmap)
 
-
     @defer.inlineCallbacks
     def test_remote_poll_send(self):
         put_json = self.mock_http_client.put_json
@@ -1057,8 +1097,9 @@ class PresencePollingTestCase(unittest.TestCase):
 
         # clementine goes online
         yield self.handler.set_state(
-                target_user=self.u_clementine, auth_user=self.u_clementine,
-                state={"state": ONLINE})
+            target_user=self.u_clementine, auth_user=self.u_clementine,
+            state={"presence": ONLINE}
+        )
 
         yield put_json.await_calls()
 
@@ -1085,7 +1126,7 @@ class PresencePollingTestCase(unittest.TestCase):
         # fig goes online; shouldn't send a second poll
         yield self.handler.set_state(
             target_user=self.u_fig, auth_user=self.u_fig,
-            state={"state": ONLINE}
+            state={"presence": ONLINE}
         )
 
         # reactor.iterate(delay=0)
@@ -1095,7 +1136,7 @@ class PresencePollingTestCase(unittest.TestCase):
         # fig goes offline
         yield self.handler.set_state(
             target_user=self.u_fig, auth_user=self.u_fig,
-            state={"state": OFFLINE}
+            state={"presence": OFFLINE}
         )
 
         reactor.iterate(delay=0)
@@ -1116,8 +1157,9 @@ class PresencePollingTestCase(unittest.TestCase):
 
         # clementine goes offline
         yield self.handler.set_state(
-                target_user=self.u_clementine, auth_user=self.u_clementine,
-                state={"state": OFFLINE})
+            target_user=self.u_clementine, auth_user=self.u_clementine,
+            state={"presence": OFFLINE}
+        )
 
         yield put_json.await_calls()
 
@@ -1135,6 +1177,7 @@ class PresencePollingTestCase(unittest.TestCase):
                     content={
                         "push": [
                             {"user_id": "@banana:test",
+                             "presence": "offline",
                              "state": "offline",
                              "status_msg": None},
                         ],
diff --git a/tests/handlers/test_presencelike.py b/tests/handlers/test_presencelike.py
index e81d7ce101..38cc34350b 100644
--- a/tests/handlers/test_presencelike.py
+++ b/tests/handlers/test_presencelike.py
@@ -166,7 +166,11 @@ class PresenceProfilelikeDataTestCase(unittest.TestCase):
         # TODO(paul): Gut-wrenching
         from synapse.handlers.presence import UserPresenceCache
         self.handlers.presence_handler._user_cachemap[self.u_apple] = (
-                UserPresenceCache())
+            UserPresenceCache()
+        )
+        self.handlers.presence_handler._user_cachemap[self.u_apple].update(
+            {"presence": OFFLINE}, serial=0
+        )
         apple_set = self.handlers.presence_handler._local_pushmap.setdefault(
                 "apple", set())
         apple_set.add(self.u_banana)
@@ -182,11 +186,13 @@ class PresenceProfilelikeDataTestCase(unittest.TestCase):
 
         self.assertEquals([
             {"observed_user": self.u_banana,
+                "presence": ONLINE,
                 "state": ONLINE,
-                "mtime_age": 0,
+                "last_active_ago": 0,
                 "displayname": "Frank",
                 "avatar_url": "http://foo"},
             {"observed_user": self.u_clementine,
+                "presence": OFFLINE,
                 "state": OFFLINE}],
         presence)
 
@@ -199,8 +205,8 @@ class PresenceProfilelikeDataTestCase(unittest.TestCase):
 
         statuscache = self.mock_update_client.call_args[1]["statuscache"]
         self.assertEquals({
-            "state": ONLINE,
-            "mtime": 1000000, # MockClock
+            "presence": ONLINE,
+            "last_active": 1000000, # MockClock
             "displayname": "Frank",
             "avatar_url": "http://foo",
         }, statuscache.state)
@@ -222,8 +228,8 @@ class PresenceProfilelikeDataTestCase(unittest.TestCase):
 
         statuscache = self.mock_update_client.call_args[1]["statuscache"]
         self.assertEquals({
-            "state": ONLINE,
-            "mtime": 1000000, # MockClock
+            "presence": ONLINE,
+            "last_active": 1000000, # MockClock
             "displayname": "I am an Apple",
             "avatar_url": "http://foo",
         }, statuscache.state)
@@ -241,7 +247,11 @@ class PresenceProfilelikeDataTestCase(unittest.TestCase):
         # TODO(paul): Gut-wrenching
         from synapse.handlers.presence import UserPresenceCache
         self.handlers.presence_handler._user_cachemap[self.u_apple] = (
-                UserPresenceCache())
+            UserPresenceCache()
+        )
+        self.handlers.presence_handler._user_cachemap[self.u_apple].update(
+            {"presence": OFFLINE}, serial=0
+        )
         apple_set = self.handlers.presence_handler._remote_sendmap.setdefault(
                 "apple", set())
         apple_set.add(self.u_potato.domain)
@@ -255,8 +265,9 @@ class PresenceProfilelikeDataTestCase(unittest.TestCase):
                 content={
                     "push": [
                         {"user_id": "@apple:test",
+                         "presence": "online",
                          "state": "online",
-                         "mtime_age": 0,
+                         "last_active_ago": 0,
                          "displayname": "Frank",
                          "avatar_url": "http://foo"},
                     ],
@@ -293,14 +304,16 @@ class PresenceProfilelikeDataTestCase(unittest.TestCase):
             statuscache=ANY)
 
         statuscache = self.mock_update_client.call_args[1]["statuscache"]
-        self.assertEquals({"state": ONLINE,
+        self.assertEquals({"presence": ONLINE,
                            "displayname": "Frank",
                            "avatar_url": "http://foo"}, statuscache.state)
 
         state = yield self.handlers.presence_handler.get_state(self.u_potato,
                 self.u_apple)
 
-        self.assertEquals({"state": ONLINE,
-                           "displayname": "Frank",
-                           "avatar_url": "http://foo"},
-                state)
+        self.assertEquals(
+                {"presence": ONLINE,
+                 "state": ONLINE,
+                 "displayname": "Frank",
+                 "avatar_url": "http://foo"},
+            state)
diff --git a/tests/rest/test_presence.py b/tests/rest/test_presence.py
index 61692f02c2..e2cdd80e07 100644
--- a/tests/rest/test_presence.py
+++ b/tests/rest/test_presence.py
@@ -98,8 +98,10 @@ class PresenceStateTestCase(unittest.TestCase):
                 "/presence/%s/status" % (myid), None)
 
         self.assertEquals(200, code)
-        self.assertEquals({"state": ONLINE, "status_msg": "Available"},
-                response)
+        self.assertEquals(
+            {"presence": ONLINE, "state": ONLINE, "status_msg": "Available"},
+            response
+        )
         mocked_get.assert_called_with("apple")
 
     @defer.inlineCallbacks
@@ -109,7 +111,7 @@ class PresenceStateTestCase(unittest.TestCase):
 
         (code, response) = yield self.mock_resource.trigger("PUT",
                 "/presence/%s/status" % (myid),
-                '{"state": "unavailable", "status_msg": "Away"}')
+                '{"presence": "unavailable", "status_msg": "Away"}')
 
         self.assertEquals(200, code)
         mocked_set.assert_called_with("apple",
@@ -173,9 +175,9 @@ class PresenceListTestCase(unittest.TestCase):
                 "/presence/list/%s" % (myid), None)
 
         self.assertEquals(200, code)
-        self.assertEquals(
-            [{"user_id": "@banana:test", "state": OFFLINE}], response
-        )
+        self.assertEquals([
+            {"user_id": "@banana:test", "presence": OFFLINE, "state": OFFLINE},
+        ], response)
 
         self.datastore.get_presence_list.assert_called_with(
             "apple", accepted=True
@@ -314,7 +316,8 @@ class PresenceEventStreamTestCase(unittest.TestCase):
                 [])
 
         yield self.presence.set_state(self.u_banana, self.u_banana,
-                state={"state": ONLINE})
+            state={"presence": ONLINE}
+        )
 
         (code, response) = yield self.mock_resource.trigger("GET",
                 "/events?from=0_1_0&timeout=0", None)
@@ -324,8 +327,9 @@ class PresenceEventStreamTestCase(unittest.TestCase):
             {"type": "m.presence",
              "content": {
                  "user_id": "@banana:test",
+                 "presence": ONLINE,
                  "state": ONLINE,
                  "displayname": "Frank",
-                 "mtime_age": 0,
+                 "last_active_ago": 0,
             }},
         ]}, response)
diff --git a/tests/rest/test_rooms.py b/tests/rest/test_rooms.py
index b432cf254e..cdaf948a3b 100644
--- a/tests/rest/test_rooms.py
+++ b/tests/rest/test_rooms.py
@@ -51,7 +51,7 @@ class RoomPermissionsTestCase(RestTestCase):
         persistence_service.get_latest_pdus_in_context.return_value = []
 
         hs = HomeServer(
-            "test",
+            "red",
             db_pool=None,
             http_client=None,
             datastore=MemoryDataStore(),
@@ -398,7 +398,7 @@ class RoomsMemberListTestCase(RestTestCase):
         persistence_service.get_latest_pdus_in_context.return_value = []
 
         hs = HomeServer(
-            "test",
+            "red",
             db_pool=None,
             http_client=None,
             datastore=MemoryDataStore(),
@@ -476,7 +476,7 @@ class RoomsCreateTestCase(RestTestCase):
         persistence_service.get_latest_pdus_in_context.return_value = []
 
         hs = HomeServer(
-            "test",
+            "red",
             db_pool=None,
             http_client=None,
             datastore=MemoryDataStore(),
@@ -566,7 +566,7 @@ class RoomTopicTestCase(RestTestCase):
         persistence_service.get_latest_pdus_in_context.return_value = []
 
         hs = HomeServer(
-            "test",
+            "red",
             db_pool=None,
             http_client=None,
             datastore=MemoryDataStore(),
@@ -669,7 +669,7 @@ class RoomMemberStateTestCase(RestTestCase):
         persistence_service.get_latest_pdus_in_context.return_value = []
 
         hs = HomeServer(
-            "test",
+            "red",
             db_pool=None,
             http_client=None,
             datastore=MemoryDataStore(),
@@ -794,7 +794,7 @@ class RoomMessagesTestCase(RestTestCase):
         persistence_service.get_latest_pdus_in_context.return_value = []
 
         hs = HomeServer(
-            "test",
+            "red",
             db_pool=None,
             http_client=None,
             datastore=MemoryDataStore(),
diff --git a/tests/utils.py b/tests/utils.py
index 37b759febc..ea7d6893c6 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -188,8 +188,9 @@ class MemoryDataStore(object):
 
     def get_rooms_for_user_where_membership_is(self, user_id, membership_list):
         return [
-            r for r in self.members
-            if self.members[r].get(user_id).membership in membership_list
+            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
         ]
 
     def get_room_events_stream(self, user_id=None, from_key=None, to_key=None,