Skip to content

Commit

Permalink
Merge pull request #60 from rldhont/tests-legend-onoff
Browse files Browse the repository at this point in the history
More tests for Legend ON/OFF - do not use requestReady
  • Loading branch information
rldhont authored Jan 29, 2024
2 parents 43a4a42 + bc4aa29 commit d6de120
Showing 1 changed file with 46 additions and 0 deletions.
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}'

0 comments on commit d6de120

Please sign in to comment.