Skip to content

Commit

Permalink
Make JSON Call Instead
Browse files Browse the repository at this point in the history
  • Loading branch information
super3 committed Aug 13, 2015
1 parent f6fbacf commit 1228517
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 3 additions & 2 deletions dataserv/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import sys
import os.path
import datetime
from flask import make_response
from flask import make_response, jsonify
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))

# Import modules
Expand Down Expand Up @@ -107,8 +107,9 @@ def total():
# return in TB the number
app.config["BYTE_SIZE"] = 1024*1024*128
result = total_shards * (app.config["BYTE_SIZE"] / (1024*1024*1024*1024)) # bytes / 1 TB
json_data = {'total_TB': round(result, 2)}

return "{0} TB".format(round(result, 2))
return jsonify(json_data)


@app.route('/api/height/<btc_addr>/<int:height>', methods=["GET"])
Expand Down
4 changes: 3 additions & 1 deletion tests/test_App.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,6 @@ def test_farmer_total_bytes(self):

# check total bytes
rv = self.app.get('/api/total')
self.assertEqual(b"1.22 TB", rv.data)
json_data = b'{\n "total_TB": 1.22\n}'

self.assertEqual(json_data, rv.data)

0 comments on commit 1228517

Please sign in to comment.