Pārlūkot izejas kodu

Fix REST API and tests.

scossu 8 mēneši atpakaļ
vecāks
revīzija
bd4351d2e6
2 mainītis faili ar 17 papildinājumiem un 19 dzēšanām
  1. 1 1
      scriptshifter/rest_api.py
  2. 16 18
      tests/test04_rest_api.py

+ 1 - 1
scriptshifter/rest_api.py

@@ -82,7 +82,7 @@ def transliterate_req():
 
     if not len(in_txt):
         return ("No input text provided! ", 400)
-    options = loads(request.form.get("options", {}))
+    options = loads(request.form.get("options", "{}"))
     logger.debug(f"Extra options: {options}")
 
     try:

+ 16 - 18
tests/test03_rest_api.py → tests/test04_rest_api.py

@@ -54,7 +54,7 @@ class TestRestAPI(TestCase):
 
     def test_trans_api_s2r(self):
         with app.test_client() as c:
-            rsp = c.post("/trans/rot3", data={"text": "defg"})
+            rsp = c.post("/trans", data={"lang": "rot3", "text": "defg"})
 
         self.assertEqual(rsp.status_code, 200)
         data = json.loads(rsp.get_data(as_text=True))
@@ -63,7 +63,13 @@ class TestRestAPI(TestCase):
 
     def test_trans_api_r2s(self):
         with app.test_client() as c:
-            rsp = c.post("/trans/rot3/r2s", data={"text": "abcd"})
+            rsp = c.post(
+                "/trans", data={
+                    "lang": "rot3",
+                    "text": "abcd",
+                    "t_dir": "r2s"
+                }
+            )
 
         self.assertEqual(rsp.status_code, 200)
         data = json.loads(rsp.get_data(as_text=True))
@@ -73,24 +79,16 @@ class TestRestAPI(TestCase):
     def test_trans_api_capitalize(self):
         with app.test_client() as c:
             rsp = c.post(
-                    "/trans/rot3/r2s",
-                    data={"capitalize": "first", "text": "bcde"})
+                "/trans",
+                data={
+                    "lang": "rot3",
+                    "capitalize": "first",
+                    "text": "bcde",
+                    "t_dir": "r2s"
+                }
+            )
 
         self.assertEqual(rsp.status_code, 200)
         data = json.loads(rsp.get_data(as_text=True))
 
         self.assertEqual(data["output"], "Efgh")
-
-    def test_trans_form(self):
-        with app.test_client() as c:
-            rsp = c.post(
-                    "/transliterate", data={
-                        "text": "abcd",
-                        "r2s": "true",
-                        "lang": "rot3",
-                    })
-
-        self.assertEqual(rsp.status_code, 200)
-        data = json.loads(rsp.get_data(as_text=True))
-
-        self.assertEqual(data["output"], "defg")