def test_create_grafana_org(client: TimeseriesClient): org_name = "test-create-org" try: client.delete_grafana_org(org_name=org_name) except Exception: pass res = client.create_grafana_org(org_name) assert res["message"] == "Organization created"
def client() -> TimeseriesClient: return TimeseriesClient( host="localhost", port=8086, token="mySuP3rS3cr3tT0keN", organization="test-org", verify_ssl=False, )
def read_and_write_data(): client = TimeseriesClient.from_env_properties() # write single points _start_points = datetime.now(UTC) _point1 = (Point("test_single_point").tag("location", "Prague").field( "temperature", 25.3).time(_start_points)) _point2 = (Point("test_single_point").tag("location", "New York").field( "temperature", 24.3).time(_start_points)) client.write_points(project=PROJECT, points=[_point1, _point2]) # write a dataframe _start_dataframe = datetime.now(UTC) _dataframe = pd.DataFrame( data=[["coyote_creek", 1.0], ["coyote_creek", 2.0]], index=[_start_dataframe, _start_dataframe + timedelta(hours=1)], columns=["location", "water_level"], ) client.write_a_dataframe( project=PROJECT, measurement_name="test_dataframe", dataframe=_dataframe, tag_columns=["location"], ) # read single points points = client.get_points( project=PROJECT, fields={"_measurement": "test_single_point"}, start_time=_start_points, ) logger.info("Request Points:") results = [] for table in points: for record in table.records: results.append((record.get_value(), record.get_field())) print(results) # read a dataframe dataframe = client.get_dataframe( project=PROJECT, fields={ "_measurement": "test_dataframe", "_field": "water_level" }, start_time=_start_dataframe, ) logger.info("Requested Dataframe:") logger.info(dataframe)
def test_delete_bucket(client: TimeseriesClient): bucket_name = "test-delete-bucket" client.create_bucket(bucket_name) assert client.exist_bucket(bucket_name) client.delete_bucket(bucket_name) assert not client.exist_bucket(bucket_name)
def test_get_grafana_org(client: TimeseriesClient): org = client.get_grafana_org(org_name="Main Org.") assert org["id"] == 1
def test_get_grafana_orgs(client: TimeseriesClient): orgs = client.get_grafana_orgs() assert len(orgs) >= 1
def test_create_bucket(client: TimeseriesClient): bucket_name = "test-create-bucket" client.create_bucket(bucket_name) assert client.exist_bucket(bucket_name)
def test_exist_bucket(client: TimeseriesClient): bucket_name = "test-bucket" assert client.exist_bucket(bucket=bucket_name)