-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add tests for static file route
- Loading branch information
Showing
3 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# This file is part of the QuestionPy Server. (https://questionpy.org) | ||
# The QuestionPy Server is free software released under terms of the MIT license. See LICENSE.md. | ||
# (c) Technische Universität Berlin, innoCampus <[email protected]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# This file is part of the QuestionPy Server. (https://questionpy.org) | ||
# The QuestionPy Server is free software released under terms of the MIT license. See LICENSE.md. | ||
# (c) Technische Universität Berlin, innoCampus <[email protected]> | ||
import pytest | ||
from aiohttp.test_utils import TestClient | ||
|
||
from tests.conftest import PACKAGE, TestPackageFactory, TestZipPackage | ||
|
||
|
||
@pytest.fixture | ||
def package(package_factory: TestPackageFactory) -> TestZipPackage: | ||
dir_package = package_factory.to_dir_package(PACKAGE) | ||
dir_package.inject_static_file("static/path/to/file.pdf", b"some data") | ||
return package_factory.to_zip_package(dir_package) | ||
|
||
|
||
async def test_should_get_static_file(client: TestClient, package: TestZipPackage) -> None: | ||
with package.path.open("rb") as package_fd: | ||
res = await client.post( | ||
f"/packages/{package.hash}/file/local/package_1/static/path/to/file.pdf", data={"package": package_fd} | ||
) | ||
|
||
assert res.status == 200 | ||
assert res.content_type == "application/pdf" | ||
assert await res.read() == b"some data" | ||
|
||
|
||
async def test_should_return_not_implemented_when_not_main_package(client: TestClient, package: TestZipPackage) -> None: | ||
with package.path.open("rb") as package_fd: | ||
res = await client.post( | ||
f"/packages/{package.hash}/file/some_other_ns/and_short_name/static/path/to/file.pdf", | ||
data={"package": package_fd} | ||
) | ||
|
||
assert res.status == 501 | ||
assert "Static file retrieval from non-main packages is not supported yet." in await res.text() | ||
|
||
|
||
async def test_should_return_not_found_when_file_does_not_exist(client: TestClient, package: TestZipPackage) -> None: | ||
with package.path.open("rb") as package_fd: | ||
res = await client.post( | ||
f"/packages/{package.hash}/file/local/package_1/static/wrong/path/to/file.pdf", | ||
data={"package": package_fd} | ||
) | ||
|
||
assert res.status == 404 |
File renamed without changes.