def _mock(*args, **kwargs): return 'vaporio/test+tcp@localhost:5001/test', api.Device( timestamp='2018-10-18T16:43:18+00:00', uid='12345', kind='test', plugin='test', location=api.Location( rack='rack', board='board', ), output=[ api.Output( type='temperature', precision=3, unit=api.Unit( name='celsius', symbol='C' ) ), api.Output( type='humidity', precision=3, unit=api.Unit( name='percent', symbol='%' ) ) ] )
def make_device_response(): """Convenience method to create Device test data.""" return api.Device( timestamp='october', uid='12345', kind='thermistor', metadata=dict( model='test', manufacturer='vapor io' ), plugin='foo', info='bar', location=api.Location( rack='rack-1', board='vec' ), output=[ api.Output( name='foo.temperature', type='temperature', precision=3, unit=api.Unit( name='celsius', symbol='C' ) ) ] )
def test_device_info_to_dict(): """Convert a Device object to dictionary.""" meta = api.Device(timestamp='october', uid='12345', kind='thermistor', metadata=dict( model='test', manufacturer='vapor io', ), plugin='foo', info='bar', location=api.Location(rack='rack-1', board='vec'), output=[ api.Output(type='temperature', precision=3, unit=api.Unit(name='celsius', symbol='C')) ]) actual = util.device_info_to_dict(meta) assert actual == { 'timestamp': 'october', 'uid': '12345', 'kind': 'thermistor', 'metadata': { 'model': 'test', 'manufacturer': 'vapor io', }, 'plugin': 'foo', 'info': 'bar', 'location': { 'rack': 'rack-1', 'board': 'vec' }, 'output': [{ 'name': '', 'scaling_factor': 0.0, 'type': 'temperature', 'precision': 3, 'unit': { 'name': 'celsius', 'symbol': 'C', } }] }
def make_device_info_response(rack, board, device): """Helper method to make a new Device object.""" return api.Device(timestamp='october', uid=device, kind='thermistor', metadata=dict( model='test', manufacturer='vapor io', ), plugin='foo', info='bar', location=api.Location(rack=rack, board=board), output=[ api.Output(type='temperature', precision=3, unit=api.Unit(name='celsius', symbol='C')) ])
def test_output_to_dict(): """Convert an Output object to dictionary.""" meta = api.Output(type='temperature', precision=3, unit=api.Unit(name='celsius', symbol='C')) actual = util.output_to_dict(meta) assert actual == { 'name': '', 'type': 'temperature', 'precision': 3, 'scaling_factor': 0.0, 'unit': { 'name': 'celsius', 'symbol': 'C', } }
def mockgetdevicemeta(rack, board, device): """Mock method to monkeypatch the get_device_info method.""" # the plugin name 'foo' here corresponds to the plugin generated by # the `make_plugin` fixture return 'vaporio/foo+unix@tmp/foo', api.Device( timestamp='october', uid='12345', kind='thermistor', metadata=dict( model='test', manufacturer='vapor io', ), plugin='foo', # this will be the name of the plugin we look up info='bar', location=api.Location(rack='rack-1', board='vec'), output=[ api.Output(type='temperature', precision=3, unit=api.Unit(name='celsius', symbol='C')) ])
def test_read_cached_scheme(): """Test that the read cached scheme matches the expected.""" dev = api.Device(timestamp='october', uid='12345', kind='thermistor', metadata=dict(model='test', manufacturer='vapor io'), plugin='foo', info='bar', location=api.Location(rack='rack-1', board='vec'), output=[ api.Output(name='foo.temperature', type='temperature', precision=3, unit=api.Unit(name='celsius', symbol='C')) ]) reading = api.DeviceReading(rack='rack-1', board='vec', device='12345', reading=api.Reading(timestamp='november', type='temperature', int64_value=10)) response_scheme = ReadCachedResponse(dev, reading) assert response_scheme.data == { 'location': { 'rack': 'rack-1', 'board': 'vec', 'device': '12345' }, 'kind': 'thermistor', 'info': '', 'type': 'temperature', 'value': 10.0, 'timestamp': 'november', 'unit': { 'name': 'celsius', 'symbol': 'C' } }