diff --git a/dataserv/Contract.py b/dataserv/Contract.py index f35396d..aa18ffb 100644 --- a/dataserv/Contract.py +++ b/dataserv/Contract.py @@ -3,7 +3,7 @@ import hashlib import binascii import RandomIO -from dataserv.app2 import app, db +from dataserv.run import app, db class Contract(db.Model): @@ -80,4 +80,4 @@ def list_contracts(self): "contracts": json_contracts } - return payload_template \ No newline at end of file + return payload_template diff --git a/dataserv/Farmer.py b/dataserv/Farmer.py index b3a9122..d0a50c3 100644 --- a/dataserv/Farmer.py +++ b/dataserv/Farmer.py @@ -1,5 +1,5 @@ import hashlib -from dataserv.app2 import db +from dataserv.run import db from datetime import datetime from sqlalchemy import DateTime from dataserv.Contract import Contract diff --git a/dataserv/app.py b/dataserv/app.py index ccbfc8b..bc70607 100644 --- a/dataserv/app.py +++ b/dataserv/app.py @@ -6,7 +6,7 @@ # Import modules -from dataserv.app2 import app, db +from dataserv.run import app, db from dataserv.Farmer import Farmer @@ -128,15 +128,3 @@ def list_contracts(btc_addr): except LookupError: msg = "Farmer Not Found." return make_response(msg, 404) - - -if __name__ == '__main__': # pragma: no cover - # Create Database - db.create_all() - - # Run the Flask app - app.run( - host="0.0.0.0", - port=int("5000"), - debug=True - ) diff --git a/dataserv/run.py b/dataserv/run.py new file mode 100644 index 0000000..e97811b --- /dev/null +++ b/dataserv/run.py @@ -0,0 +1,20 @@ +from flask import Flask +from flask.ext.sqlalchemy import SQLAlchemy + + +# Initialize the Flask application +app = Flask(__name__) +app.config.from_pyfile('config.py') +db = SQLAlchemy(app) + + +if __name__ == '__main__': # pragma: no cover + # Create Database + db.create_all() + + # Run the Flask app + app.run( + host="0.0.0.0", + port=int("5000"), + debug=True + ) diff --git a/tests/test_App.py b/tests/test_App.py index fda706d..9091bc8 100644 --- a/tests/test_App.py +++ b/tests/test_App.py @@ -1,7 +1,8 @@ import json import unittest +from dataserv.run import app, db from dataserv.app import secs_to_mins -from dataserv.app2 import app, db + class AppTest(unittest.TestCase): @@ -137,7 +138,7 @@ def test_new_contract_fail(self): def test_max_contracts(self): addr = '191GVvAaTRxLmz3rW3nU5jAV1rF186VxQc' - rv = self.app.get('/api/register/{0}'.format(addr)) + self.app.get('/api/register/{0}'.format(addr)) # force app config to testing params app.config["BYTE_SIZE"] = 10*1024*1024 # 10 MB @@ -151,7 +152,7 @@ def test_max_contracts(self): def test_list_contracts(self): addr = '191GVvAaTRxLmz3rW3nU5jAV1rF186VxQc' - rv = self.app.get('/api/register/{0}'.format(addr)) + self.app.get('/api/register/{0}'.format(addr)) # force app config to testing params app.config["BYTE_SIZE"] = 10*1024*1024 # 10 MB @@ -162,6 +163,7 @@ def test_list_contracts(self): self.app.get('/api/contract/new/{0}'.format(addr)) rv = self.app.get('/api/contract/list/{0}'.format(addr)) + self.assertEqual(rv.status_code, 200) def test_list_contract_no_register(self): addr = '191GVvAaTRxLmz3rW3nU5jAV1rF186VxQc' @@ -171,4 +173,4 @@ def test_list_contract_no_register(self): def test_list_contract_no_bad_address(self): addr = 'notvalidaddress' rv = self.app.get('/api/contract/list/{0}'.format(addr)) - self.assertEqual(rv.status_code, 400) \ No newline at end of file + self.assertEqual(rv.status_code, 400) diff --git a/tests/test_Contract.py b/tests/test_Contract.py index 47903dc..e0698e3 100644 --- a/tests/test_Contract.py +++ b/tests/test_Contract.py @@ -71,4 +71,4 @@ def test_address_errors(self): con2 = Contract(addr2) self.assertRaises(LookupError, con1.new_contract('ba17da75c580a0749b6c3d32', 1024)) - self.assertRaises(ValueError, con2.new_contract('ad797d10dc8e12e8553f370e', 1024)) \ No newline at end of file + self.assertRaises(ValueError, con2.new_contract('ad797d10dc8e12e8553f370e', 1024))