Browse Source

rework errors

git-svn-id: https://bucket.mit.edu/svn/nilm/nilmdb@10647 ddd99763-3ecb-0310-9145-efcb8ce7c51f
tags/bxinterval-last
Jim Paris 10 years ago
parent
commit
3b696e2a03
3 changed files with 16 additions and 9 deletions
  1. +5
    -3
      nilmdb/server.py
  2. +9
    -0
      tests/test_client.py
  3. +2
    -6
      tests/test_nilmdb.py

+ 5
- 3
nilmdb/server.py View File

@@ -157,14 +157,16 @@ class Stream(NilmApp):
except TypeError:
body = ""

# Bail out if no body provided
if not body:
raise cherrypy.HTTPError("400 Bad Request", "No data provided")

# Check path and get layout
streams = self.db.stream_list(path = path)
if len(streams) != 1:
raise cherrypy.HTTPError("404 Not Found", "No such stream")
layout = streams[0][1]

if not body:
raise cherrypy.HTTPError("400 Bad Request", "No data provided")

return "ok"
raise cherrypy.HTTPError("501 Not Implemented", "Layout is: " + layout)



+ 9
- 0
tests/test_client.py View File

@@ -131,5 +131,14 @@ class TestClient(object):
testfile = "tests/data/prep-20120323T1000"
start = datetime_tz.datetime_tz.smartparse("20120323T1000")
rate = 120

# First try a nonexistent path
data = nilmdb.timestamper.TimestamperRate(testfile, start, 120)
with assert_raises(ClientError) as e:
result = client.stream_insert("/newton/no-such-path", data)
assert("404" in e.exception.status)

# Now do the real load
data = nilmdb.timestamper.TimestamperRate(testfile, start, 120)
result = client.stream_insert("/newton/prep", data)
print result

+ 2
- 6
tests/test_nilmdb.py View File

@@ -191,12 +191,8 @@ class TestServer(object):


def test_insert(self):
# invalid path first
with assert_raises(HTTPError) as e:
getjson("/stream/insert?path=/newton/")
eq_(e.exception.code, 404)

# XXX TODO
# GET instead of POST (no body)
# (actual POST test is done by client code)
with assert_raises(HTTPError) as e:
getjson("/stream/insert?path=/newton/prep")
eq_(e.exception.code, 400)

Loading…
Cancel
Save