File size: 2,705 Bytes
d086025
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
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