From dec93a907f918a8444941d6f263a761d7e3d100c Mon Sep 17 00:00:00 2001 From: mkeller <7525285+keller-mark@users.noreply.github.com> Date: Wed, 17 Jun 2020 19:57:12 -0400 Subject: [PATCH] Add test for additional tile type --- tilesets/json_schemas.py | 1 + tilesets/tests.py | 20 +++++++++++++++++++- tilesets/views.py | 10 ++++++---- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/tilesets/json_schemas.py b/tilesets/json_schemas.py index 88af7f2a..e5284864 100644 --- a/tilesets/json_schemas.py +++ b/tilesets/json_schemas.py @@ -25,6 +25,7 @@ "type": "array", "items": { "type": "object", + "required": ["tilesetUid", "tileIds"], "properties": { "tilesetUid": { "type": "string" }, "tileIds": { "type": "array", "items": { "type": "string" }}, diff --git a/tilesets/tests.py b/tilesets/tests.py index 7755ae14..26bfd687 100644 --- a/tilesets/tests.py +++ b/tilesets/tests.py @@ -499,7 +499,7 @@ def test_get_tile(self): assert q.shape[0] == 512 - def test_get_tile_with_aggregation(self): + def test_get_tiles_via_post_with_aggregation(self): self.user1 = dcam.User.objects.create_user( username='user1', password='pass' ) @@ -1005,6 +1005,24 @@ def test_get_tiles(self): except OSError: pass + def test_get_tiles_via_post(self): + c1 = dt.Client() + c1.login(username='user1', password='pass') + + body = [ + { + "tilesetUid": "bb", + "tileIds": ["14.12"] + } + ] + + ret = c1.post('/api/v1/tiles/', json.dumps(body), content_type="application/json") + assert ret.status_code == 200 + content = json.loads(ret.content.decode('utf-8')) + content_len = len(content['bb.14.12']) + + assert content_len == 200 + class CoolerTest(dt.TestCase): def setUp(self): diff --git a/tilesets/views.py b/tilesets/views.py index 28fe1999..4a766b80 100644 --- a/tilesets/views.py +++ b/tilesets/views.py @@ -426,10 +426,12 @@ def tiles(request): tile_ids = [ f"{tileset_uid}.{tile_id}" for tile_id in tileset_info["tileIds"] ] tileids_to_fetch.update(tile_ids) - tileset_options = tileset_info["options"] - tileset_to_options[tileset_uid] = tileset_options - # Hash the options object so that the tile can be cached. - tileset_to_options[tileset_uid]["options_hash"] = hashlib.md5(json.dumps(tileset_options).encode('utf-8')).hexdigest() + tileset_options = tileset_info.get("options", None) + # The "options" property is optional. + if type(tileset_options) == dict: + tileset_to_options[tileset_uid] = tileset_options + # Hash the options object so that the tile can be cached. + tileset_to_options[tileset_uid]["options_hash"] = hashlib.md5(json.dumps(tileset_options).encode('utf-8')).hexdigest() elif request.method == 'GET': # create a set so that we don't fetch the same tile multiple times