Skip to content

Commit

Permalink
Merge pull request #101 from oceanprotocol/fix/remove-srting-issue
Browse files Browse the repository at this point in the history
Remove issue returning string instead of object
  • Loading branch information
eruizgar91 authored Nov 14, 2018
2 parents 5fc567d + e4c95b9 commit bdbd4c7
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.1.2
current_version = 0.1.3

[bumpversion:file:setup.cfg]

Expand Down
17 changes: 10 additions & 7 deletions aquarius/app/assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from datetime import datetime

import pytz
from flask import Blueprint, jsonify, request
from flask import Blueprint, request
from oceandb_driver_interface.search_model import QueryModel, FullTextModel

from aquarius.app.dao import Dao
Expand Down Expand Up @@ -34,7 +34,7 @@ def get_assets():
asset_with_id = dao.get_assets()
asset_ids = [a['id'] for a in asset_with_id]
resp_body = dict({'ids': asset_ids})
return jsonify(resp_body), 200
return _sanitize_record(resp_body), 200


@assets.route('/ddo/<id>', methods=['GET'])
Expand All @@ -57,7 +57,7 @@ def get_ddo(id):
"""
try:
asset_record = dao.get(id)
return jsonify(asset_record), 200
return _sanitize_record(asset_record), 200
except Exception as e:
logging.error(e)
return '"%s asset_id is not in OceanDB' % id, 404
Expand Down Expand Up @@ -89,7 +89,7 @@ def get_metadata(id):
i = i + 1
if service['type'] == 'Metadata':
metadata = asset_record['service'][i]
return jsonify(metadata), 200
return _sanitize_record(metadata), 200
except Exception as e:
logging.error(e)
return '"%s asset_id is not in OceanDB' % id, 404
Expand Down Expand Up @@ -441,7 +441,9 @@ def get_asset_ddos():
args.append(query)
assets_with_id = dao.get_assets()
assets_metadata = {a['id']: a for a in assets_with_id}
return jsonify(json.dumps(assets_metadata)), 200
for i in assets_metadata:
_sanitize_record(i)
return json.dumps(assets_metadata), 200


@assets.route('/ddo/query', methods=['GET'])
Expand Down Expand Up @@ -482,9 +484,10 @@ def query_text():
offset=int(data.get('offset', 100)),
page=int(data.get('page', 0)))
query_result = dao.query(search_model)

for i in query_result:
_sanitize_record(i)
return jsonify(json.dumps(query_result)), 200
return json.dumps(query_result), 200


@assets.route('/ddo/query', methods=['POST'])
Expand Down Expand Up @@ -537,7 +540,7 @@ def query_ddo():
query_result = dao.query(search_model)
for i in query_result:
_sanitize_record(i)
return jsonify(json.dumps(query_result)), 200
return json.dumps(query_result), 200


def _sanitize_record(data_record):
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.1.2
current_version = 0.1.3
commit = True
tag = True

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,6 @@
test_suite='tests',
tests_require=test_requirements,
url='https://github.com/oceanprotocol/aquarius',
version='0.1.2',
version='0.1.3',
zip_safe=False,
)
8 changes: 4 additions & 4 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,14 @@ def test_query_metadata(client):
content_type='application/json')
assert len(json.loads(client.post(BaseURLs.BASE_AQUARIUS_URL + '/assets/ddo/query',
data=json.dumps({"query": {}}),
content_type='application/json').json)) == 2
content_type='application/json').data.decode('utf-8'))) == 2
assert len(json.loads(client.post(BaseURLs.BASE_AQUARIUS_URL + '/assets/ddo/query',
data=json.dumps({"query": {"id": "did:op:123456789abcdefghi"}}),
content_type='application/json').json)) == 1
content_type='application/json').data.decode('utf-8'))) == 1
assert len(json.loads(client.get(BaseURLs.BASE_AQUARIUS_URL + '/assets/ddo/query?text=Office',
).json)) == 2
).data.decode('utf-8'))) == 2
assert len(json.loads(client.get(BaseURLs.BASE_AQUARIUS_URL + '/assets/ddo/query?text=112233445566778899',
).json)) == 1
).data.decode('utf-8'))) == 1
client.delete(BaseURLs.BASE_AQUARIUS_URL + '/assets/ddo/%s' % json.loads(post.data.decode('utf-8'))['id'])
client.delete(
BaseURLs.BASE_AQUARIUS_URL + '/assets/ddo/%s' % json.loads(post2.data.decode('utf-8'))['id'])

0 comments on commit bdbd4c7

Please sign in to comment.