Skip to content

Commit

Permalink
Travis Fix 3 + Extra Code
Browse files Browse the repository at this point in the history
  • Loading branch information
super3 committed Jun 24, 2015
1 parent 43e2f51 commit beb3f08
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
4 changes: 4 additions & 0 deletions dataserv/Contract.py
Expand Up @@ -43,6 +43,10 @@ def new_contract(self, seed=None, byte_size=None):
"""Build a new contract."""
self.contract_type = 0

# make sure that farmer can actually create new contracts
if not self.below_limit():
raise MemoryError("Contract Capacity Limit Reached.")

# take in a seed, if not generate it ourselves
if seed is None:
seed = os.urandom(12)
Expand Down
9 changes: 6 additions & 3 deletions dataserv/app.py
@@ -1,7 +1,7 @@
import sys
import os.path
import datetime
from flask import make_response, jsonify
from flask import Flask, make_response, jsonify
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))


Expand Down Expand Up @@ -62,7 +62,7 @@ def ping(btc_addr):
msg = "Invalid BTC Address."
return make_response(error_msg.format(msg), 400)
except LookupError:
msg = "Farmer not found."
msg = "Farmer Not Found."
return make_response(error_msg.format(msg), 404)


Expand Down Expand Up @@ -107,8 +107,11 @@ def new_contract(btc_addr):
msg = "Invalid BTC Address."
return make_response(error_msg.format(msg), 400)
except LookupError:
msg = "Farmer not found."
msg = "Farmer Not Found."
return make_response(error_msg.format(msg), 404)
except MemoryError:
msg = "Contract Capacity Limit Reached."
return make_response(error_msg.format(msg), 413)


if __name__ == '__main__': # pragma: no cover
Expand Down
2 changes: 1 addition & 1 deletion tests/test_App.py
Expand Up @@ -64,7 +64,7 @@ def test_ping_not_found(self):
rv = self.app.get('/api/ping/{0}'.format(addr))

# good ping
self.assertEqual(b"Ping Failed: Farmer not found.", rv.data)
self.assertEqual(b"Ping Failed: Farmer Not Found.", rv.data)
self.assertEqual(rv.status_code, 404)

def test_ping_invalid_address(self):
Expand Down
5 changes: 5 additions & 0 deletions tests/test_Contract.py
Expand Up @@ -57,3 +57,8 @@ def test_contract_limit(self):
con3.new_contract('b780bd4852b8c8a62859a50c', 1024)
self.assertFalse(con3.below_limit(2000))
self.assertTrue(con3.below_limit(3073))

# change config to break limit
app.config["BYTE_FARMER_MAX"] = 1024
with self.assertRaises(MemoryError):
con3.new_contract('b780bd4852b8c8a62859a50c', 1024)

0 comments on commit beb3f08

Please sign in to comment.