class CashTransaction(Measurement): measurement_name = 'CashTransaction' # Fields # Date of the transaction transactionDate = attributes.TimestampFieldAttribute() #The amount of the transaction amount = attributes.FloatFieldAttribute() #Tags # Description of the transaction memo = attributes.TagFieldAttribute() # Financial Institution specific transaction id fi_id = attributes.TagFieldAttribute() # Account ID account = attributes.TagFieldAttribute()
class MySampleMeasurement(Measurement): measurement_name = 'mysamplemeasurement' time = attributes.TimestampFieldAttribute(precision="s") value = attributes.IntegerFieldAttribute()
class MySampleMeasurement(Measurement): measurement_name = 'mysamplemeasurement' time = attributes.TimestampFieldAttribute() value = attributes.IntegerFieldAttribute(is_nullable=False)
def test_convert_to_precision_success(self): attr = attributes.TimestampFieldAttribute() attr.set_internal_value(1570209691) assert attr.convert_to_precision(1570209691, 'ms') == D('1570209691000')
def test_validate_fail(self): with pytest.raises(exceptions.InfluxDBAttributeValueError): attributes.TimestampFieldAttribute(precision='k')
def test_convert_to_nanoseconds_success(self): attr = attributes.TimestampFieldAttribute() attr.set_internal_value(1570209691) assert attr.convert_to_nanoseconds(1570209691) == D('1570209691000000000')
def test_clean_with_none_success(self): attr = attributes.TimestampFieldAttribute(auto_now=False) attr.set_internal_value(None) assert attr.get_internal_value() is None
def test_clean_success(self): attr = attributes.TimestampFieldAttribute() attr.set_internal_value(1570209691) assert attr.to_python(1570209691) == D('1570209691000000000')
def test_to_influx_success(self): attr = attributes.TimestampFieldAttribute() attr.set_internal_value(1570209691) assert attr.to_influx(1570209691000000000) == '1570209691000000000'
class PopulateMeasurement(Measurement): measurement_name = name time = attributes.TimestampFieldAttribute(precision='s') phase = attributes.TagFieldAttribute() value = attributes.FloatFieldAttribute()