def test_multi_measurements_1(): db = influxdb.InfluxDBClient(database="example") client = InfluxAlchemy(db) fizz = Measurement.new("fuzz") bizz = Measurement.new("buzz") query = client.query(fizz, bizz).limit(10) assert str(query) == "SELECT * FROM /fuzz|buzz/ LIMIT 10;"
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_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_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_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_multi_measurements_2(): db = influxdb.InfluxDBClient(database="marketdata", port=28088) client = InfluxAlchemy(db) fizz = Measurement.new("fuzz") bizz = Measurement.new("buzz") query = client.query(fizz, bizz).limit(10) assert None == query.first()
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_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_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_multi_measurements_3(): db = influxdb.InfluxDBClient(database="marketdata", port=28088) client = InfluxAlchemy(db) fizz = Measurement.new("term_structure_px") bizz = Measurement.new("term_structure_symbol_list") query = client.query(fizz, bizz).limit(2) rs = query.first() assert True == isinstance(rs, MultiResultSet)
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_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_multi_measurements_4(): db = influxdb.InfluxDBClient(database="marketdata", port=28088) client = InfluxAlchemy(db) fizz = Measurement.new("term_structure_px") bizz = Measurement.new("term_structure_symbol_list") query = client.query(fizz, bizz).limit(2) rs1 = query.first() rs2 = query.all() assert type(rs1) == type(rs2[0]) assert True == isinstance(rs2, list) # since 2 measurement x 2 limits = 4 if all data are available print(len(rs2)) assert 4 == len(rs2)
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_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_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_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_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_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_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_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_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_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;"