Skip to content

Commit

Permalink
test(validators) add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
ElJocho authored and matthiasschaub committed Oct 16, 2023
1 parent f26a35c commit 5882146
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
11 changes: 6 additions & 5 deletions sketch_map_tool/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def validate_type(type_: REQUEST_TYPES):


def validate_uploaded_sketchmap(file):
"""Validation function for uploaded files."""
max_single_file_size = int(get_config_value("max_single_file_size"))
max_pixel_per_image = int(get_config_value("max_pixel_per_image"))

Expand Down Expand Up @@ -50,19 +51,19 @@ def validate_uuid(uuid: str):
raise ValueError("The provided URL does not contain a valid UUID") from error


def validate_literature_reference(literatur_reference: LiteratureReference):
"""Validate literatur reference to not include empty strings."""
if literatur_reference.citation == "":
def validate_literature_reference(literature_reference: LiteratureReference):
"""Validate literature reference to not include empty strings."""
if literature_reference.citation == "":
raise ValueError(
"Literature reference JSON fields "
"should not contain empty strings as values."
)
if literatur_reference.img_src == "":
if literature_reference.img_src == "":
raise ValueError(
"Literature reference JSON fields should "
"not contain empty strings as values."
)
if literatur_reference.url == "":
if literature_reference.url == "":
raise ValueError(
"Literature reference JSON fields should "
"not contain empty strings as values."
Expand Down
19 changes: 18 additions & 1 deletion tests/unit/test_validators.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import pytest

from sketch_map_tool.validators import validate_type, validate_uuid
from sketch_map_tool.exceptions import UploadLimitsExceededError
from sketch_map_tool.validators import (
validate_type,
validate_uploaded_sketchmap,
validate_uuid,
)


@pytest.mark.parametrize(
Expand All @@ -17,6 +22,18 @@ def test_validate_type_invalid(type_):
validate_type(type_)


def test_validate_file_by_pixel_count(files, monkeypatch):
with pytest.raises(UploadLimitsExceededError):
monkeypatch.setenv("MAX-PIXEL-PER-IMAGE", "10")
validate_uploaded_sketchmap(files[0])


def test_validate_file_by_size(files, monkeypatch):
with pytest.raises(UploadLimitsExceededError):
monkeypatch.setenv("MAX-SINGLE-FILE-SIZE", "10")
validate_uploaded_sketchmap(files[1])


def test_validate_uui(uuid):
validate_uuid(uuid)

Expand Down

0 comments on commit 5882146

Please sign in to comment.