def test_early_store_loading(self): client = Client("ephemeral") with pytest.raises(LocalProtocolError): client.load_store() client = Client("ephemeral", store_path=ephemeral_dir) client.user_id = "@ephemeral:example.org" with pytest.raises(LocalProtocolError): client.load_store() client.user_id = None client.device_id = "DEVICEID" with pytest.raises(LocalProtocolError): client.load_store() client.receive_response(self.login_response) del client client = Client("ephemeral", "DEVICEID", ephemeral_dir) client.user_id = "@ephemeral:example.org" assert not client.store assert not client.olm client.load_store() assert client.store assert client.olm
def test_storing_room_encryption_state(self, client): client.receive_response(self.login_response) assert not client.encrypted_rooms client.receive_response(self.sync_response) assert TEST_ROOM_ID in client.encrypted_rooms encrypted_rooms = client.store.load_encrypted_rooms() assert TEST_ROOM_ID in encrypted_rooms client2 = Client(client.user, client.device_id, client.store_path) client2.receive_response(self.login_response) assert TEST_ROOM_ID in client2.encrypted_rooms client2.receive_response(self.downgrade_sync) room = client2.rooms[TEST_ROOM_ID] assert room.encrypted
def test_device_store(self, tempdir): client = Client("ephemeral", "DEVICEID", tempdir) client.receive_response(self.login_response) client.receive_response(KeysUploadResponse(50, 50)) assert not client.should_query_keys client.receive_response(self.sync_response) client.receive_response(self.keys_query_response) assert list(client.device_store.users) == [ALICE_ID] alice_device = client.device_store[ALICE_ID][ALICE_DEVICE_ID] assert alice_device client = Client("ephemeral", "DEVICEID", tempdir) client.receive_response(self.login_response) assert list(client.device_store.users) == [ALICE_ID] alice_device = client.device_store[ALICE_ID][ALICE_DEVICE_ID] assert alice_device
def test_sync_token_restoring(self, client): user = client.user_id device_id = client.device_id path = client.store_path del client config = ClientConfig(store_sync_tokens=True) client = Client(user, device_id, path, config=config) client.receive_response(self.login_response) assert not client.next_batch assert not client.loaded_sync_token client.receive_response(self.sync_response) assert client.next_batch client = Client(user, device_id, path, config=config) client.receive_response(self.login_response) assert client.loaded_sync_token
def test_query_rule(self): client = Client("ephemeral", "DEVICEID", ephemeral_dir) client.receive_response(self.login_response) assert client.store is not None client.receive_response(KeysUploadResponse(50, 50)) assert not client.should_query_keys client.receive_response(self.sync_response) assert client.should_query_keys client.receive_response(self.keys_query_response) assert client.olm.tracked_users == set([ALICE_ID]) assert list(client.device_store.users) == [ALICE_ID] assert not client.should_query_keys del client client = Client("ephemeral", "DEVICEID", ephemeral_dir) client.receive_response(self.login_response) assert not client.should_upload_keys assert not client.should_query_keys assert list(client.device_store.users) == [ALICE_ID] assert client.device_store.active_user_devices(ALICE_ID) alice_device = client.device_store[ALICE_ID][ALICE_DEVICE_ID] assert alice_device client.receive_response(self.second_sync) assert client.should_query_keys client.users_for_key_query == set([ALICE_ID]) client.receive_response(self.joined_members) client.users_for_key_query == set([ALICE_ID, BOB_ID]) client.receive_response(self.keys_query_response) assert client.olm.tracked_users == set([ALICE_ID]) assert client.users_for_key_query == set([BOB_ID]) assert client.should_query_keys