Пример #1
0
def test_parse_server_js_define_error():
    with pytest.raises(ParseError, match="Could not find any"):
        parse_server_js_define("")

    html = 'function(){(require("ServerJSDefine")).handleDefines([{"a": function(){}}])'
    with pytest.raises(ParseError, match="Invalid"):
        parse_server_js_define(html + html)

    html = 'function(){require("ServerJSDefine").handleDefines({"a": "b"})'
    with pytest.raises(ParseError, match="Invalid"):
        parse_server_js_define(html + html)
Пример #2
0
def test_parse_server_js_define_new():
    html = """
    some data;require("TimeSliceImpl").guard(function(){new (require("ServerJS"))().handle({"define":[["DTSGInitialData",[],{"token":""},100]],"require":[...]});}, "ServerJS define", {"root":true})();
    more data
    <script><script>require("TimeSliceImpl").guard(function(){var s=new (require("ServerJS"))();s.handle({"define":[["DTSGInitData",[],{"token":"","async_get_token":""},3333]],"require":[...]});require("Run").onAfterLoad(function(){s.cleanup(require("TimeSliceImpl"))});}, "ServerJS define", {"root":true})();</script>
    other irrelevant data
    """
    define = parse_server_js_define(html)
    assert define == {
        "DTSGInitialData": {
            "token": ""
        },
        "DTSGInitData": {
            "async_get_token": "",
            "token": ""
        },
    }
Пример #3
0
def test_parse_server_js_define_old():
    html = """
    some data;require("TimeSliceImpl").guard(function(){(require("ServerJSDefine")).handleDefines([["DTSGInitialData",[],{"token":"123"},100]])

    <script>require("TimeSliceImpl").guard(function() {require("ServerJSDefine").handleDefines([["DTSGInitData",[],{"token":"123","async_get_token":"12345"},3333]])

    </script>
    other irrelevant data
    """
    define = parse_server_js_define(html)
    assert define == {
        "DTSGInitialData": {
            "token": "123"
        },
        "DTSGInitData": {
            "async_get_token": "12345",
            "token": "123"
        },
    }