-
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.
- Loading branch information
Showing
5 changed files
with
100 additions
and
64 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
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
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
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
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 |
---|---|---|
|
@@ -4,50 +4,6 @@ | |
from api.constants import constants | ||
|
||
|
||
def test_create_archive_correct_data(logged_in_client, project_id): | ||
data = { | ||
"filename": "test_name", | ||
"email": "[email protected]", | ||
"config": { | ||
"title": "test_title", | ||
"description": "test_description", | ||
"name": "test_name", | ||
"publisher": "test_publisher", | ||
"creator": "test_creator", | ||
"languages": ["en"], | ||
"tags": ["test_tags"], | ||
}, | ||
} | ||
response = logged_in_client.post( | ||
f"{constants.api_version_prefix}/projects/{project_id}/archives", json=data | ||
) | ||
assert response.status_code == HTTPStatus.CREATED | ||
json_result = response.json() | ||
assert uuid.UUID(json_result.get("id")) | ||
assert json_result.get("filename") == "test_name" | ||
assert json_result.get("email") == "[email protected]" | ||
assert json_result.get("config").get("title") == "test_title" | ||
assert json_result.get("config").get("description") == "test_description" | ||
assert json_result.get("config").get("name") == "test_name" | ||
assert json_result.get("config").get("publisher") == "test_publisher" | ||
assert json_result.get("config").get("creator") == "test_creator" | ||
assert json_result.get("config").get("languages")[0] == "en" | ||
assert json_result.get("config").get("tags")[0] == "test_tags" | ||
|
||
|
||
def test_create_archive_wrong_authorization(client, project_id, missing_user_cookie): | ||
response = client.post( | ||
f"{constants.api_version_prefix}/projects/{project_id}/archives" | ||
) | ||
assert response.status_code == HTTPStatus.UNAUTHORIZED | ||
|
||
client.cookies = missing_user_cookie | ||
response = client.post( | ||
f"{constants.api_version_prefix}/projects/{project_id}/archives" | ||
) | ||
assert response.status_code == HTTPStatus.UNAUTHORIZED | ||
|
||
|
||
def test_get_all_archive_correct_data(logged_in_client, project_id, archive_id): | ||
response = logged_in_client.get( | ||
f"{constants.api_version_prefix}/projects/{project_id}/archives" | ||
|
@@ -105,9 +61,9 @@ def test_get_archive_wrong_authorization( | |
|
||
def test_update_archive_correct_data(logged_in_client, project_id, archive_id): | ||
data = { | ||
"filename": "test_name", | ||
"email": "[email protected]", | ||
"config": { | ||
"filename": "test_name", | ||
"title": "test_title", | ||
"description": "test_description", | ||
"name": "test_name", | ||
|
@@ -128,8 +84,8 @@ def test_update_archive_correct_data(logged_in_client, project_id, archive_id): | |
f"{constants.api_version_prefix}/projects/{project_id}/archives/{archive_id}", | ||
) | ||
json_result = response.json() | ||
assert json_result.get("filename") == "test_name" | ||
assert json_result.get("email") == "[email protected]" | ||
assert json_result.get("config").get("filename") == "test_name" | ||
assert json_result.get("config").get("title") == "test_title" | ||
assert json_result.get("config").get("description") == "test_description" | ||
assert json_result.get("config").get("name") == "test_name" | ||
|
@@ -141,9 +97,9 @@ def test_update_archive_correct_data(logged_in_client, project_id, archive_id): | |
|
||
def test_update_archive_wrong_id(logged_in_client, project_id, missing_archive_id): | ||
data = { | ||
"filename": "test_name", | ||
"email": "[email protected]", | ||
"config": { | ||
"filename": "test_name", | ||
"title": "test_title", | ||
"description": "test_description", | ||
"name": "test_name", | ||
|
@@ -165,9 +121,9 @@ def test_update_archive_wrong_authorization( | |
client, missing_user_cookie, project_id, archive_id | ||
): | ||
data = { | ||
"filename": "test_name", | ||
"email": "[email protected]", | ||
"config": { | ||
"filename": "test_name", | ||
"title": "test_title", | ||
"description": "test_description", | ||
"name": "test_name", | ||
|
@@ -189,3 +145,72 @@ def test_update_archive_wrong_authorization( | |
json=data, | ||
) | ||
assert response.status_code == HTTPStatus.UNAUTHORIZED | ||
|
||
|
||
def test_upload_illustration_correct_data( | ||
logged_in_client, project_id, test_png_image, archive_id | ||
): | ||
file = {"uploaded_illustration": test_png_image} | ||
response = logged_in_client.post( | ||
f"{constants.api_version_prefix}/projects/{project_id}/archives/{archive_id}/illustration", | ||
files=file, | ||
) | ||
assert response.status_code == HTTPStatus.CREATED | ||
|
||
|
||
def test_upload_illustration_other_format(logged_in_client, project_id, archive_id): | ||
test_image = ( | ||
b"GIF89a\x01\x00\x01\x00\x80\x00\x00\xff\xff\xff\x00\x00\x00," | ||
b"\x00\x00\x00\x00\x01\x00\x01\x00\x00\x02\x02D\x01\x00;" | ||
) | ||
file = {"uploaded_illustration": test_image} | ||
response = logged_in_client.post( | ||
f"{constants.api_version_prefix}/projects/{project_id}/archives/{archive_id}/illustration", | ||
files=file, | ||
) | ||
assert response.status_code == HTTPStatus.CREATED | ||
|
||
|
||
def test_upload_illustration_empty_file(logged_in_client, project_id, archive_id): | ||
file = {"uploaded_illustration": b""} | ||
response = logged_in_client.post( | ||
f"{constants.api_version_prefix}/projects/{project_id}/archives/{archive_id}/illustration", | ||
files=file, | ||
) | ||
assert response.status_code == HTTPStatus.BAD_REQUEST | ||
|
||
|
||
def test_upload_too_large_illustration(logged_in_client, project_id, archive_id): | ||
file = {"uploaded_illustration": b"\xff" * (constants.illustration_quota + 1)} | ||
response = logged_in_client.post( | ||
f"{constants.api_version_prefix}/projects/{project_id}/archives/{archive_id}/illustration", | ||
files=file, | ||
) | ||
assert response.status_code == HTTPStatus.REQUEST_ENTITY_TOO_LARGE | ||
|
||
|
||
def test_upload_none_image_illustration(logged_in_client, project_id, archive_id): | ||
file = {"uploaded_illustration": b"\xff"} | ||
response = logged_in_client.post( | ||
f"{constants.api_version_prefix}/projects/{project_id}/archives/{archive_id}/illustration", | ||
files=file, | ||
) | ||
assert response.status_code == HTTPStatus.BAD_REQUEST | ||
|
||
|
||
def test_upload_illustration_without_wrong_authorization( | ||
client, missing_user_cookie, project_id, archive_id, test_png_image | ||
): | ||
file = {"uploaded_illustration": test_png_image} | ||
response = client.post( | ||
f"{constants.api_version_prefix}/projects/{project_id}/archives/{archive_id}/illustration", | ||
files=file, | ||
) | ||
assert response.status_code == HTTPStatus.UNAUTHORIZED | ||
|
||
client.cookies = missing_user_cookie | ||
response = client.post( | ||
f"{constants.api_version_prefix}/projects/{project_id}/archives/{archive_id}/illustration", | ||
files=file, | ||
) | ||
assert response.status_code == HTTPStatus.UNAUTHORIZED |