# Path: test/settings/mqttkit.py
# PROCESS_DELAY_MQTT = 0.3
# PROCESS_DELAY_HTTP = 0.3
# class TestSettings:
# 
# Path: test/util.py
# def sleep(secs):
#     # https://gist.github.com/jhorman/891717
#     return deferLater(reactor, secs, lambda: None)
# 
# def http_json_sensor(topic, data):
#     uri = 'http://localhost:24642/api{}'.format(topic)
#     logger.info('HTTP: Submitting reading to {} using JSON'.format(uri))
#     return requests.post(uri, json=data)
# 
# def http_get_data(topic=None, format='csv', ts_from=None, ts_to=None):
#     uri = 'http://localhost:24642/api{topic}.{format}?from={ts_from}&to={ts_to}'.format(
#         topic=topic, format=format, ts_from=ts_from, ts_to=ts_to)
#     logger.info('HTTP: Exporting data from {} using format "{}"'.format(uri, format))
#     payload = requests.get(uri).content
#     if format in ["csv", "txt", "json", "html"]:
#         payload = payload.decode()
#     return payload


import json
import logging
import io
import pandas as pd
import pytest
import pytest_twisted
    import h5py
from twisted.internet import threads
from test.settings.mqttkit import settings, PROCESS_DELAY_MQTT
from test.util import sleep, http_json_sensor, http_get_data
from pandas.testing import assert_frame_equal
from datadiff.tools import assert_equal
    from io import BytesIO
    from pandas import array
# -*- coding: utf-8 -*-
# (c) 2020-2021 Andreas Motl <andreas@getkotori.org>



logger = logging.getLogger(__name__)


@pytest_twisted.inlineCallbacks
@pytest.mark.http
@pytest.mark.export
def test_export(machinery, create_influxdb, reset_influxdb):
    """
    Submit single reading in JSON format to HTTP API and proof
    it can be retrieved back from the HTTP API in different formats.
    """

    # Submit a single measurement, with timestamp.
    data = {
        'time': 1583810982,
        'temperature': 25.26,
        'humidity': 51.8,
    }

# Path: test/settings/mqttkit.py
# PROCESS_DELAY_MQTT = 0.3
# PROCESS_DELAY_HTTP = 0.3
# class TestSettings:
# 
# Path: test/util.py
# def sleep(secs):
#     # https://gist.github.com/jhorman/891717
#     return deferLater(reactor, secs, lambda: None)
# 
# def http_json_sensor(topic, data):
#     uri = 'http://localhost:24642/api{}'.format(topic)
#     logger.info('HTTP: Submitting reading to {} using JSON'.format(uri))
#     return requests.post(uri, json=data)
# 
# def http_get_data(topic=None, format='csv', ts_from=None, ts_to=None):
#     uri = 'http://localhost:24642/api{topic}.{format}?from={ts_from}&to={ts_to}'.format(
#         topic=topic, format=format, ts_from=ts_from, ts_to=ts_to)
#     logger.info('HTTP: Exporting data from {} using format "{}"'.format(uri, format))
#     payload = requests.get(uri).content
#     if format in ["csv", "txt", "json", "html"]:
#         payload = payload.decode()
#     return payload


# Path: test/test_export.py
import json
import logging
import io
import pandas as pd
import pytest
import pytest_twisted
    import h5py
from twisted.internet import threads
from test.settings.mqttkit import settings, PROCESS_DELAY_MQTT
from test.util import sleep, http_json_sensor, http_get_data
from pandas.testing import assert_frame_equal
from datadiff.tools import assert_equal
    from io import BytesIO
    from pandas import array

# -*- coding: utf-8 -*-
# (c) 2020-2021 Andreas Motl <andreas@getkotori.org>



logger = logging.getLogger(__name__)


@pytest_twisted.inlineCallbacks
@pytest.mark.http
@pytest.mark.export
def test_export(machinery, create_influxdb, reset_influxdb):
    """
    Submit single reading in JSON format to HTTP API and proof
    it can be retrieved back from the HTTP API in different formats.
    """

    # Submit a single measurement, with timestamp.
    data = {
        'time': 1583810982,
        'temperature': 25.26,
        'humidity': 51.8,
    }

    yield threads.deferToThread(http_json_sensor, settings.channel_path_data, data)