Browse Source

[Python/robyn]: add JSON test (#8557)

Kamil Gałuszka 1 year ago
parent
commit
9a69933ced

+ 12 - 3
frameworks/Python/robyn/app-const.py

@@ -1,7 +1,7 @@
 import multiprocessing
 import os
 
-from robyn import Robyn
+from robyn import Response, Robyn, jsonify
 from robyn.argument_parser import Config
 
 
@@ -21,8 +21,17 @@ def plaintext() -> str:
     return "Hello, world!"
 
 
[email protected]("/json", const=True)
+def json() -> str:
+    return Response(
+        status_code=200,
+        description=jsonify({"message": "Hello, world!"}),
+        headers={"Content-Type": "application/json"}
+        )
+
+
+
 if __name__ == "__main__":
     app.add_response_header("Server", "Robyn")
-    app.add_response_header("Content-Type", "text/plain")
 
-    app.start(url="0.0.0.0", port=8080)
+    app.start(host="0.0.0.0", port=8080)

+ 12 - 5
frameworks/Python/robyn/app.py

@@ -1,7 +1,7 @@
 import multiprocessing
 import os
 
-from robyn import Robyn
+from robyn import Response, Robyn, jsonify
 from robyn.argument_parser import Config
 
 
@@ -21,8 +21,15 @@ def plaintext() -> str:
     return "Hello, world!"
 
 
-if __name__ == "__main__":
-    app.add_response_header("Server", "Robyn")
-    app.add_response_header("Content-Type", "text/plain")
[email protected]("/json")
+def json() -> str:
+    return Response(
+        status_code=200,
+        description=jsonify({"message": "Hello, world!"}),
+        headers={"Content-Type": "application/json"}
+        )
+
 
-    app.start(url="0.0.0.0", port=8080)
+if __name__ == "__main__":
+    app.add_response_header("Server", "Roby1n")
+    app.start(host="0.0.0.0", port=8080)

+ 2 - 0
frameworks/Python/robyn/benchmark_config.json

@@ -3,6 +3,7 @@
   "tests": [
     {
       "default": {
+        "json_url": "/json",
         "plaintext_url": "/plaintext",
         "port": 8080,
         "approach": "Realistic",
@@ -19,6 +20,7 @@
         "versus": "None"
       },
       "const": {
+        "json_url": "/json",
         "plaintext_url": "/plaintext",
         "port": 8080,
         "approach": "Realistic",

+ 2 - 0
frameworks/Python/robyn/config.toml

@@ -3,6 +3,7 @@ name = "Robyn"
 
 [main]
 urls.plaintext = "/plaintext"
+urls.json = "/json"
 approach = "Realistic"
 classification = "Micro"
 os = "Linux"
@@ -13,6 +14,7 @@ versus = "None"
 
 [const]
 urls.plaintext = "/plaintext"
+urls.json = "/json"
 approach = "Realistic"
 classification = "Micro"
 os = "Linux"

+ 2 - 2
frameworks/Python/robyn/requirements-const.txt

@@ -1,2 +1,2 @@
-uvloop==0.17.0
-robyn==0.37.0
+uvloop==0.19.0
+robyn==0.45.0

+ 2 - 2
frameworks/Python/robyn/requirements.txt

@@ -1,2 +1,2 @@
-uvloop==0.17.0
-robyn==0.37.0
+uvloop==0.19.0
+robyn==0.45.0

+ 1 - 1
frameworks/Python/robyn/robyn-const.dockerfile

@@ -1,4 +1,4 @@
-FROM python:3.11
+FROM python:3.12
 
 ADD ./ /robyn
 

+ 1 - 1
frameworks/Python/robyn/robyn.dockerfile

@@ -1,4 +1,4 @@
-FROM python:3.9
+FROM python:3.12
 
 ADD ./ /robyn