From 7f1c744ca4473148fcd96976e636ad56258e444a Mon Sep 17 00:00:00 2001 From: F483 Date: Thu, 20 Aug 2015 15:37:55 +0200 Subject: [PATCH] added get address api call --- Makefile | 5 +++++ dataserv/app.py | 5 +++++ tests/test_App.py | 7 +++++++ 3 files changed, 17 insertions(+) diff --git a/Makefile b/Makefile index 740a001..ebac8e6 100644 --- a/Makefile +++ b/Makefile @@ -13,6 +13,7 @@ help: @echo "Some usefull development shortcuts." @echo " clean Remove all generated files." @echo " setup Setup development environment." + @echo " shell Open ipython from the development environment." @echo " test Run tests and analysis tools." @echo " wheel Build package wheel and save in '$(WHEEL_DIR)'." @echo " wheels Build dependencie wheels and save in '$(WHEEL_DIR)'." @@ -50,6 +51,10 @@ setup: virtualenv $(PIP) install $(USE_WHEEL) -r develop_requirements.txt +shell: setup + env/bin/ipython + + test: setup $(PY) setup.py test diff --git a/dataserv/app.py b/dataserv/app.py index f3c86d6..0dc422d 100644 --- a/dataserv/app.py +++ b/dataserv/app.py @@ -93,6 +93,11 @@ def ping(btc_addr): return make_response(error_msg.format(msg), 404) +@app.route('/api/address', methods=["GET"]) +def get_address(): + return jsonify({ "address": app.config["ADDRESS"] }) + + @app.route('/api/online', methods=["GET"]) def online(): # this could be formatted a bit better, but we just want to publicly display diff --git a/tests/test_App.py b/tests/test_App.py index ab360a5..c05d932 100644 --- a/tests/test_App.py +++ b/tests/test_App.py @@ -1,4 +1,5 @@ import unittest +import json from btctxstore import BtcTxStore from dataserv.run import app, db from dataserv.app import secs_to_mins, online_farmers @@ -192,6 +193,12 @@ def test_farmer_order(self): farmers = online_farmers() self.assertEqual(farmers[0].btc_addr, addr1) + def test_get_address(self): + rv = self.app.get('/api/address') + self.assertEqual(rv.status_code, 200) + data = rv.data.decode("utf-8") + self.assertEqual(app.config["ADDRESS"], json.loads(data)["address"]) + class AppAuthenticationHeadersTest(unittest.TestCase):