Skip to content

Commit

Permalink
Changed App2.py to Run.py
Browse files Browse the repository at this point in the history
  • Loading branch information
super3 committed Jul 2, 2015
1 parent 728ab30 commit 658e169
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 21 deletions.
4 changes: 2 additions & 2 deletions dataserv/Contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -80,4 +80,4 @@ def list_contracts(self):
"contracts": json_contracts
}

return payload_template
return payload_template
2 changes: 1 addition & 1 deletion dataserv/Farmer.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
14 changes: 1 addition & 13 deletions dataserv/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


# Import modules
from dataserv.app2 import app, db
from dataserv.run import app, db
from dataserv.Farmer import Farmer


Expand Down Expand Up @@ -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
)
20 changes: 20 additions & 0 deletions dataserv/run.py
Original file line number Diff line number Diff line change
@@ -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
)
10 changes: 6 additions & 4 deletions tests/test_App.py
Original file line number Diff line number Diff line change
@@ -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):

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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'
Expand All @@ -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)
self.assertEqual(rv.status_code, 400)
2 changes: 1 addition & 1 deletion tests/test_Contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
self.assertRaises(ValueError, con2.new_contract('ad797d10dc8e12e8553f370e', 1024))

0 comments on commit 658e169

Please sign in to comment.