-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_auth.py
More file actions
138 lines (134 loc) · 5.21 KB
/
test_auth.py
File metadata and controls
138 lines (134 loc) · 5.21 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
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import unittest
from polyapi.auth import render_auth_function
GET_TOKEN = {
"type": "authFunction",
"id": "dummyid",
"context": "auth0.authCodeFlow",
"name": "getToken",
"description": "This function obtains a token from authO using the OAuth 2.0 authorization code flow. It will return a login url if the user needs to log in, a token once they are logged in, and an error if the user fails to log in. It allows an optional callback url where the user is going to be redirected after log in. If the refresh token flow is enabled, the refresh token will be stored on the poly server.",
"function": {
"arguments": [
{
"name": "clientId",
"required": True,
"type": {"kind": "primitive", "type": "string"},
},
{
"name": "clientSecret",
"required": True,
"type": {"kind": "primitive", "type": "string"},
},
{
"name": "scopes",
"required": True,
"type": {
"kind": "array",
"items": {"kind": "primitive", "type": "string"},
},
},
{
"name": "callback",
"required": True,
"type": {
"kind": "function",
"name": "AuthFunctionCallback",
"spec": {
"arguments": [
{
"name": "token",
"required": False,
"nullable": True,
"type": {"kind": "primitive", "type": "string"},
},
{
"name": "url",
"required": False,
"type": {"kind": "primitive", "type": "string"},
},
{
"name": "error",
"required": False,
"nullable": True,
"type": {"kind": "primitive", "type": "object"},
},
],
"returnType": {"kind": "void"},
"synchronous": True,
},
},
},
{
"name": "options",
"required": False,
"type": {
"kind": "object",
"properties": [
{
"name": "callbackUrl",
"required": False,
"type": {"kind": "primitive", "type": "string"},
},
{
"name": "timeout",
"required": False,
"type": {"kind": "primitive", "type": "number"},
},
{
"name": "audience",
"required": False,
"type": {"kind": "primitive", "type": "string"},
},
{
"name": "autoCloseOnToken",
"required": False,
"type": {"kind": "primitive", "type": "boolean"},
},
{
"name": "autoCloseOnUrl",
"required": False,
"type": {"kind": "primitive", "type": "boolean"},
},
{
"name": "userId",
"required": False,
"type": {"kind": "primitive", "type": "string"},
},
],
},
},
],
"returnType": {
"kind": "object",
"properties": [
{
"name": "close",
"type": {
"kind": "function",
"spec": {
"arguments": [],
"returnType": {"kind": "void"},
"synchronous": True,
},
},
"required": True,
}
],
},
"synchronous": True,
},
"visibilityMetadata": {"visibility": "ENVIRONMENT"},
}
class T(unittest.TestCase):
def test_render_get_token(self):
# same test but try it as a serverFunction rather than an apiFunction
func_str, _ = render_auth_function(
"atuhFunction",
GET_TOKEN["name"],
GET_TOKEN["id"],
GET_TOKEN["description"],
GET_TOKEN["function"]["arguments"],
GET_TOKEN["function"]["returnType"],
)
self.assertIn(GET_TOKEN["id"], func_str)
# self.assertIn("conversationSID: str", func_str)
# self.assertIn("authToken: str", func_str)