浏览代码

Redirect plain hits

master
Roderic Day 6 年前
父节点
当前提交
a0fa0e2f5d
共有 2 个文件被更改,包括 19 次插入8 次删除
  1. +11
    -0
      pico.py
  2. +8
    -8
      test.py

+ 11
- 0
pico.py 查看文件

import datetime import datetime
import http import http
import json import json
import uuid
from functools import partial from functools import partial
from pathlib import Path from pathlib import Path


document.read_bytes(), document.read_bytes(),
) )


def random_redirect(self):
new_path = str(uuid.uuid4()).split('-')[1]
return (
http.HTTPStatus.FOUND,
[('Location', new_path)],
b'',
)

async def process_request(self, path, request_headers): async def process_request(self, path, request_headers):
if path == '/':
return self.random_redirect()
if request_headers.get('Upgrade') != 'websocket': if request_headers.get('Upgrade') != 'websocket':
return self.serve_file(path) return self.serve_file(path)
return await super().process_request(path, request_headers) return await super().process_request(path, request_headers)

+ 8
- 8
test.py 查看文件





def test_name_taken(): def test_name_taken():
client1 = _make_client('ws://localhost:8642/', 0.10, Script()
client1 = _make_client('ws://localhost:8642/A', 0.10, Script()
+ {'kind': 'login', 'value': 'A'} + {'kind': 'login', 'value': 'A'}
- {'kind': 'state', 'username': 'A'} - {'kind': 'state', 'username': 'A'}
- {'kind': 'state', 'online': ['A']} - {'kind': 'state', 'online': ['A']}
- {'kind': 'state', 'online': ['A', 'B']} - {'kind': 'state', 'online': ['A', 'B']}
) )
client2 = _make_client('ws://localhost:8642/', 0.11, Script()
client2 = _make_client('ws://localhost:8642/A', 0.11, Script()
+ {'kind': 'login', 'value': 'A'} + {'kind': 'login', 'value': 'A'}
- {'kind': 'error', 'value': 'Username taken'} - {'kind': 'error', 'value': 'Username taken'}
) )
client3 = _make_client('ws://localhost:8642/', 0.12, Script()
client3 = _make_client('ws://localhost:8642/A', 0.12, Script()
+ {'kind': 'login', 'value': 'B'} + {'kind': 'login', 'value': 'B'}
- {'kind': 'state', 'username': 'B'} - {'kind': 'state', 'username': 'B'}
- {'kind': 'state', 'online': ['A', 'B']} - {'kind': 'state', 'online': ['A', 'B']}




def test_interaction(): def test_interaction():
client1 = _make_client('ws://localhost:8642/', 0.10, Script()
client1 = _make_client('ws://localhost:8642/A', 0.10, Script()
+ {'kind': 'login', 'value': 'Alice'} + {'kind': 'login', 'value': 'Alice'}
- {'kind': 'state', 'username': 'Alice'} - {'kind': 'state', 'username': 'Alice'}
- {'kind': 'state', 'online': ['Alice']} - {'kind': 'state', 'online': ['Alice']}
- {'kind': 'post', 'value': 'Hey Bob!', 'source': 'Alice'} - {'kind': 'post', 'value': 'Hey Bob!', 'source': 'Alice'}
- {'kind': 'post', 'value': 'Howdy!', 'source': 'Bob'} - {'kind': 'post', 'value': 'Howdy!', 'source': 'Bob'}
) )
client2 = _make_client('ws://localhost:8642/', 0.11, Script()
client2 = _make_client('ws://localhost:8642/A', 0.11, Script()
+ {'kind': 'login', 'value': 'Bob'} + {'kind': 'login', 'value': 'Bob'}
- {'kind': 'state', 'username': 'Bob'} - {'kind': 'state', 'username': 'Bob'}
- {'kind': 'state', 'online': ['Alice', 'Bob']} - {'kind': 'state', 'online': ['Alice', 'Bob']}




def test_private_message(): def test_private_message():
client1 = _make_client('ws://localhost:8642/', 0.10, Script()
client1 = _make_client('ws://localhost:8642/A', 0.10, Script()
+ {'kind': 'login', 'value': 'Norman'} + {'kind': 'login', 'value': 'Norman'}
- {'kind': 'state', 'username': 'Norman'} - {'kind': 'state', 'username': 'Norman'}
- {'kind': 'state', 'online': ['Norman']} - {'kind': 'state', 'online': ['Norman']}
- {'kind': 'post', 'value': '1', 'source': 'Norman'} - {'kind': 'post', 'value': '1', 'source': 'Norman'}
- {'kind': 'post', 'value': '3', 'source': 'Emma'} - {'kind': 'post', 'value': '3', 'source': 'Emma'}
) )
client2 = _make_client('ws://localhost:8642/', 0.11, Script()
client2 = _make_client('ws://localhost:8642/A', 0.11, Script()
+ {'kind': 'login', 'value': 'Ray'} + {'kind': 'login', 'value': 'Ray'}
- {'kind': 'state', 'username': 'Ray'} - {'kind': 'state', 'username': 'Ray'}
- {'kind': 'state', 'online': ['Norman', 'Ray']} - {'kind': 'state', 'online': ['Norman', 'Ray']}
- {'kind': 'post', 'value': '2', 'source': 'Ray'} - {'kind': 'post', 'value': '2', 'source': 'Ray'}
- {'kind': 'state', 'online': ['Ray', 'Emma']} - {'kind': 'state', 'online': ['Ray', 'Emma']}
) )
client3 = _make_client('ws://localhost:8642/', 0.12, Script()
client3 = _make_client('ws://localhost:8642/A', 0.12, Script()
+ {'kind': 'login', 'value': 'Emma'} + {'kind': 'login', 'value': 'Emma'}
- {'kind': 'state', 'username': 'Emma'} - {'kind': 'state', 'username': 'Emma'}
- {'kind': 'state', 'online': ['Norman', 'Ray', 'Emma']} - {'kind': 'state', 'online': ['Norman', 'Ray', 'Emma']}

正在加载...
取消
保存