|
|
@@ -29,6 +29,8 @@ async def _make_client(path, timeout, script): |
|
|
|
if kind == 'recv': |
|
|
|
A, B = message, await recv_json(websocket) |
|
|
|
B.pop('ts') |
|
|
|
if B['kind'] == 'login': |
|
|
|
username = B['value'] |
|
|
|
state.update(message) |
|
|
|
if A != B: |
|
|
|
error = True |
|
|
@@ -38,8 +40,8 @@ async def _make_client(path, timeout, script): |
|
|
|
elif kind == 'send': |
|
|
|
await send_json(websocket, **message) |
|
|
|
|
|
|
|
while 'users' in state: |
|
|
|
if min(state['users']) == state['username']: |
|
|
|
while 'online' in state: |
|
|
|
if state['online'][0] == username: |
|
|
|
break |
|
|
|
message = await recv_json(websocket) |
|
|
|
message.pop('ts') |
|
|
@@ -69,116 +71,102 @@ async def _test(*clients): |
|
|
|
|
|
|
|
def test_happy_path(): |
|
|
|
client = _make_client('ws://localhost:8642/A', 0.1, Script() |
|
|
|
+ {'action': 'login', 'username': 'TestUser'} |
|
|
|
- {'kind': 'update', 'users': ['TestUser'], 'info': 'Welcome to /A', 'username': 'TestUser'} |
|
|
|
+ {'action': 'post', 'text': 'Hello World!'} |
|
|
|
- {'kind': 'post', 'source': 'TestUser', 'text': 'Hello World!'} |
|
|
|
+ {'kind': 'login', 'value': 'TestUser'} |
|
|
|
- {'kind': 'login', 'value': 'TestUser', 'online': ['TestUser']} |
|
|
|
- {'kind': 'post', 'value': 'Welcome to /A'} |
|
|
|
+ {'kind': 'post', 'value': 'Hello World!'} |
|
|
|
- {'kind': 'post', 'value': 'Hello World!', 'source': 'TestUser'} |
|
|
|
) |
|
|
|
return _test(client) |
|
|
|
|
|
|
|
|
|
|
|
def test_name_taken(): |
|
|
|
client1 = _make_client('ws://localhost:8642/', 0.10, Script() |
|
|
|
+ {'action': 'login', 'username': 'A'} |
|
|
|
- {'kind': 'update', 'users': ['A'], 'info': 'Welcome to /', 'username': 'A'} |
|
|
|
- {'kind': 'update', 'users': ['A', 'B'], 'info': 'B joined'} |
|
|
|
+ {'kind': 'login', 'value': 'A'} |
|
|
|
- {'kind': 'login', 'value': 'A', 'online': ['A']} |
|
|
|
- {'kind': 'post', 'value': 'Welcome to /'} |
|
|
|
- {'kind': 'post', 'value': 'B joined', 'online': ['A', 'B']} |
|
|
|
) |
|
|
|
client2 = _make_client('ws://localhost:8642/', 0.11, Script() |
|
|
|
+ {'action': 'login', 'username': 'A'} |
|
|
|
- {'kind': 'error', 'info': 'Username taken'} |
|
|
|
+ {'kind': 'login', 'value': 'A'} |
|
|
|
- {'kind': 'error', 'value': 'Username taken'} |
|
|
|
) |
|
|
|
client3 = _make_client('ws://localhost:8642/', 0.12, Script() |
|
|
|
+ {'action': 'login', 'username': 'B'} |
|
|
|
- {'kind': 'update', 'users': ['A', 'B'], 'info': 'Welcome to /', 'username': 'B'} |
|
|
|
- {'kind': 'update', 'users': ['B'], 'info': 'A left'} |
|
|
|
+ {'kind': 'login', 'value': 'B'} |
|
|
|
- {'kind': 'login', 'value': 'B', 'online': ['A', 'B']} |
|
|
|
- {'kind': 'post', 'value': 'Welcome to /'} |
|
|
|
- {'kind': 'post', 'value': 'A left', 'online': ['B']} |
|
|
|
) |
|
|
|
return _test(client1, client2, client3) |
|
|
|
|
|
|
|
|
|
|
|
def test_interact(): |
|
|
|
def test_interaction(): |
|
|
|
client1 = _make_client('ws://localhost:8642/', 0.10, Script() |
|
|
|
+ {'action': 'login', 'username': 'Alice'} |
|
|
|
- {'kind': 'update', 'users': ['Alice'], 'info': 'Welcome to /', 'username': 'Alice'} |
|
|
|
- {'kind': 'update', 'users': ['Alice', 'Bob'], 'info': 'Bob joined'} |
|
|
|
+ {'action': 'post', 'text': 'Hey Bob!'} |
|
|
|
- {'kind': 'post', 'source': 'Alice', 'text': 'Hey Bob!'} |
|
|
|
- {'kind': 'post', 'source': 'Bob', 'text': 'Howdy!'} |
|
|
|
+ {'kind': 'login', 'value': 'Alice'} |
|
|
|
- {'kind': 'login', 'value': 'Alice', 'online': ['Alice']} |
|
|
|
- {'kind': 'post', 'value': 'Welcome to /'} |
|
|
|
- {'kind': 'post', 'value': 'Bob joined', 'online': ['Alice', 'Bob']} |
|
|
|
+ {'kind': 'post', 'value': 'Hey Bob!'} |
|
|
|
- {'kind': 'post', 'value': 'Hey Bob!', 'source': 'Alice'} |
|
|
|
- {'kind': 'post', 'value': 'Howdy!', 'source': 'Bob'} |
|
|
|
) |
|
|
|
client2 = _make_client('ws://localhost:8642/', 0.11, Script() |
|
|
|
+ {'action': 'login', 'username': 'Bob'} |
|
|
|
- {'kind': 'update', 'users': ['Alice', 'Bob'], 'info': 'Welcome to /', 'username': 'Bob'} |
|
|
|
- {'kind': 'post', 'source': 'Alice', 'text': 'Hey Bob!'} |
|
|
|
+ {'action': 'post', 'text': 'Howdy!'} |
|
|
|
- {'kind': 'post', 'source': 'Bob', 'text': 'Howdy!'} |
|
|
|
+ {'action': 'post', 'text': ''} |
|
|
|
- {'kind': 'update', 'users': ['Bob'], 'info': 'Alice left'} |
|
|
|
+ {'kind': 'login', 'value': 'Bob'} |
|
|
|
- {'kind': 'login', 'value': 'Bob', 'online': ['Alice', 'Bob']} |
|
|
|
- {'kind': 'post', 'value': 'Welcome to /'} |
|
|
|
- {'kind': 'post', 'value': 'Hey Bob!', 'source': 'Alice'} |
|
|
|
+ {'kind': 'post', 'value': 'Howdy!'} |
|
|
|
- {'kind': 'post', 'value': 'Howdy!', 'source': 'Bob'} |
|
|
|
- {'kind': 'post', 'value': 'Alice left', 'online': ['Bob']} |
|
|
|
) |
|
|
|
return _test(client1, client2) |
|
|
|
|
|
|
|
|
|
|
|
def test_party(): |
|
|
|
client1 = _make_client('ws://localhost:8642/', 0.10, Script() |
|
|
|
+ {'action': 'login', 'username': 'Norman'} |
|
|
|
- {'kind': 'update', 'users': ['Norman'], 'info': 'Welcome to /', 'username': 'Norman'} |
|
|
|
- {'kind': 'update', 'users': ['Norman', 'Ray'], 'info': 'Ray joined'} |
|
|
|
- {'kind': 'update', 'users': ['Emma', 'Norman', 'Ray'], 'info': 'Emma joined'} |
|
|
|
+ {'action': 'post', 'text': 'なに?'} |
|
|
|
- {'kind': 'post', 'source': 'Norman', 'text': 'なに?'} |
|
|
|
- {'kind': 'update', 'users': ['Norman', 'Ray'], 'info': 'Emma left'} |
|
|
|
) |
|
|
|
client2 = _make_client('ws://localhost:8642/', 0.11, Script() |
|
|
|
+ {'action': 'login', 'username': 'Ray'} |
|
|
|
- {'kind': 'update', 'users': ['Norman', 'Ray'], 'info': 'Welcome to /', 'username': 'Ray'} |
|
|
|
- {'kind': 'update', 'users': ['Emma', 'Norman', 'Ray'], 'info': 'Emma joined'} |
|
|
|
- {'kind': 'post', 'source': 'Norman', 'text': 'なに?'} |
|
|
|
- {'kind': 'update', 'users': ['Norman', 'Ray'], 'info': 'Emma left'} |
|
|
|
- {'kind': 'update', 'users': ['Ray'], 'info': 'Norman left'} |
|
|
|
) |
|
|
|
client3 = _make_client('ws://localhost:8642/', 0.12, Script() |
|
|
|
+ {'action': 'login', 'username': 'Emma'} |
|
|
|
- {'kind': 'update', 'users': ['Emma', 'Norman', 'Ray'], 'info': 'Welcome to /', 'username': 'Emma'} |
|
|
|
- {'kind': 'post', 'source': 'Norman', 'text': 'なに?'} |
|
|
|
) |
|
|
|
return _test(client1, client2, client3) |
|
|
|
|
|
|
|
|
|
|
|
def test_rooms(): |
|
|
|
client1 = _make_client('ws://localhost:8642/A', 0.10, Script() |
|
|
|
+ {'action': 'login', 'username': 'Dandy'} |
|
|
|
- {'kind': 'update', 'users': ['Dandy'], 'info': 'Welcome to /A', 'username': 'Dandy'} |
|
|
|
+ {'action': 'post', 'text': 'Hi'} |
|
|
|
- {'kind': 'post', 'source': 'Dandy', 'text': 'Hi'} |
|
|
|
+ {'kind': 'login', 'value': 'Dandy'} |
|
|
|
- {'kind': 'login', 'value': 'Dandy', 'online': ['Dandy']} |
|
|
|
- {'kind': 'post', 'value': 'Welcome to /A'} |
|
|
|
+ {'kind': 'post', 'value': 'Hi', 'source': 'Dandy'} |
|
|
|
- {'kind': 'post', 'value': 'Hi', 'source': 'Dandy'} |
|
|
|
) |
|
|
|
client2 = _make_client('ws://localhost:8642/B', 0.10, Script() |
|
|
|
+ {'action': 'login', 'username': 'Dandy'} |
|
|
|
- {'kind': 'update', 'users': ['Dandy'], 'info': 'Welcome to /B', 'username': 'Dandy'} |
|
|
|
+ {'action': 'post', 'text': 'Howdy'} |
|
|
|
- {'kind': 'post', 'source': 'Dandy', 'text': 'Howdy'} |
|
|
|
+ {'kind': 'login', 'value': 'Dandy'} |
|
|
|
- {'kind': 'login', 'value': 'Dandy', 'online': ['Dandy']} |
|
|
|
- {'kind': 'post', 'value': 'Welcome to /B'} |
|
|
|
+ {'kind': 'post', 'value': 'Hi', 'source': 'Dandy'} |
|
|
|
- {'kind': 'post', 'value': 'Hi', 'source': 'Dandy'} |
|
|
|
) |
|
|
|
return _test(client1, client2) |
|
|
|
|
|
|
|
|
|
|
|
def test_private_message(): |
|
|
|
client1 = _make_client('ws://localhost:8642/', 0.10, Script() |
|
|
|
+ {'action': 'login', 'username': 'Norman'} |
|
|
|
- {'kind': 'update', 'users': ['Norman'], 'info': 'Welcome to /', 'username': 'Norman'} |
|
|
|
- {'kind': 'update', 'users': ['Norman', 'Ray'], 'info': 'Ray joined'} |
|
|
|
- {'kind': 'update', 'users': ['Emma', 'Norman', 'Ray'], 'info': 'Emma joined'} |
|
|
|
+ {'action': 'post', 'target': 'Emma', 'text': 'なに?'} |
|
|
|
- {'kind': 'post', 'source': 'Norman', 'text': 'なに?'} |
|
|
|
- {'kind': 'update', 'users': ['Norman', 'Ray'], 'info': 'Emma left'} |
|
|
|
+ {'kind': 'login', 'value': 'Norman'} |
|
|
|
- {'kind': 'login', 'value': 'Norman', 'online': ['Norman']} |
|
|
|
- {'kind': 'post', 'value': 'Welcome to /'} |
|
|
|
- {'kind': 'post', 'value': 'Ray joined', 'online': ['Norman', 'Ray']} |
|
|
|
- {'kind': 'post', 'value': 'Emma joined', 'online': ['Norman', 'Ray', 'Emma']} |
|
|
|
+ {'kind': 'post', 'value': 'なに?', 'target': 'Emma'} |
|
|
|
- {'kind': 'post', 'value': 'なに?', 'source': 'Norman'} |
|
|
|
) |
|
|
|
client2 = _make_client('ws://localhost:8642/', 0.11, Script() |
|
|
|
+ {'action': 'login', 'username': 'Ray'} |
|
|
|
- {'kind': 'update', 'users': ['Norman', 'Ray'], 'info': 'Welcome to /', 'username': 'Ray'} |
|
|
|
- {'kind': 'update', 'users': ['Emma', 'Norman', 'Ray'], 'info': 'Emma joined'} |
|
|
|
- {'kind': 'update', 'users': ['Norman', 'Ray'], 'info': 'Emma left'} |
|
|
|
- {'kind': 'update', 'users': ['Ray'], 'info': 'Norman left'} |
|
|
|
+ {'kind': 'login', 'value': 'Ray'} |
|
|
|
- {'kind': 'login', 'value': 'Ray', 'online': ['Norman', 'Ray']} |
|
|
|
- {'kind': 'post', 'value': 'Welcome to /'} |
|
|
|
- {'kind': 'post', 'value': 'Emma joined', 'online': ['Norman', 'Ray', 'Emma']} |
|
|
|
- {'kind': 'post', 'value': '秘密!', 'source': 'Emma'} |
|
|
|
- {'kind': 'post', 'value': 'Norman left', 'online': ['Ray', 'Emma']} |
|
|
|
) |
|
|
|
client3 = _make_client('ws://localhost:8642/', 0.12, Script() |
|
|
|
+ {'action': 'login', 'username': 'Emma'} |
|
|
|
- {'kind': 'update', 'users': ['Emma', 'Norman', 'Ray'], 'info': 'Welcome to /', 'username': 'Emma'} |
|
|
|
- {'kind': 'post', 'source': 'Norman', 'text': 'なに?'} |
|
|
|
+ {'kind': 'login', 'value': 'Emma'} |
|
|
|
- {'kind': 'login', 'value': 'Emma', 'online': ['Norman', 'Ray', 'Emma']} |
|
|
|
- {'kind': 'post', 'value': 'Welcome to /'} |
|
|
|
- {'kind': 'post', 'value': 'なに?', 'source': 'Norman'} |
|
|
|
+ {'kind': 'post', 'value': '秘密!', 'target': 'Ray'} |
|
|
|
- {'kind': 'post', 'value': '秘密!', 'source': 'Emma'} |
|
|
|
- {'kind': 'post', 'value': 'Norman left', 'online': ['Ray', 'Emma']} |
|
|
|
- {'kind': 'post', 'value': 'Ray left', 'online': ['Emma']} |
|
|
|
) |
|
|
|
return _test(client1, client2, client3) |
|
|
|
|