Fix Client.fetch_image_url in some cases
Sometimes (or always?), jsmods require includes a JS version specifier. This means we couldn't find the url
This commit is contained in:
@@ -24,6 +24,8 @@ def parse_server_js_define(html: str) -> Mapping[str, Any]:
|
||||
# Find points where we should start parsing
|
||||
define_splits = SERVER_JS_DEFINE_REGEX.split(html)
|
||||
|
||||
# TODO: Extract jsmods "require" and "define" from `bigPipe.onPageletArrive`?
|
||||
|
||||
# Skip leading entry
|
||||
_, *define_splits = define_splits
|
||||
|
||||
|
@@ -63,16 +63,19 @@ def generate_offline_threading_id():
|
||||
return str(int(msgs, 2))
|
||||
|
||||
|
||||
def remove_version_from_module(module):
|
||||
return module.split("@", 1)[0]
|
||||
|
||||
|
||||
def get_jsmods_require(require) -> Mapping[str, Sequence[Any]]:
|
||||
rtn = {}
|
||||
for item in require:
|
||||
if len(item) == 1:
|
||||
(module,) = item
|
||||
rtn[module] = []
|
||||
rtn[remove_version_from_module(module)] = []
|
||||
continue
|
||||
method = "{}.{}".format(item[0], item[1])
|
||||
requirements = item[2]
|
||||
arguments = item[3]
|
||||
module, method, requirements, arguments = item
|
||||
method = "{}.{}".format(remove_version_from_module(module), method)
|
||||
rtn[method] = arguments
|
||||
return rtn
|
||||
|
||||
|
@@ -46,11 +46,6 @@ def test_undocumented(client):
|
||||
client.fetch_unseen()
|
||||
|
||||
|
||||
@pytest.mark.skip(reason="need a way to get an image id")
|
||||
def test_fetch_image_url(client):
|
||||
client.fetch_image_url("TODO")
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def open_resource(pytestconfig):
|
||||
def get_resource_inner(filename):
|
||||
@@ -60,6 +55,14 @@ def open_resource(pytestconfig):
|
||||
return get_resource_inner
|
||||
|
||||
|
||||
def test_upload_and_fetch_image_url(client, open_resource):
|
||||
with open_resource("image.png") as f:
|
||||
((id, mimetype),) = client.upload([("image.png", f, "image/png")])
|
||||
assert mimetype == "image/png"
|
||||
|
||||
assert client.fetch_image_url(id).startswith("http")
|
||||
|
||||
|
||||
def test_upload_image(client, open_resource):
|
||||
with open_resource("image.png") as f:
|
||||
_ = client.upload([("image.png", f, "image/png")])
|
||||
|
@@ -68,6 +68,17 @@ def test_get_jsmods_require():
|
||||
}
|
||||
|
||||
|
||||
def test_get_jsmods_require_version_specifier():
|
||||
data = [
|
||||
["DimensionTracking@1234"],
|
||||
["CavalryLoggerImpl@2345", "startInstrumentation", [], []],
|
||||
]
|
||||
assert get_jsmods_require(data) == {
|
||||
"DimensionTracking": [],
|
||||
"CavalryLoggerImpl.startInstrumentation": [],
|
||||
}
|
||||
|
||||
|
||||
def test_get_jsmods_require_get_image_url():
|
||||
data = [
|
||||
[
|
||||
|
Reference in New Issue
Block a user