import json from urllib.request import urlopen from test_ready_server import server_url, send, receive from websockets.sync.client import connect def test_discovery_visibility_and_connected_users(server_url): endpoint = server_url.replace('ws://', 'http://').removesuffix('/ws') + '/api/rooms' def listing(): with urlopen(endpoint, timeout=3) as response: assert response.headers['Cache-Control'] == 'no-store' return json.load(response)['rooms'] assert listing() == [] with connect(server_url) as public, connect(server_url) as private: file_info = {'name': 'test.mkv', 'size': 1234, 'duration': 60} send(public, type='create_room', username='Public', fileInfo=file_info) public_code = receive(public, 'room_created')['code'] send(private, type='create_room', username='Private', fileInfo=file_info, listed=False) private_code = receive(private, 'room_created')['code'] rooms = listing() assert len(rooms) == 1 assert rooms[0]['code'] == public_code assert rooms[0]['users'] == ['Public'] assert rooms[0]['playing'] is False with connect(server_url) as guest: send(guest, type='join_room', username='Guest', code=private_code) receive(guest, 'room_file_check') send(guest, type='confirm_join', fileInfo=file_info) receive(guest, 'room_joined') assert len(listing()) == 1 assert listing() == []