Skip to content

Commit

Permalink
change render_factory to silently ignore missing place be. add test f…
Browse files Browse the repository at this point in the history
…or RenderName.BE_GEOJSON. (#96)

part of #93
  • Loading branch information
TomGoBravo authored Sep 20, 2023
1 parent f0f13eb commit 0e81663
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
8 changes: 4 additions & 4 deletions tourist/render_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,10 +289,10 @@ def get_all(cls):
value_str=geojson.dumps(geojson_feature_collection))

be_place = tstore.Place.query.filter_by(short_name='be').first()
be_geojson_feature_collection = _build_be_geojson_feature_collection(be_place)

yield tstore.RenderCache(name=RenderName.BE_GEOJSON.value,
value_str=geojson.dumps(be_geojson_feature_collection))
if be_place:
be_geojson_feature_collection = _build_be_geojson_feature_collection(be_place)
yield tstore.RenderCache(name=RenderName.BE_GEOJSON.value,
value_str=geojson.dumps(be_geojson_feature_collection))

si = io.StringIO()
cw = csv.DictWriter(si, extrasaction='ignore',
Expand Down
32 changes: 30 additions & 2 deletions tourist/tests/test_render_factory.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import geojson
from geoalchemy2 import WKTElement

import tourist
Expand Down Expand Up @@ -43,10 +44,37 @@ def test_geojson(test_app):
tourist.update_render_cache(tstore.db.session)

with test_app.app_context():
collection = render_factory._build_geojson_feature_collection(tstore.Place.query.all(),
tstore.Pool.query.all())
collection = geojson.loads(render_factory.get_string(
render_factory.RenderName.POOLS_GEOJSON))

titles = set(f['properties']['title'] for f in collection['features'])
# Check that the collection contains the pool with geometry and metro without a pool.
assert titles == {'Pool Geo Ref', 'Metro No Pool'}


def test_be_geojson(test_app):
with test_app.app_context():
world = tstore.Place(name='World', short_name='world', region=polygon1, markdown='')
country = tstore.Place(name='Belgium', short_name='be', parent=world, region=polygon1,
markdown='')
metro_with_pool = tstore.Place(
name='Metro With Pool',
short_name='metro_with_pool',
parent=country,
region=polygon1,
markdown='',
)
poolgeoref = tstore.Pool(name='Pool Geo Ref', short_name='poolgeoref',
parent=metro_with_pool, markdown='', entrance=point1)
club = tstore.Club(name='Our Club', short_name='our_club', parent=metro_with_pool,
markdown='plays at [[poolgeoref]]')
tstore.db.session.add_all([world, country, metro_with_pool, poolgeoref, club])
tstore.db.session.commit()
tourist.update_render_cache(tstore.db.session)

with test_app.app_context():
collection = geojson.loads(render_factory.get_string(render_factory.RenderName.BE_GEOJSON))

titles = set(f['properties']['title'] for f in collection['features'])
assert titles == {'Our Club'}

0 comments on commit 0e81663

Please sign in to comment.