Changeset View
Changeset View
Standalone View
Standalone View
swh/scanner/tests/flask_api.py
# Copyright (C) 2020 The Software Heritage developers | # Copyright (C) 2020 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
from flask import Flask, request | from flask import Flask, request | ||||
from .data import present_pids | from .data import present_swhids | ||||
from swh.web.common.exc import LargePayloadExc | from swh.web.common.exc import LargePayloadExc | ||||
def create_app(): | def create_app(): | ||||
app = Flask(__name__) | app = Flask(__name__) | ||||
@app.route("/known/", methods=["POST"]) | @app.route("/known/", methods=["POST"]) | ||||
def known(): | def known(): | ||||
pids = request.get_json() | swhids = request.get_json() | ||||
if len(pids) > 900: | if len(swhids) > 900: | ||||
raise LargePayloadExc( | raise LargePayloadExc( | ||||
"The maximum number of PIDs this endpoint " "can receive is 900" | "The maximum number of PIDs this endpoint " "can receive is 900" | ||||
) | ) | ||||
res = {pid: {"known": False} for pid in pids} | res = {swhid: {"known": False} for swhid in swhids} | ||||
for pid in pids: | for swhid in swhids: | ||||
if pid in present_pids: | if swhid in present_swhids: | ||||
res[pid]["known"] = True | res[swhid]["known"] = True | ||||
return res | return res | ||||
return app | return app |