Browse Source

Improve coverage for client

tags/nilmdb-2.0.0
Jim Paris 2 years ago
parent
commit
349eec3942
2 changed files with 21 additions and 11 deletions
  1. +1
    -1
      nilmdb/client/client.py
  2. +20
    -10
      tests/test_client.py

+ 1
- 1
nilmdb/client/client.py View File

@@ -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:


+ 20
- 10
tests/test_client.py View File

@@ -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()


Loading…
Cancel
Save