|
|
@@ -12,6 +12,7 @@ import os |
|
|
|
import sys |
|
|
|
import threading |
|
|
|
import cStringIO |
|
|
|
import simplejson as json |
|
|
|
|
|
|
|
from test_helpers import * |
|
|
|
|
|
|
@@ -167,3 +168,39 @@ class TestClient(object): |
|
|
|
result = client.stream_insert("/newton/prep", data) |
|
|
|
in_("400 Bad Request", str(e.exception)) |
|
|
|
in_("OverlapError", str(e.exception)) |
|
|
|
|
|
|
|
def test_client_4_generators(self): |
|
|
|
# A lot of the client functionality is already tested by test_cmdline, |
|
|
|
# but this gets a bit more coverage that cmdline misses. |
|
|
|
client = nilmdb.Client(url = "http://localhost:12380/") |
|
|
|
|
|
|
|
# Trigger a client error in generator |
|
|
|
start = datetime_tz.datetime_tz.smartparse("20120323T2000") |
|
|
|
end = datetime_tz.datetime_tz.smartparse("20120323T1000") |
|
|
|
with assert_raises(ClientError) as e: |
|
|
|
client.stream_intervals("/newton/prep", |
|
|
|
start.totimestamp(), |
|
|
|
end.totimestamp()).next() |
|
|
|
in_("400 Bad Request", str(e.exception)) |
|
|
|
in_("invalid interval", str(e.exception)) |
|
|
|
|
|
|
|
# Trigger a curl error in generator |
|
|
|
with assert_raises(ServerError) as e: |
|
|
|
client.http.get_gen("http://nosuchurl/").next() |
|
|
|
|
|
|
|
# Check non-json version of string output |
|
|
|
eq_(json.loads(client.http.get("/stream/list",retjson=False)), |
|
|
|
client.http.get("/stream/list",retjson=True)) |
|
|
|
|
|
|
|
# Check non-json version of generator output |
|
|
|
for (a, b) in itertools.izip( |
|
|
|
client.http.get_gen("/stream/list",retjson=False), |
|
|
|
client.http.get_gen("/stream/list",retjson=True)): |
|
|
|
eq_(json.loads(a), b) |
|
|
|
|
|
|
|
# Check PUT with generator out |
|
|
|
with assert_raises(ClientError) as e: |
|
|
|
client.http.put_gen("stream/insert", "", |
|
|
|
{ "path": "/newton/prep" }).next() |
|
|
|
in_("400 Bad Request", str(e.exception)) |
|
|
|
in_("no data provided", str(e.exception)) |