Get the IoT plugins to pass tests on Py3

This commit is contained in:
Lance Stout 2014-02-06 09:54:45 -08:00
parent 49acdac776
commit a2423b8499
5 changed files with 262 additions and 262 deletions

View File

@ -12,51 +12,51 @@ import datetime
import logging import logging
class Device(object): class Device(object):
""" """
Example implementation of a device readout object. Example implementation of a device readout object.
Is registered in the XEP_0323.register_node call Is registered in the XEP_0323.register_node call
The device object may be any custom implementation to support The device object may be any custom implementation to support
specific devices, but it must implement the functions: specific devices, but it must implement the functions:
has_field has_field
request_fields request_fields
""" """
def __init__(self, nodeId, fields={}): def __init__(self, nodeId, fields={}):
self.nodeId = nodeId self.nodeId = nodeId
self.fields = fields # see fields described below self.fields = fields # see fields described below
# {'type':'numeric', # {'type':'numeric',
# 'name':'myname', # 'name':'myname',
# 'value': 42, # 'value': 42,
# 'unit':'Z'}]; # 'unit':'Z'}];
self.timestamp_data = {} self.timestamp_data = {}
self.momentary_data = {} self.momentary_data = {}
self.momentary_timestamp = "" self.momentary_timestamp = ""
logging.debug("Device object started nodeId %s",nodeId) logging.debug("Device object started nodeId %s",nodeId)
def has_field(self, field): def has_field(self, field):
""" """
Returns true if the supplied field name exists in this device. Returns true if the supplied field name exists in this device.
Arguments: Arguments:
field -- The field name field -- The field name
""" """
if field in self.fields.keys(): if field in self.fields.keys():
return True; return True;
return False; return False;
def refresh(self, fields): def refresh(self, fields):
""" """
override method to do the refresh work override method to do the refresh work
refresh values from hardware or other refresh values from hardware or other
""" """
pass pass
def request_fields(self, fields, flags, session, callback): def request_fields(self, fields, flags, session, callback):
""" """
Starts a data readout. Verifies the requested fields, Starts a data readout. Verifies the requested fields,
refreshes the data (if needed) and calls the callback refreshes the data (if needed) and calls the callback
with requested data. with requested data.
Arguments: Arguments:
@ -65,153 +65,153 @@ class Device(object):
Formatted as a dictionary like { "flag name": "flag value" ... } Formatted as a dictionary like { "flag name": "flag value" ... }
session -- Session id, only used in the callback as identifier session -- Session id, only used in the callback as identifier
callback -- Callback function to call when data is available. callback -- Callback function to call when data is available.
The callback function must support the following arguments: The callback function must support the following arguments:
session -- Session id, as supplied in the request_fields call session -- Session id, as supplied in the request_fields call
nodeId -- Identifier for this device nodeId -- Identifier for this device
result -- The current result status of the readout. Valid values are: result -- The current result status of the readout. Valid values are:
"error" - Readout failed. "error" - Readout failed.
"fields" - Contains readout data. "fields" - Contains readout data.
"done" - Indicates that the readout is complete. May contain "done" - Indicates that the readout is complete. May contain
readout data. readout data.
timestamp_block -- [optional] Only applies when result != "error" timestamp_block -- [optional] Only applies when result != "error"
The readout data. Structured as a dictionary: The readout data. Structured as a dictionary:
{ {
timestamp: timestamp for this datablock, timestamp: timestamp for this datablock,
fields: list of field dictionary (one per readout field). fields: list of field dictionary (one per readout field).
readout field dictionary format: readout field dictionary format:
{ {
type: The field type (numeric, boolean, dateTime, timeSpan, string, enum) type: The field type (numeric, boolean, dateTime, timeSpan, string, enum)
name: The field name name: The field name
value: The field value value: The field value
unit: The unit of the field. Only applies to type numeric. unit: The unit of the field. Only applies to type numeric.
dataType: The datatype of the field. Only applies to type enum. dataType: The datatype of the field. Only applies to type enum.
flags: [optional] data classifier flags for the field, e.g. momentary flags: [optional] data classifier flags for the field, e.g. momentary
Formatted as a dictionary like { "flag name": "flag value" ... } Formatted as a dictionary like { "flag name": "flag value" ... }
} }
} }
error_msg -- [optional] Only applies when result == "error". error_msg -- [optional] Only applies when result == "error".
Error details when a request failed. Error details when a request failed.
""" """
logging.debug("request_fields called looking for fields %s",fields) logging.debug("request_fields called looking for fields %s",fields)
if len(fields) > 0: if len(fields) > 0:
# Check availiability # Check availiability
for f in fields: for f in fields:
if f not in self.fields.keys(): if f not in self.fields.keys():
self._send_reject(session, callback) self._send_reject(session, callback)
return False; return False;
else: else:
# Request all fields # Request all fields
fields = self.fields.keys(); fields = self.fields.keys();
# Refresh data from device # Refresh data from device
# ... # ...
logging.debug("about to refresh device fields %s",fields) logging.debug("about to refresh device fields %s",fields)
self.refresh(fields) self.refresh(fields)
if "momentary" in flags and flags['momentary'] == "true" or \ if "momentary" in flags and flags['momentary'] == "true" or \
"all" in flags and flags['all'] == "true": "all" in flags and flags['all'] == "true":
ts_block = {}; ts_block = {};
timestamp = ""; timestamp = "";
if len(self.momentary_timestamp) > 0: if len(self.momentary_timestamp) > 0:
timestamp = self.momentary_timestamp; timestamp = self.momentary_timestamp;
else: else:
timestamp = self._get_timestamp(); timestamp = self._get_timestamp();
field_block = []; field_block = [];
for f in self.momentary_data: for f in self.momentary_data:
if f in fields: if f in fields:
field_block.append({"name": f, field_block.append({"name": f,
"type": self.fields[f]["type"], "type": self.fields[f]["type"],
"unit": self.fields[f]["unit"], "unit": self.fields[f]["unit"],
"dataType": self.fields[f]["dataType"], "dataType": self.fields[f]["dataType"],
"value": self.momentary_data[f]["value"], "value": self.momentary_data[f]["value"],
"flags": self.momentary_data[f]["flags"]}); "flags": self.momentary_data[f]["flags"]});
ts_block["timestamp"] = timestamp; ts_block["timestamp"] = timestamp;
ts_block["fields"] = field_block; ts_block["fields"] = field_block;
callback(session, result="done", nodeId=self.nodeId, timestamp_block=ts_block); callback(session, result="done", nodeId=self.nodeId, timestamp_block=ts_block);
return return
from_flag = self._datetime_flag_parser(flags, 'from') from_flag = self._datetime_flag_parser(flags, 'from')
to_flag = self._datetime_flag_parser(flags, 'to') to_flag = self._datetime_flag_parser(flags, 'to')
for ts in sorted(self.timestamp_data.keys()): for ts in sorted(self.timestamp_data.keys()):
tsdt = datetime.datetime.strptime(ts, "%Y-%m-%dT%H:%M:%S") tsdt = datetime.datetime.strptime(ts, "%Y-%m-%dT%H:%M:%S")
if not from_flag is None: if not from_flag is None:
if tsdt < from_flag: if tsdt < from_flag:
#print (str(tsdt) + " < " + str(from_flag)) #print (str(tsdt) + " < " + str(from_flag))
continue continue
if not to_flag is None: if not to_flag is None:
if tsdt > to_flag: if tsdt > to_flag:
#print (str(tsdt) + " > " + str(to_flag)) #print (str(tsdt) + " > " + str(to_flag))
continue continue
ts_block = {}; ts_block = {};
field_block = []; field_block = [];
for f in self.timestamp_data[ts]: for f in self.timestamp_data[ts]:
if f in fields: if f in fields:
field_block.append({"name": f, field_block.append({"name": f,
"type": self.fields[f]["type"], "type": self.fields[f]["type"],
"unit": self.fields[f]["unit"], "unit": self.fields[f]["unit"],
"dataType": self.fields[f]["dataType"], "dataType": self.fields[f]["dataType"],
"value": self.timestamp_data[ts][f]["value"], "value": self.timestamp_data[ts][f]["value"],
"flags": self.timestamp_data[ts][f]["flags"]}); "flags": self.timestamp_data[ts][f]["flags"]});
ts_block["timestamp"] = ts; ts_block["timestamp"] = ts;
ts_block["fields"] = field_block; ts_block["fields"] = field_block;
callback(session, result="fields", nodeId=self.nodeId, timestamp_block=ts_block); callback(session, result="fields", nodeId=self.nodeId, timestamp_block=ts_block);
callback(session, result="done", nodeId=self.nodeId, timestamp_block=None); callback(session, result="done", nodeId=self.nodeId, timestamp_block=None);
def _datetime_flag_parser(self, flags, flagname): def _datetime_flag_parser(self, flags, flagname):
if not flagname in flags: if not flagname in flags:
return None return None
dt = None dt = None
try: try:
dt = datetime.datetime.strptime(flags[flagname], "%Y-%m-%dT%H:%M:%S") dt = datetime.datetime.strptime(flags[flagname], "%Y-%m-%dT%H:%M:%S")
except ValueError: except ValueError:
# Badly formatted datetime, ignore it # Badly formatted datetime, ignore it
pass pass
return dt return dt
def _get_timestamp(self): def _get_timestamp(self):
""" """
Generates a properly formatted timestamp of current time Generates a properly formatted timestamp of current time
""" """
return datetime.datetime.now().replace(microsecond=0).isoformat() return datetime.datetime.now().replace(microsecond=0).isoformat()
def _send_reject(self, session, callback): def _send_reject(self, session, callback):
""" """
Sends a reject to the caller Sends a reject to the caller
Arguments: Arguments:
session -- Session id, see definition in request_fields function session -- Session id, see definition in request_fields function
callback -- Callback function, see definition in request_fields function callback -- Callback function, see definition in request_fields function
""" """
callback(session, result="error", nodeId=self.nodeId, timestamp_block=None, error_msg="Reject"); callback(session, result="error", nodeId=self.nodeId, timestamp_block=None, error_msg="Reject");
def _add_field(self, name, typename, unit=None, dataType=None): def _add_field(self, name, typename, unit=None, dataType=None):
""" """
Adds a field to the device Adds a field to the device
Arguments: Arguments:
name -- Name of the field name -- Name of the field
typename -- Type of the field (numeric, boolean, dateTime, timeSpan, string, enum) typename -- Type of the field (numeric, boolean, dateTime, timeSpan, string, enum)
unit -- [optional] only applies to "numeric". Unit for the field. unit -- [optional] only applies to "numeric". Unit for the field.
dataType -- [optional] only applies to "enum". Datatype for the field. dataType -- [optional] only applies to "enum". Datatype for the field.
""" """
self.fields[name] = {"type": typename, "unit": unit, "dataType": dataType}; self.fields[name] = {"type": typename, "unit": unit, "dataType": dataType};
def _add_field_timestamp_data(self, name, timestamp, value, flags=None): def _add_field_timestamp_data(self, name, timestamp, value, flags=None):
""" """
Adds timestamped data to a field Adds timestamped data to a field
Arguments: Arguments:
name -- Name of the field name -- Name of the field
@ -219,37 +219,37 @@ class Device(object):
value -- Field value at the timestamp value -- Field value at the timestamp
flags -- [optional] data classifier flags for the field, e.g. momentary flags -- [optional] data classifier flags for the field, e.g. momentary
Formatted as a dictionary like { "flag name": "flag value" ... } Formatted as a dictionary like { "flag name": "flag value" ... }
""" """
if not name in self.fields.keys(): if not name in self.fields.keys():
return False; return False;
if not timestamp in self.timestamp_data: if not timestamp in self.timestamp_data:
self.timestamp_data[timestamp] = {}; self.timestamp_data[timestamp] = {};
self.timestamp_data[timestamp][name] = {"value": value, "flags": flags}; self.timestamp_data[timestamp][name] = {"value": value, "flags": flags};
return True; return True;
def _add_field_momentary_data(self, name, value, flags=None): def _add_field_momentary_data(self, name, value, flags=None):
""" """
Sets momentary data to a field Sets momentary data to a field
Arguments: Arguments:
name -- Name of the field name -- Name of the field
value -- Field value at the timestamp value -- Field value at the timestamp
flags -- [optional] data classifier flags for the field, e.g. momentary flags -- [optional] data classifier flags for the field, e.g. momentary
Formatted as a dictionary like { "flag name": "flag value" ... } Formatted as a dictionary like { "flag name": "flag value" ... }
""" """
if not self.fields.has_key(name): if name not in self.fields:
return False; return False;
if flags is None: if flags is None:
flags = {}; flags = {};
flags["momentary"] = "true" flags["momentary"] = "true"
self.momentary_data[name] = {"value": value, "flags": flags}; self.momentary_data[name] = {"value": value, "flags": flags};
return True; return True;
def _set_momentary_timestamp(self, timestamp): def _set_momentary_timestamp(self, timestamp):
""" """
This function is only for unit testing to produce predictable results. This function is only for unit testing to produce predictable results.
""" """
self.momentary_timestamp = timestamp; self.momentary_timestamp = timestamp;

View File

@ -124,10 +124,10 @@ class Request(ElementBase):
def get_nodes(self): def get_nodes(self):
"""Return all nodes.""" """Return all nodes."""
nodes = set() nodes = []
for node in self['substanzas']: for node in self['substanzas']:
if isinstance(node, RequestNode): if isinstance(node, RequestNode):
nodes.add(node) nodes.append(node)
return nodes return nodes
def set_nodes(self, nodes): def set_nodes(self, nodes):
@ -190,10 +190,10 @@ class Request(ElementBase):
def get_fields(self): def get_fields(self):
"""Return all fields.""" """Return all fields."""
fields = set() fields = []
for field in self['substanzas']: for field in self['substanzas']:
if isinstance(field, RequestField): if isinstance(field, RequestField):
fields.add(field) fields.append(field)
return fields return fields
def set_fields(self, fields): def set_fields(self, fields):
@ -351,10 +351,10 @@ class Fields(ElementBase):
def get_nodes(self): def get_nodes(self):
"""Return all nodes.""" """Return all nodes."""
nodes = set() nodes = []
for node in self['substanzas']: for node in self['substanzas']:
if isinstance(node, FieldsNode): if isinstance(node, FieldsNode):
nodes.add(node) nodes.append(node)
return nodes return nodes
def set_nodes(self, nodes): def set_nodes(self, nodes):
@ -450,10 +450,10 @@ class FieldsNode(ElementBase):
def get_timestamps(self): def get_timestamps(self):
"""Return all timestamps.""" """Return all timestamps."""
#print(str(id(self)) + " get_timestamps: ") #print(str(id(self)) + " get_timestamps: ")
timestamps = set() timestamps = []
for timestamp in self['substanzas']: for timestamp in self['substanzas']:
if isinstance(timestamp, Timestamp): if isinstance(timestamp, Timestamp):
timestamps.add(timestamp) timestamps.append(timestamp)
return timestamps return timestamps
def set_timestamps(self, timestamps): def set_timestamps(self, timestamps):
@ -634,10 +634,10 @@ class Timestamp(ElementBase):
def get_datas(self): def get_datas(self):
""" Return all data elements. """ """ Return all data elements. """
datas = set() datas = []
for data in self['substanzas']: for data in self['substanzas']:
if isinstance(data, Field): if isinstance(data, Field):
datas.add(data) datas.append(data)
return datas return datas
def set_datas(self, datas): def set_datas(self, datas):

View File

@ -11,36 +11,36 @@
import datetime import datetime
class Device(object): class Device(object):
""" """
Example implementation of a device control object. Example implementation of a device control object.
The device object may by any custom implementation to support The device object may by any custom implementation to support
specific devices, but it must implement the functions: specific devices, but it must implement the functions:
has_control_field has_control_field
set_control_fields set_control_fields
""" """
def __init__(self, nodeId): def __init__(self, nodeId):
self.nodeId = nodeId; self.nodeId = nodeId;
self.control_fields = {}; self.control_fields = {};
def has_control_field(self, field, typename): def has_control_field(self, field, typename):
""" """
Returns true if the supplied field name exists Returns true if the supplied field name exists
and the type matches for control in this device. and the type matches for control in this device.
Arguments: Arguments:
field -- The field name field -- The field name
typename -- The expected type typename -- The expected type
""" """
if field in self.control_fields and self.control_fields[field]["type"] == typename: if field in self.control_fields and self.control_fields[field]["type"] == typename:
return True; return True;
return False; return False;
def set_control_fields(self, fields, session, callback): def set_control_fields(self, fields, session, callback):
""" """
Starts a control setting procedure. Verifies the fields, Starts a control setting procedure. Verifies the fields,
sets the data and (if needed) and calls the callback. sets the data and (if needed) and calls the callback.
Arguments: Arguments:
fields -- List of control fields in tuple format: fields -- List of control fields in tuple format:
@ -48,50 +48,50 @@ class Device(object):
session -- Session id, only used in the callback as identifier session -- Session id, only used in the callback as identifier
callback -- Callback function to call when control set is complete. callback -- Callback function to call when control set is complete.
The callback function must support the following arguments: The callback function must support the following arguments:
session -- Session id, as supplied in the session -- Session id, as supplied in the
request_fields call request_fields call
nodeId -- Identifier for this device nodeId -- Identifier for this device
result -- The current result status of the readout. result -- The current result status of the readout.
Valid values are: Valid values are:
"error" - Set fields failed. "error" - Set fields failed.
"ok" - All fields were set. "ok" - All fields were set.
error_field -- [optional] Only applies when result == "error" error_field -- [optional] Only applies when result == "error"
The field name that failed The field name that failed
(usually means it is missing) (usually means it is missing)
error_msg -- [optional] Only applies when result == "error". error_msg -- [optional] Only applies when result == "error".
Error details when a request failed. Error details when a request failed.
""" """
if len(fields) > 0: if len(fields) > 0:
# Check availiability # Check availiability
for name, typename, value in fields: for name, typename, value in fields:
if not self.has_control_field(name, typename): if not self.has_control_field(name, typename):
self._send_control_reject(session, name, "NotFound", callback) self._send_control_reject(session, name, "NotFound", callback)
return False; return False;
for name, typename, value in fields: for name, typename, value in fields:
self._set_field_value(name, value) self._set_field_value(name, value)
callback(session, result="ok", nodeId=self.nodeId); callback(session, result="ok", nodeId=self.nodeId);
return True return True
def _send_control_reject(self, session, field, message, callback): def _send_control_reject(self, session, field, message, callback):
""" """
Sends a reject to the caller Sends a reject to the caller
Arguments: Arguments:
session -- Session id, see definition in session -- Session id, see definition in
set_control_fields function set_control_fields function
callback -- Callback function, see definition in callback -- Callback function, see definition in
set_control_fields function set_control_fields function
""" """
callback(session, result="error", nodeId=self.nodeId, error_field=field, error_msg=message); callback(session, result="error", nodeId=self.nodeId, error_field=field, error_msg=message);
def _add_control_field(self, name, typename, value): def _add_control_field(self, name, typename, value):
""" """
Adds a control field to the device Adds a control field to the device
Arguments: Arguments:
name -- Name of the field name -- Name of the field
@ -99,27 +99,27 @@ class Device(object):
(boolean, color, string, date, dateTime, (boolean, color, string, date, dateTime,
double, duration, int, long, time) double, duration, int, long, time)
value -- Field value value -- Field value
""" """
self.control_fields[name] = {"type": typename, "value": value}; self.control_fields[name] = {"type": typename, "value": value};
def _set_field_value(self, name, value): def _set_field_value(self, name, value):
""" """
Set the value of a control field Set the value of a control field
Arguments: Arguments:
name -- Name of the field name -- Name of the field
value -- New value for the field value -- New value for the field
""" """
if name in self.control_fields: if name in self.control_fields:
self.control_fields[name]["value"] = value; self.control_fields[name]["value"] = value;
def _get_field_value(self, name): def _get_field_value(self, name):
""" """
Get the value of a control field. Only used for unit testing. Get the value of a control field. Only used for unit testing.
Arguments: Arguments:
name -- Name of the field name -- Name of the field
""" """
if name in self.control_fields: if name in self.control_fields:
return self.control_fields[name]["value"]; return self.control_fields[name]["value"];
return None; return None;

View File

@ -83,10 +83,10 @@ class ControlSet(ElementBase):
def get_nodes(self): def get_nodes(self):
"""Return all nodes.""" """Return all nodes."""
nodes = set() nodes = []
for node in self['substanzas']: for node in self['substanzas']:
if isinstance(node, RequestNode): if isinstance(node, RequestNode):
nodes.add(node) nodes.append(node)
return nodes return nodes
def set_nodes(self, nodes): def set_nodes(self, nodes):
@ -175,10 +175,10 @@ class ControlSet(ElementBase):
def get_datas(self): def get_datas(self):
""" Return all data elements. """ """ Return all data elements. """
datas = set() datas = []
for data in self['substanzas']: for data in self['substanzas']:
if isinstance(data, BaseParameter): if isinstance(data, BaseParameter):
datas.add(data) datas.append(data)
return datas return datas
def set_datas(self, datas): def set_datas(self, datas):
@ -274,10 +274,10 @@ class ControlSetResponse(ElementBase):
def get_nodes(self): def get_nodes(self):
"""Return all nodes.""" """Return all nodes."""
nodes = set() nodes = []
for node in self['substanzas']: for node in self['substanzas']:
if isinstance(node, RequestNode): if isinstance(node, RequestNode):
nodes.add(node) nodes.append(node)
return nodes return nodes
def set_nodes(self, nodes): def set_nodes(self, nodes):

View File

@ -572,16 +572,16 @@ class TestStreamSensorData(SleekTest):
self.failUnlessEqual(results, ["accepted","fields","done"]); self.failUnlessEqual(results, ["accepted","fields","done"]);
# self.assertIn("nodeId", callback_data); # self.assertIn("nodeId", callback_data);
self.assertTrue(callback_data.has_key("nodeId")); self.assertTrue("nodeId" in callback_data)
self.failUnlessEqual(callback_data["nodeId"], "Device33"); self.failUnlessEqual(callback_data["nodeId"], "Device33");
# self.assertIn("timestamp", callback_data); # self.assertIn("timestamp", callback_data);
self.assertTrue(callback_data.has_key("timestamp")); self.assertTrue("timestamp" in callback_data);
self.failUnlessEqual(callback_data["timestamp"], "2000-01-01T00:01:02"); self.failUnlessEqual(callback_data["timestamp"], "2000-01-01T00:01:02");
#self.assertIn("field_Voltage", callback_data); #self.assertIn("field_Voltage", callback_data);
self.assertTrue(callback_data.has_key("field_Voltage")); self.assertTrue("field_Voltage" in callback_data);
self.failUnlessEqual(callback_data["field_Voltage"], {"name": "Voltage", "value": "230.4", "typename": "numeric", "unit": "V", "flags": {"invoiced": "true"}}); self.failUnlessEqual(callback_data["field_Voltage"], {"name": "Voltage", "value": "230.4", "typename": "numeric", "unit": "V", "flags": {"invoiced": "true"}});
#self.assertIn("field_TestBool", callback_data); #self.assertIn("field_TestBool", callback_data);
self.assertTrue(callback_data.has_key("field_TestBool")); self.assertTrue("field_TestBool" in callback_data);
self.failUnlessEqual(callback_data["field_TestBool"], {"name": "TestBool", "value": "true", "typename": "boolean" }); self.failUnlessEqual(callback_data["field_TestBool"], {"name": "TestBool", "value": "true", "typename": "boolean" });
def testServiceDiscoveryClient(self): def testServiceDiscoveryClient(self):
@ -693,13 +693,13 @@ class TestStreamSensorData(SleekTest):
self.failUnlessEqual(results, ["accepted","failure"]); self.failUnlessEqual(results, ["accepted","failure"]);
# self.assertIn("nodeId", callback_data); # self.assertIn("nodeId", callback_data);
self.assertTrue(callback_data.has_key("nodeId")); self.assertTrue("nodeId" in callback_data);
self.failUnlessEqual(callback_data["nodeId"], "Device33"); self.failUnlessEqual(callback_data["nodeId"], "Device33");
# self.assertIn("timestamp", callback_data); # self.assertIn("timestamp", callback_data);
self.assertTrue(callback_data.has_key("timestamp")); self.assertTrue("timestamp" in callback_data);
self.failUnlessEqual(callback_data["timestamp"], "2013-03-07T17:13:30"); self.failUnlessEqual(callback_data["timestamp"], "2013-03-07T17:13:30");
# self.assertIn("error_msg", callback_data); # self.assertIn("error_msg", callback_data);
self.assertTrue(callback_data.has_key("error_msg")); self.assertTrue("error_msg" in callback_data);
self.failUnlessEqual(callback_data["error_msg"], "Timeout."); self.failUnlessEqual(callback_data["error_msg"], "Timeout.");
def testDelayedRequest(self): def testDelayedRequest(self):
@ -1095,16 +1095,16 @@ class TestStreamSensorData(SleekTest):
self.failUnlessEqual(results, ["queued","started","fields","done"]); self.failUnlessEqual(results, ["queued","started","fields","done"]);
# self.assertIn("nodeId", callback_data); # self.assertIn("nodeId", callback_data);
self.assertTrue(callback_data.has_key("nodeId")); self.assertTrue("nodeId" in callback_data);
self.failUnlessEqual(callback_data["nodeId"], "Device33"); self.failUnlessEqual(callback_data["nodeId"], "Device33");
# self.assertIn("timestamp", callback_data); # self.assertIn("timestamp", callback_data);
self.assertTrue(callback_data.has_key("timestamp")); self.assertTrue("timestamp" in callback_data);
self.failUnlessEqual(callback_data["timestamp"], "2000-01-01T00:01:02"); self.failUnlessEqual(callback_data["timestamp"], "2000-01-01T00:01:02");
# self.assertIn("field_Voltage", callback_data); # self.assertIn("field_Voltage", callback_data);
self.assertTrue(callback_data.has_key("field_Voltage")); self.assertTrue("field_Voltage" in callback_data);
self.failUnlessEqual(callback_data["field_Voltage"], {"name": "Voltage", "value": "230.4", "typename": "numeric", "unit": "V", "flags": {"invoiced": "true"}}); self.failUnlessEqual(callback_data["field_Voltage"], {"name": "Voltage", "value": "230.4", "typename": "numeric", "unit": "V", "flags": {"invoiced": "true"}});
# self.assertIn("field_TestBool", callback_data); # self.assertIn("field_TestBool", callback_data);
self.assertTrue(callback_data.has_key("field_TestBool")); self.assertTrue("field_TestBool" in callback_data);
self.failUnlessEqual(callback_data["field_TestBool"], {"name": "TestBool", "value": "true", "typename": "boolean" }); self.failUnlessEqual(callback_data["field_TestBool"], {"name": "TestBool", "value": "true", "typename": "boolean" });