Changeset View
Changeset View
Standalone View
Standalone View
swh/vault/tests/test_server.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 | ||||
import copy | import copy | ||||
import os | import os | ||||
from typing import Any, Dict | from typing import Any, Dict | ||||
import pytest | import pytest | ||||
import yaml | import yaml | ||||
from swh.core.api.serializers import json_dumps, msgpack_dumps, msgpack_loads | from swh.core.api.serializers import json_dumps, msgpack_dumps, msgpack_loads | ||||
from swh.vault.api.serializers import ENCODERS | |||||
from swh.vault.api.server import ( | from swh.vault.api.server import ( | ||||
VaultServerApp, | VaultServerApp, | ||||
check_config, | check_config, | ||||
make_app, | make_app, | ||||
make_app_from_configfile, | make_app_from_configfile, | ||||
) | ) | ||||
from swh.vault.tests.test_backend import TEST_HEX_ID | from swh.vault.tests.test_backend import TEST_SWHID | ||||
def test_make_app_from_file_missing(): | def test_make_app_from_file_missing(): | ||||
with pytest.raises(ValueError, match="Missing configuration path."): | with pytest.raises(ValueError, match="Missing configuration path."): | ||||
make_app_from_configfile() | make_app_from_configfile() | ||||
def test_make_app_from_file_does_not_exist(tmp_path): | def test_make_app_from_file_does_not_exist(tmp_path): | ||||
▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | |||||
async def test_client_index(cli): | async def test_client_index(cli): | ||||
resp = await cli.get("/") | resp = await cli.get("/") | ||||
assert resp.status == 200 | assert resp.status == 200 | ||||
async def test_client_cook_notfound(cli): | async def test_client_cook_notfound(cli): | ||||
resp = await cli.post( | resp = await cli.post( | ||||
"/cook", | "/cook", | ||||
data=json_dumps({"bundle_type": "directory", "obj_id": TEST_HEX_ID}), | data=json_dumps( | ||||
{"bundle_type": "flat", "swhid": TEST_SWHID}, extra_encoders=ENCODERS | |||||
), | |||||
headers=[("Content-Type", "application/json")], | headers=[("Content-Type", "application/json")], | ||||
) | ) | ||||
assert resp.status == 400 | assert resp.status == 400 | ||||
content = msgpack_loads(await resp.content.read()) | content = msgpack_loads(await resp.content.read()) | ||||
assert content["type"] == "NotFoundExc" | assert content["type"] == "NotFoundExc" | ||||
assert content["args"] == [f"directory {TEST_HEX_ID} was not found."] | assert content["args"] == [f"flat {TEST_SWHID} was not found."] | ||||
async def test_client_progress_notfound(cli): | async def test_client_progress_notfound(cli): | ||||
resp = await cli.post( | resp = await cli.post( | ||||
"/progress", | "/progress", | ||||
data=json_dumps({"bundle_type": "directory", "obj_id": TEST_HEX_ID}), | data=json_dumps( | ||||
{"bundle_type": "flat", "swhid": TEST_SWHID}, extra_encoders=ENCODERS | |||||
), | |||||
headers=[("Content-Type", "application/json")], | headers=[("Content-Type", "application/json")], | ||||
) | ) | ||||
assert resp.status == 400 | assert resp.status == 400 | ||||
content = msgpack_loads(await resp.content.read()) | content = msgpack_loads(await resp.content.read()) | ||||
assert content["type"] == "NotFoundExc" | assert content["type"] == "NotFoundExc" | ||||
assert content["args"] == [f"directory {TEST_HEX_ID} was not found."] | assert content["args"] == [f"flat {TEST_SWHID} was not found."] | ||||
async def test_client_batch_cook_invalid_type(cli): | async def test_client_batch_cook_invalid_type(cli): | ||||
resp = await cli.post( | resp = await cli.post( | ||||
"/batch_cook", | "/batch_cook", | ||||
data=msgpack_dumps({"batch": [("foobar", [])]}), | data=msgpack_dumps({"batch": [("foobar", [])]}), | ||||
headers={"Content-Type": "application/x-msgpack"}, | headers={"Content-Type": "application/x-msgpack"}, | ||||
) | ) | ||||
▲ Show 20 Lines • Show All 50 Lines • Show Last 20 Lines |