Skip to content

Commit

Permalink
Add test for additional tile type
Browse files Browse the repository at this point in the history
  • Loading branch information
keller-mark committed Jun 17, 2020
1 parent b5718ae commit dec93a9
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
1 change: 1 addition & 0 deletions tilesets/json_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"type": "array",
"items": {
"type": "object",
"required": ["tilesetUid", "tileIds"],
"properties": {
"tilesetUid": { "type": "string" },
"tileIds": { "type": "array", "items": { "type": "string" }},
Expand Down
20 changes: 19 additions & 1 deletion tilesets/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
)
Expand Down Expand Up @@ -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):
Expand Down
10 changes: 6 additions & 4 deletions tilesets/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit dec93a9

Please sign in to comment.