switch to using HomeserverTestCase

This commit is contained in:
Hubert Chathi 2019-10-25 10:42:07 -04:00
parent 29a0bc5637
commit 4cf3a30a20

View File

@ -26,46 +26,52 @@ room_key = {
} }
class E2eRoomKeysHandlerTestCase(unittest.TestCase): class E2eRoomKeysHandlerTestCase(unittest.HomeserverTestCase):
@defer.inlineCallbacks def make_homeserver(self, reactor, clock):
def setUp(self): hs = self.setup_test_homeserver("server", http_client=None)
hs = yield utils.setup_test_homeserver(self.addCleanup)
self.store = hs.get_datastore() self.store = hs.get_datastore()
return hs
@defer.inlineCallbacks
def test_room_keys_version_delete(self): def test_room_keys_version_delete(self):
# test that deleting a room key backup deletes the keys # test that deleting a room key backup deletes the keys
version1 = yield self.store.create_e2e_room_keys_version( version1 = self.get_success(
"user_id", {"algorithm": "rot13", "auth_data": {}} self.store.create_e2e_room_keys_version(
"user_id", {"algorithm": "rot13", "auth_data": {}}
)
) )
yield self.store.set_e2e_room_key( self.get_success(
"user_id", version1, "room", "session", room_key self.store.set_e2e_room_key(
"user_id", version1, "room", "session", room_key
)
) )
version2 = yield self.store.create_e2e_room_keys_version( version2 = self.get_success(
"user_id", {"algorithm": "rot13", "auth_data": {}} self.store.create_e2e_room_keys_version(
"user_id", {"algorithm": "rot13", "auth_data": {}}
)
) )
yield self.store.set_e2e_room_key( self.get_success(
"user_id", version2, "room", "session", room_key self.store.set_e2e_room_key(
"user_id", version2, "room", "session", room_key
)
) )
# make sure the keys were stored properly # make sure the keys were stored properly
keys = yield self.store.get_e2e_room_keys("user_id", version1) keys = self.get_success(self.store.get_e2e_room_keys("user_id", version1))
self.assertEqual(len(keys["rooms"]), 1) self.assertEqual(len(keys["rooms"]), 1)
keys = yield self.store.get_e2e_room_keys("user_id", version2) keys = self.get_success(self.store.get_e2e_room_keys("user_id", version2))
self.assertEqual(len(keys["rooms"]), 1) self.assertEqual(len(keys["rooms"]), 1)
# delete version1 # delete version1
yield self.store.delete_e2e_room_keys_version("user_id", version1) self.get_success(self.store.delete_e2e_room_keys_version("user_id", version1))
# make sure the key from version1 is gone, and the key from version2 is # make sure the key from version1 is gone, and the key from version2 is
# still there # still there
keys = yield self.store.get_e2e_room_keys("user_id", version1) keys = self.get_success(self.store.get_e2e_room_keys("user_id", version1))
self.assertEqual(len(keys["rooms"]), 0) self.assertEqual(len(keys["rooms"]), 0)
keys = yield self.store.get_e2e_room_keys("user_id", version2) keys = self.get_success(self.store.get_e2e_room_keys("user_id", version2))
self.assertEqual(len(keys["rooms"]), 1) self.assertEqual(len(keys["rooms"]), 1)