def test_tags(mock_flux): mock_res = mock.MagicMock() mock_res.get_points.return_value = [{'tagKey': 'sensor_id'}] mock_flux.return_value = mock_res db = influxdb.InfluxDBClient(database="fizz") client = InfluxAlchemy(db) assert client.tags(Measurement.new("environment")) == ["sensor_id"]
def test_limit_2(mock_limit): db = influxdb.InfluxDBClient(database="example") client = InfluxAlchemy(db) fizz = Measurement.new("fuzz") query = client.query(fizz).filter_by(vendor='quandl', market='XCME') assert str(query) == \ "SELECT * FROM fuzz WHERE (market = 'XCME') AND (vendor = 'quandl');"
def test_filter(mock_qry): mock_qry.side_effect = influxdb.exceptions.InfluxDBClientError(None) db = influxdb.InfluxDBClient(database="example") client = InfluxAlchemy(db) meas = Measurement.new("fizz") query = client.query(meas).filter(meas.buzz == "goo") assert repr(query) == "SELECT * FROM fizz WHERE (buzz = 'goo');"
def test_measurements(mock_flux): mock_res = mock.MagicMock() mock_res.get_points.return_value = [{"name": "fizz"}] mock_flux.return_value = mock_res db = influxdb.InfluxDBClient(database="fizz") client = InfluxAlchemy(db) measurements = list(client.measurements()) mock_flux.assert_called_once_with("SHOW MEASUREMENTS;")
def test_get_empty_tags_fields(mock_fields, mock_tags): mock_tags.return_value = [] mock_fields.return_value = [] db = influxdb.InfluxDBClient(database="example") client = InfluxAlchemy(db) fizz = Measurement.new("fuzz") query = client.query(fizz) assert str(query) == "SELECT * FROM fuzz;"
def test_filter_time_date(mock_qry): mock_qry.side_effect = influxdb.exceptions.InfluxDBClientError(None) db = influxdb.InfluxDBClient(database="example") client = InfluxAlchemy(db) meas = Measurement.new("fizz") d = date(2016, 10, 1) query = client.query(meas).filter(meas.time >= d) assert repr(query) == "SELECT * FROM fizz WHERE (time >= '2016-10-01');"
def test_fields(mock_flux): mock_res = mock.MagicMock() mock_res.get_points.return_value = [ {'fieldKey': 'humidity', 'fieldType': 'float'}, {'fieldKey': 'temperature', 'fieldType': 'float'} ] mock_flux.return_value = mock_res db = influxdb.InfluxDBClient(database="fizz") client = InfluxAlchemy(db) assert client.fields(Measurement.new("environment")) == ["humidity", "temperature"]
def test_limit_3(mock_limit): db = influxdb.InfluxDBClient(database="example") client = InfluxAlchemy(db) fizz = Measurement.new("fuzz") query = client.query(fizz)\ .filter(fizz.foo == '123')\ .filter(fizz.boo == '555')\ .limit(2) assert str(query) == \ "SELECT * FROM fuzz WHERE (foo = '123') AND (boo = '555') LIMIT 2;"
def test_filter_time_aware(mock_qry): mock_qry.side_effect = influxdb.exceptions.InfluxDBClientError(None) db = influxdb.InfluxDBClient(database="example") client = InfluxAlchemy(db) meas = Measurement.new("fizz") if sys.version_info.major >= 3: tz_vietnam = timezone(timedelta(hours=7, minutes=7)) else: tz_vietnam = timezone('Asia/Ho_Chi_Minh') d_low = datetime(2016, 9, 1, tzinfo=tz_vietnam) d_high = datetime(2016, 10, 2, 8) query = client.query(meas).filter(meas.time.between(d_low, d_high)) assert repr(query) == \ "SELECT * FROM fizz WHERE (time >= '2016-09-01T00:00:00+07:07' "\ "AND time <= '2016-10-02T08:00:00+00:00');"
def test_execute(mock_qry): db = influxdb.InfluxDBClient(database="example") client = InfluxAlchemy(db) query = client.query(Measurement.new("fizz").buzz) query.execute() mock_qry.assert_called_with("SELECT buzz FROM fizz;")
def test_query(mock_flux): db = influxdb.InfluxDBClient(database="fizz") db.query.side_effect = influxdb.exceptions.InfluxDBClientError(None) client = InfluxAlchemy(db) query = client.query(Measurement.new("buzz")) assert str(query) == "SELECT * FROM buzz;"
def test_tags(): db = influxdb.InfluxDBClient(database="example") client = InfluxAlchemy(db) fizz = Measurement.new("fizz") query = client.query(fizz.buzz, fizz.bug) assert str(query) == "SELECT buzz, bug FROM fizz;"
def test_limit_1(mock_limit): db = influxdb.InfluxDBClient(database="example") client = InfluxAlchemy(db) fizz = Measurement.new("fuzz") query = client.query(fizz).limit(1) assert str(query) == "SELECT * FROM fuzz LIMIT 1;"
def test_filter_by(mock_qry): mock_qry.side_effect = influxdb.exceptions.InfluxDBClientError(None) db = influxdb.InfluxDBClient(database="example") client = InfluxAlchemy(db) query = client.query(Measurement.new("fizz")).filter_by(buzz="goo") assert str(query) == "SELECT * FROM fizz WHERE (buzz = 'goo');"
def test_group_by(mock_qry): mock_qry.side_effect = influxdb.exceptions.InfluxDBClientError(None) db = influxdb.InfluxDBClient(database="example") client = InfluxAlchemy(db) query = client.query(Measurement.new("fizz")).group_by("buzz") assert str(query) == "SELECT * FROM fizz GROUP BY buzz;"
def test_repr(mock_qry): mock_qry.side_effect = influxdb.exceptions.InfluxDBClientError(None) db = influxdb.InfluxDBClient(database="example") client = InfluxAlchemy(db) query = client.query(Measurement.new("fizz")) assert repr(query) == "SELECT * FROM fizz;"