Changeset View
Changeset View
Standalone View
Standalone View
swh/graphql/tests/functional/test_origin_node.py
Show All 16 Lines | query_str = """ | ||||
} | } | ||||
} | } | ||||
""" | """ | ||||
assert_missing_object(client, query_str, "origin") | assert_missing_object(client, query_str, "origin") | ||||
@pytest.mark.parametrize("origin", get_origins()) | @pytest.mark.parametrize("origin", get_origins()) | ||||
def test_get(client, storage, origin): | def test_get(client, storage, origin): | ||||
query_str = f""" | query_str = ( | ||||
{{ | """ | ||||
origin(url: "{origin.url}") {{ | { | ||||
origin(url: "%s") { | |||||
url | url | ||||
id | id | ||||
visits(first: 10) {{ | visits(first: 10) { | ||||
nodes {{ | nodes { | ||||
id | id | ||||
}} | } | ||||
}} | } | ||||
latestVisit {{ | latestVisit { | ||||
visitId | visitId | ||||
}} | } | ||||
snapshots(first: 2) {{ | snapshots(first: 2) { | ||||
nodes {{ | nodes { | ||||
id | id | ||||
}} | } | ||||
}} | } | ||||
}} | } | ||||
}} | } | ||||
""" | """ | ||||
% origin.url | |||||
) | |||||
ardumont: That's what i actually proposed to you a while back but you used f-string instead ¯\_(ツ)_/¯.
I… | |||||
Done Inline ActionsThanks @ardumont . There is another issue here, The query has '{' and '}' char in the body itself, so I'm forced to use double '{' for this to work with .format or f-strings. Hence I added the old style string manipulation. jayeshv: Thanks @ardumont . There is another issue here, The query has '{' and '}' char in the body… | |||||
Not Done Inline Actionsvlorentz: @ardumont the end goal is to replace all interpolations with query variables (T4306) | |||||
Not Done Inline Actionsack ardumont: ack | |||||
response, _ = get_query_response(client, query_str) | response, _ = get_query_response(client, query_str) | ||||
data_origin = response["origin"] | data_origin = response["origin"] | ||||
storage_origin = storage.origin_get([origin.url])[0] | storage_origin = storage.origin_get([origin.url])[0] | ||||
visits_and_statuses = storage.origin_visit_get_with_statuses(origin.url).results | visits_and_statuses = storage.origin_visit_get_with_statuses(origin.url).results | ||||
assert data_origin["url"] == storage_origin.url | assert data_origin["url"] == storage_origin.url | ||||
assert data_origin["id"] == storage_origin.id.hex() | assert data_origin["id"] == storage_origin.id.hex() | ||||
assert len(data_origin["visits"]["nodes"]) == len(visits_and_statuses) | assert len(data_origin["visits"]["nodes"]) == len(visits_and_statuses) | ||||
assert data_origin["latestVisit"]["visitId"] == visits_and_statuses[-1].visit.visit | assert data_origin["latestVisit"]["visitId"] == visits_and_statuses[-1].visit.visit | ||||
snapshots = storage.origin_snapshot_get_all(origin.url) | snapshots = storage.origin_snapshot_get_all(origin.url) | ||||
assert len(data_origin["snapshots"]["nodes"]) == len(snapshots) | assert len(data_origin["snapshots"]["nodes"]) == len(snapshots) |
That's what i actually proposed to you a while back but you used f-string instead ¯\_(ツ)_/¯.
I was probably unclear.
See [1] for a concrete example you can reproduce.
That form allows to convey much more readable information especially in cases where there are multiple variables in the templated string.
But i won't push too much for this. As you want.
Cheers,
[1]
works with any strings, including """ string """ ones.