diff --git a/nilmdb/client/client.py b/nilmdb/client/client.py index 31ccf66..c82e000 100644 --- a/nilmdb/client/client.py +++ b/nilmdb/client/client.py @@ -159,7 +159,7 @@ class Client(object): so it will be broken into reasonably-sized chunks and start/end will be deduced if missing.""" with self.stream_insert_context(path, start, end) as ctx: - if isinstance(data, str): + if isinstance(data, bytes): ctx.insert(data) else: for chunk in data: diff --git a/tests/test_client.py b/tests/test_client.py index 22813e5..4e11dc7 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -291,22 +291,32 @@ class TestClient(object): ">= end time 1332511201000000", str(e.exception)) is not None) + def check_data(): + # Verify the intervals. Should be just one, even if the data + # was inserted in chunks, due to nilmdb interval concatenation. + intervals = list(client.stream_intervals("/newton/prep")) + eq_(intervals, [[start, start + 119999777]]) + + # Try some overlapping data -- just insert it again + data = timestamper.TimestamperRate(testfile, start, 120) + with assert_raises(ClientError) as e: + result = client.stream_insert("/newton/prep", data) + in_("400 Bad Request", str(e.exception)) + in_("verlap", str(e.exception)) + # Now do the real load data = timestamper.TimestamperRate(testfile, start, 120) result = client.stream_insert("/newton/prep", data, start, start + 119999777) + check_data() - # Verify the intervals. Should be just one, even if the data - # was inserted in chunks, due to nilmdb interval concatenation. - intervals = list(client.stream_intervals("/newton/prep")) - eq_(intervals, [[start, start + 119999777]]) - - # Try some overlapping data -- just insert it again + # Try inserting directly-passed data + client.stream_remove("/newton/prep", start, start + 119999777) data = timestamper.TimestamperRate(testfile, start, 120) - with assert_raises(ClientError) as e: - result = client.stream_insert("/newton/prep", data) - in_("400 Bad Request", str(e.exception)) - in_("verlap", str(e.exception)) + data_bytes = b''.join(data) + result = client.stream_insert("/newton/prep", data_bytes, + start, start + 119999777) + check_data() nilmdb.client.client.StreamInserter._max_data = old_max_data client.close()