コード例 #1
0
ファイル: test_server.py プロジェクト: frnsys/scanmap
def client(monkeypatch):
    # Copy over the test keys to the temporary key file
    keyf = tempfile.NamedTemporaryFile()
    with open('tests/app/data/keys.yml', mode='rb') as testkeyf:
        keyf.write(testkeyf.read())
        keyf.flush()

    labelsf = tempfile.NamedTemporaryFile()
    with open('tests/app/data/labels.yml', mode='rb') as testlabelsf:
        labelsf.write(testlabelsf.read())
        labelsf.flush()

    dbf = tempfile.NamedTemporaryFile()
    from app import routes, create_app

    # Stub key ring and database
    monkeypatch.setattr(routes, 'kr', KeyRing(keyf.name))
    monkeypatch.setattr(routes, 'db', Database(dbf.name))
    monkeypatch.setattr(routes, 'lm', LabelManager(labelsf.name))

    import server
    server.app.config['TESTING'] = True
    yield server.app.test_client()

    keyf.close()
    labelsf.close()
    dbf.close()
コード例 #2
0
def server(monkeypatch):
    # Copy over the test keys to the temporary key file
    keyf = tempfile.NamedTemporaryFile()
    with open('tests/app/data/keys.yml', mode='rb') as testkeyf:
        keyf.write(testkeyf.read())
        keyf.flush()

    labelsf = tempfile.NamedTemporaryFile()
    with open('tests/app/data/labels.yml', mode='rb') as testlabelsf:
        labelsf.write(testlabelsf.read())
        labelsf.flush()

    dbf = tempfile.NamedTemporaryFile()
    from app import routes

    # Stub key ring and database
    monkeypatch.setattr(routes, 'kr', KeyRing(keyf.name))
    monkeypatch.setattr(routes, 'db', Database(dbf.name))
    monkeypatch.setattr(routes, 'lm', LabelManager(labelsf.name))

    import server
    server.app.config['TESTING'] = True
    proc = multiprocessing.Process(
        target=lambda: server.app.run(port=8800, debug=True))
    proc.start()

    time.sleep(5)

    yield

    proc.terminate()
    keyf.close()
    labelsf.close()
    dbf.close()
コード例 #3
0
ファイル: test_keys.py プロジェクト: frnsys/scanmap
def keys():
    with tempfile.NamedTemporaryFile(mode='w+') as keyf:
        keyf.write('ny:\n')
        keyf.write('  prime:\n')
        keyf.write('  -\n')
        keyf.write('  write:\n')
        keyf.write('  -')
        keyf.flush()
        yield KeyRing(keyf.name)
コード例 #4
0
ファイル: test_keys.py プロジェクト: frnsys/scanmap
def empty_keys():
    with tempfile.NamedTemporaryFile(mode='w+') as keyf:
        yield KeyRing(keyf.name)
コード例 #5
0
ファイル: server.py プロジェクト: unitof/scanmap
import json
import config
from app.db import Database
from app.cams import cameras
from app.keys import KeyRing
from app.geo import search_places
from flask_caching import Cache
from flask import Flask, abort, request, render_template, jsonify
from flask_sse import sse
from datetime import datetime, timezone

app = Flask(__name__)
app.config.from_object(config)
app.register_blueprint(sse, url_prefix='/location-stream')

kr = KeyRing(config.KEYS_FILE)
db = Database(config.DB_PATH)
cache = Cache(app)


def get_conf(loc):
    try:
        return config.LOCATIONS[loc]
    except KeyError:
        abort(404)


@app.route('/')
def index():
    return render_template('index.html', locations=config.LOCATIONS.keys())