-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_server.py
More file actions
64 lines (58 loc) · 2.13 KB
/
test_server.py
File metadata and controls
64 lines (58 loc) · 2.13 KB
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
import unittest
from polyapi.utils import to_func_namespace
from .test_api import TWILIO
from polyapi.server import render_server_function
GET_PRODUCTS_COUNT = {
"id": "8f7d24b0-4a29-40c0-9091",
"type": "serverFunction",
"context": "test",
"name": "getProductsCount111",
"description": "An API call to retrieve the count of products in the product list.",
"requirements": ["snabbdom"],
"function": {
"arguments": [
{
"name": "products",
"required": False,
"type": {
"kind": "array",
"items": {"kind": "primitive", "type": "string"},
},
}
],
"returnType": {"kind": "plain", "value": "number"},
"synchronous": True,
},
"code": "",
"language": "javascript",
"visibilityMetadata": {"visibility": "ENVIRONMENT"},
}
class T(unittest.TestCase):
def test_render_function_twilio_server(self):
# same test but try it as a serverFunction rather than an apiFunction
name = TWILIO["name"]
func_str, _ = render_server_function(
"serverFunction",
TWILIO["name"],
TWILIO["id"],
TWILIO["description"],
TWILIO["function"]["arguments"],
TWILIO["function"]["returnType"],
)
self.assertIn(TWILIO["id"], func_str)
self.assertIn("conversationSID: str", func_str)
self.assertIn("authToken: str", func_str)
self.assertIn(f"-> {to_func_namespace(name)}.ResponseType", func_str)
def test_render_function_get_products_count(self):
return_type = GET_PRODUCTS_COUNT["function"]["returnType"]
func_str, _ = render_server_function(
GET_PRODUCTS_COUNT["type"],
GET_PRODUCTS_COUNT["name"],
GET_PRODUCTS_COUNT["id"],
GET_PRODUCTS_COUNT["description"],
GET_PRODUCTS_COUNT["function"]["arguments"],
return_type,
)
self.assertIn(GET_PRODUCTS_COUNT["id"], func_str)
self.assertIn("products: List[str]", func_str)
self.assertIn("-> float", func_str)