diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_main.py b/tests/test_main.py new file mode 100644 --- /dev/null +++ b/tests/test_main.py @@ -0,0 +1,2 @@ +def test_main(): + assert True diff --git a/tests/test_parsers.py b/tests/test_parsers.py new file mode 100644 --- /dev/null +++ b/tests/test_parsers.py @@ -0,0 +1,34 @@ +import pytest + +from loafang._dataclasses import Header +from loafang._parsers import HeaderParser + + +@pytest.mark.parametrize( + 'input,output', + ( + ("GET:test-id:pe", (Header("GET", "test-id", "pe"), None, None)), + ("GET:test-id:", (Header("GET", "test-id", None), None, None)), + ("GET:test-id", (Header("GET", "test-id", None), None, None)), + ("POST:add-user:", (Header("POST", "add-user", None), None, None)), + ("DELETE:remove-mail", (Header("DELETE", "remove-mail", None), None, None)), + ) +) +def test_header_parser_pass(input, output): + assert HeaderParser(input).parse() == output + + +@pytest.mark.parametrize( + 'input,output', + ( + ("get", (None, 604, "Missing ID.")), + ("GETS", (None, 604, "Missing ID.")), + ("GETS:test-id", (None, 602, "The method 'GETS' does not exists.")), + ("get:test-id", (None, 602, "The method 'get' does not exists.")), + ("", (None, 601, "The header cannot be empty.")), + ("GET:id:pe:test", (None, 600, "The header cannot be more than 3 parts.")), + ("GET:id:p4", (None, 603, "The property key 'p4' does not exists.")), + ) +) +def test_header_parser_error(input, output): + assert HeaderParser(input).parse() == output diff --git a/tests/test_query.py b/tests/test_query.py new file mode 100644 --- /dev/null +++ b/tests/test_query.py @@ -0,0 +1,18 @@ +import pytest + +from loafang.query import gen_arg_name + + +@pytest.mark.parametrize( + 'input,output', + ( + ("name", "--name"), + ("-name", "--name"), + ("---name", "--name"), + ("c42", "--c42"), + ("42", "--42"), + + ) +) +def test_gen_arg_name(input, output): + assert gen_arg_name(input) == output diff --git a/tests/test_utils.py b/tests/test_utils.py new file mode 100644 --- /dev/null +++ b/tests/test_utils.py @@ -0,0 +1,16 @@ +import pytest + +from loafang.utils import err_msg + + +@pytest.mark.parametrize( + ("input", "output"), + ( + (600, "Something went wrong."), + (605, "Invalid data type for the argument in the query."), + (612, "Execution block with pe property key cannot have an after key"), + (500, "") + ) +) +def test_err_msg(input, output): + assert err_msg(input) == output