Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More tests for Legend ON/OFF - do not use requestReady #60

Merged
merged 1 commit into from
Jan 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions test/test_legend_onoff.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,29 @@ def test_categorized_symbol(client):
# same colors as the first request - the legend has been well reset
assert len(colors) == default_color_numbers, f'{len(colors)} != {default_color_numbers}'

# REQUEST with new loaded project (no cache)
qs = dict(BASE_QUERY)
qs['LAYERS'] = 'categorized'
qs['LEGEND_ON'] = 'categorized:1'
qs['LEGEND_OFF'] = 'categorized:0,2,3,4'
rv = client.get(_build_query_string(qs), PROJECT)
assert rv.status_code == 200
assert rv.headers.get('Content-Type', '').find('image/png') == 0

img = Image.open(io.BytesIO(rv.content))
# save image for debugging
# img.save(client.datapath.join('legend_categorized_onoff.png').strpath)
assert img.format == 'PNG'
assert img.width == 550
assert img.height == 408
# remove transparency to reduce the number of colors
img = img.convert('RGB')
colors = img.getcolors(1024)
assert colors is not None
colors.sort(key=lambda color: color[0], reverse=True)
# less colors because 1 feature displayed
assert len(colors) < default_color_numbers, f'not {len(colors)} < {default_color_numbers}'


def test_simple_rule_based(client):
""" Test rule based layer, simple conversion from categorized. """
Expand Down Expand Up @@ -159,3 +182,26 @@ def test_simple_rule_based(client):
colors.sort(key=lambda color: color[0], reverse=True)
# same colors as the first request - the legend has been well reset
assert len(colors) == default_color_numbers, f'{len(colors)} != {default_color_numbers}'

# REQUEST with new loaded project (no cache)
qs = dict(BASE_QUERY)
qs['LAYERS'] = 'rule_based'
qs['LEGEND_ON'] = 'rule_based:{49db22fd-3aed-495d-9140-4b82f50fdcfd}'
qs['LEGEND_OFF'] = 'rule_based:{1e75ef9b-1c18-46c1-b7f7-b16efc5bb791},{37b9b766-5309-4617-b0a4-1122168cbfd0},{bd0ace82-eee5-46c3-ad70-f8ecb7d50bb3},{77b34ffc-2198-4450-8e4d-270df282a81b}'
rv = client.get(_build_query_string(qs), PROJECT)
assert rv.status_code == 200
assert rv.headers.get('Content-Type', '').find('image/png') == 0

img = Image.open(io.BytesIO(rv.content))
# save image for debugging
# img.save(client.datapath.join('legend_rule_based_onoff.png').strpath)
assert img.format == 'PNG'
assert img.width == 550
assert img.height == 408
# remove transparency to reduce the number of colors
img = img.convert('RGB')
colors = img.getcolors(1024)
assert colors is not None
colors.sort(key=lambda color: color[0], reverse=True)
# less colors because 1 feature displayed
assert len(colors) < default_color_numbers, f'not {len(colors)} < {default_color_numbers}'
Loading