Beispiel #1
0
def test_scan_for_tilt_data_parse_webhook(mock_webhook, ):
    config = MockConfigParser('webhook')[0]
    emitter = webhook.Webhook(config=config)
    tilty.emit(emitters=[emitter],
               tilt_data={
                   'color': 'black',
                   'gravity': 1,
                   'temp': 32,
                   'mac': '00:0a:95:9d:68:16',
                   'timestamp': 155558888
               })
    assert mock_webhook.mock_calls == [
        mock.call(
            config={
                'url': 'http://www.google.com',
                'headers': '{"Content-Type": "application/json"}',
                'payload_template':
                '{"color": "{{ color }}", "gravity": {{ gravity }}, "temp": {{ temp }}, "timestamp": "{{ timestamp }}"}',  # noqa
                'method': 'GET'
            }),
        mock.call().emit(
            tilt_data={
                'color': 'black',
                'gravity': 1,
                'temp': 32,
                'mac': '00:0a:95:9d:68:16',
                'timestamp': 155558888
            })
    ]
Beispiel #2
0
def test_scan_for_tilt_data_parse_influxdb(mock_influxdb, ):
    config = MockConfigParser('influxdb')[0]
    emitter = influxdb.InfluxDB(config=config)
    tilty.emit(emitters=[emitter],
               tilt_data={
                   'color': 'black',
                   'gravity': 1,
                   'temp': 32,
                   'mac': '00:0a:95:9d:68:16',
                   'timestamp': 155558888
               })
    assert mock_influxdb.mock_calls == [
        mock.call(
            config={
                'url':
                'http://www.google.com',
                'database':
                'foo',
                'gravity_payload_template':
                'gravity,color={{ color }} value={{ gravity }} {{timestamp}}',  # noqa
                'temperature_payload_template':
                'temperature,scale=fahrenheit,color={{ color }} value={{ temp }} {{timestamp}}'  # noqa
            }),
        mock.call().emit(
            tilt_data={
                'color': 'black',
                'gravity': 1,
                'temp': 32,
                'mac': '00:0a:95:9d:68:16',
                'timestamp': 155558888
            })
    ]
Beispiel #3
0
def test_scan_for_tilt_data_parse_datadog(mock_dd, ):
    config = MockConfigParser('datadog')[0]
    emitter = datadog.Datadog(config=config)
    tilty.emit(emitters=[emitter],
               tilt_data={
                   'color': 'black',
                   'gravity': 1,
                   'temp': 32,
                   'mac': '00:0a:95:9d:68:16',
                   'timestamp': 155558888
               })
    assert mock_dd.mock_calls == [
        mock.call(config={
            'host': 'http://api.datadog.com',
            'port': '8120'
        }),
        mock.call().emit(
            tilt_data={
                'color': 'black',
                'gravity': 1,
                'temp': 32,
                'mac': '00:0a:95:9d:68:16',
                'timestamp': 155558888
            })
    ]
Beispiel #4
0
def test_scan_for_tilt_data_parse_sqlite(
    mock_sqlite,
):
    config = MockConfigParser('sqlite')[0]
    emitter = sqlite.SQLite(config=config)
    tilty.emit(
        emitters=[emitter],
        tilt_data=[{
            'color': 'black',
            'gravity': 1,
            'temp': 32,
            'mac': '00:0a:95:9d:68:16',
        },
        {
            'color': 'pink',
            'gravity': 1,
            'temp': 33,
            'mac': '00:0a:95:9d:68:17',
        }]
    )
    assert mock_sqlite.mock_calls == [
        mock.call.connect('/foo.sqlite'),
        mock.call.connect().execute('\n            CREATE TABLE IF NOT EXISTS data(\n              id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,\n              gravity INTEGER,\n              temp INTEGER,\n              color VARCHAR(16),\n              mac VARCHAR(17),\n              timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL)\n        '),  # noqa
        mock.call.connect().execute('insert into data (gravity,temp,color,mac) values (?,?,?,?)', (1, 32, 'black', '00:0a:95:9d:68:16')),  # noqa
        mock.call.connect().commit(),
        mock.call.connect().execute('insert into data (gravity,temp,color,mac) values (?,?,?,?)', (1, 33, 'pink', '00:0a:95:9d:68:17')),  # noqa
        mock.call.connect().commit()
    ]
Beispiel #5
0
def test_parse_config(
    mock_sqlite,
):
    config = MockConfigParser('sqlite', include_extra_section=True)
    emitters = parse_config(config)
    assert len(emitters) == 1
    assert str(type(emitters[0])) == "<class 'tilty.emitters.sqlite.SQLite'>"
Beispiel #6
0
def test_scan_for_tilt_data_parse_webhook(mock_webhook, ):
    config = MockConfigParser('webhook')
    tilty.emit(config, {
        'color': 'black',
        'gravity': 1,
        'temp': 32,
        'timestamp': 155558888
    })
    assert mock_webhook.mock_calls == [
        mock.call(
            config={
                'url': 'http://www.google.com',
                'headers': {
                    'Content-Type': 'application/json'
                },
                'method': 'GET',
                'payload': {
                    'color': 'black',
                    'gravity': 1,
                    'temp': 32,
                    'timestamp': '155558888'
                }  # noqa
            }),
        mock.call().emit()
    ]
Beispiel #7
0
def test_scan_for_tilt_data_parse_datadog(mock_dd, ):
    config = MockConfigParser('datadog')
    tilty.emit(config, {
        'color': 'black',
        'gravity': 1,
        'temp': 32,
        'timestamp': 155558888
    })
    assert mock_dd.mock_calls == [
        mock.call(
            config={
                'host': 'http://api.datadog.com',
                'port': '8120',
                'gravity': 1,
                'temperature': 32,
                'color': 'black'
            }),  # noqa
        mock.call().emit()
    ]
Beispiel #8
0
def test_scan_for_tilt_data_parse_influxdb(mock_influxdb, ):
    config = MockConfigParser('influxdb')
    tilty.emit(config, {
        'color': 'black',
        'gravity': 1,
        'temp': 32,
        'timestamp': 155558888
    })
    assert mock_influxdb.mock_calls == [
        mock.call(
            config={
                'url': 'http://www.google.com',
                'database': 'foo',
                'temperature_payload':
                'temperature,scale=fahrenheit,color=black value=32 155558888',  # noqa
                'gravity_payload': 'gravity,color=black value=1 155558888'
            }),
        mock.call().emit()
    ]
Beispiel #9
0
def test_parse_config_invalid_emitter():
    with pytest.raises(ModuleNotFoundError):
        config = MockConfigParser('', include_extra_section=True)
        emitters = parse_config(config)
        assert not emitters
Beispiel #10
0
def test_parse_config_empty():
    with pytest.raises(ConfigurationFileEmptyException):
        config = MockConfigParser('', return_empty=True)
        emitters = parse_config(config)
        assert not emitters