Exemple #1
0
def main():
    import argparse
    parser = argparse.ArgumentParser(description="the location service")
    parser.add_argument("--bind-host",
                        type=str,
                        default="0.0.0.0",
                        help="hostname/ip to bind to")

    parser.add_argument("--bind-port",
                        type=int,
                        default="8080",
                        help="port to bind to")

    args = parser.parse_args()

    app = get_app()

    # this is our fancy plugin system ;)
    from tls import plugin_google
    app["services"].append(plugin_google.Plugin())

    import logging
    util.init_logging(level=logging.INFO)

    aiohttp.web.run_app(app, host=args.bind_host, port=args.bind_port)
Exemple #2
0
async def test_location_query(debug_log):
    from tls import plugin_google
    p = plugin_google.Plugin()
    data = await p("food", latitude="53.5", longitude="10.0")
    assert isinstance(data, list)
    assert len(data) > 1

    d0 = data[0]
    assert "id" in d0
    assert "provider" in d0
    assert d0["provider"] == "google"
Exemple #3
0
async def test_text_query(debug_log):
    from tls import plugin_google
    p = plugin_google.Plugin()
    data = await p("hamburg food")
    assert isinstance(data, list)
    assert len(data) > 1

    d0 = data[0]
    assert "id" in d0
    assert "provider" in d0
    assert d0["provider"] == "google"
Exemple #4
0
def test_keyfile_load(monkeypatch):
    from tls import plugin_google
    key = "jadddaada"
    with tempfile.TemporaryDirectory() as tmp_dir:
        keyfile = os.path.join(tmp_dir, "the_key")
        with open(keyfile, "w") as f:
            f.write(key)

        monkeypatch.setenv("GOOGLE_PLACES_API_KEY", keyfile)
        p = plugin_google.Plugin()
        assert p.api_key == key
Exemple #5
0
def test_without_keyfile_var(monkeypatch):
    from tls import plugin_google
    if "GOOGLE_PLACES_API_KEY" in os.environ:
        monkeypatch.delenv("GOOGLE_PLACES_API_KEY")
    with pytest.raises(RuntimeError):
        plugin_google.Plugin()
Exemple #6
0
def test_without_keyfile(monkeypatch):
    from tls import plugin_google
    monkeypatch.setenv("GOOGLE_PLACES_API_KEY", "/does/not/exist")
    with pytest.raises(RuntimeError):
        plugin_google.Plugin()