12
12
# License for the specific language governing permissions and limitations
13
13
# under the License.
14
14
15
+ import asyncio
16
+ import os
17
+
15
18
import pytest
19
+
16
20
from supertokens_python import InputAppInfo , Supertokens , SupertokensConfig , init
17
21
from supertokens_python .recipe import session
18
- import asyncio
19
22
from tests .utils import reset
20
23
21
24
22
25
@pytest .mark .asyncio
23
- async def test_asgi_telemetry ():
26
+ async def test_telemetry ():
24
27
reset ()
25
- with pytest .warns (None ) as record :
28
+ with pytest .warns (None ) as _ :
26
29
init (
27
30
supertokens_config = SupertokensConfig ("http://localhost:3567" ),
28
31
app_info = InputAppInfo (
@@ -44,20 +47,16 @@ async def test_asgi_telemetry():
44
47
)
45
48
await asyncio .sleep (1 )
46
49
47
- for warn in record :
48
- if warn .category is RuntimeWarning :
49
- if "telemetry" in str (warn .message ) and "was never awaited" in str (
50
- warn .message
51
- ):
52
- assert False , "Asyncio error"
50
+ assert Supertokens .get_instance ().telemetry is not None
53
51
54
- assert Supertokens .get_instance ()._telemetry_status == "SKIPPED" # type: ignore pylint: disable=W0212
52
+ assert Supertokens .get_instance ().telemetry
55
53
56
54
57
55
@pytest .mark .asyncio
58
- async def test_asgi_telemetry_with_wrong_mode ():
56
+ async def test_read_from_env ():
59
57
reset ()
60
- with pytest .warns (None ) as record :
58
+ os .environ ["TEST_MODE" ] = "testing"
59
+ with pytest .warns (None ) as _ :
61
60
init (
62
61
supertokens_config = SupertokensConfig ("http://localhost:3567" ),
63
62
app_info = InputAppInfo (
@@ -67,75 +66,6 @@ async def test_asgi_telemetry_with_wrong_mode():
67
66
api_base_path = "/auth" ,
68
67
),
69
68
framework = "fastapi" ,
70
- mode = "wsgi" ,
71
- recipe_list = [
72
- session .init (
73
- anti_csrf = "VIA_TOKEN" ,
74
- cookie_domain = "supertokens.io" ,
75
- override = session .InputOverrideConfig (),
76
- )
77
- ],
78
- telemetry = True ,
79
- )
80
- await asyncio .sleep (1 )
81
-
82
- found_warning = False
83
- for warn in record :
84
- if warn .category is RuntimeWarning :
85
- found_warning = found_warning or "Inconsistent mode detected" in str (
86
- warn .message
87
- )
88
-
89
- assert found_warning , "Asyncio error"
90
-
91
- assert Supertokens .get_instance ()._telemetry_status == "SKIPPED" # type: ignore pylint: disable=W0212
92
-
93
-
94
- def test_wsgi_telemetry ():
95
- reset ()
96
- with pytest .warns (None ) as record :
97
- init (
98
- supertokens_config = SupertokensConfig ("http://localhost:3567" ),
99
- app_info = InputAppInfo (
100
- app_name = "SuperTokens Demo" ,
101
- api_domain = "http://api.supertokens.io" ,
102
- website_domain = "http://supertokens.io" ,
103
- api_base_path = "/auth" ,
104
- ),
105
- framework = "flask" ,
106
- mode = "wsgi" ,
107
- recipe_list = [
108
- session .init (
109
- anti_csrf = "VIA_TOKEN" ,
110
- cookie_domain = "supertokens.io" ,
111
- override = session .InputOverrideConfig (),
112
- )
113
- ],
114
- telemetry = True ,
115
- )
116
-
117
- for warn in record :
118
- if warn .category is RuntimeWarning :
119
- if "telemetry" in str (warn .message ) and "was never awaited" in str (
120
- warn .message
121
- ):
122
- assert False , "Asyncio error"
123
-
124
- assert Supertokens .get_instance ()._telemetry_status == "SKIPPED" # type: ignore pylint: disable=W0212
125
-
126
-
127
- def test_wsgi_telemetry_with_wrong_mode ():
128
- reset ()
129
- with pytest .warns (None ) as record :
130
- init (
131
- supertokens_config = SupertokensConfig ("http://localhost:3567" ),
132
- app_info = InputAppInfo (
133
- app_name = "SuperTokens Demo" ,
134
- api_domain = "http://api.supertokens.io" ,
135
- website_domain = "http://supertokens.io" ,
136
- api_base_path = "/auth" ,
137
- ),
138
- framework = "flask" ,
139
69
mode = "asgi" ,
140
70
recipe_list = [
141
71
session .init (
@@ -144,16 +74,7 @@ def test_wsgi_telemetry_with_wrong_mode():
144
74
override = session .InputOverrideConfig (),
145
75
)
146
76
],
147
- telemetry = True ,
148
77
)
78
+ await asyncio .sleep (1 )
149
79
150
- found_warning = False
151
- for warn in record :
152
- if warn .category is RuntimeWarning :
153
- found_warning = found_warning or "Inconsistent mode detected" in str (
154
- warn .message
155
- )
156
-
157
- assert found_warning , "Asyncio error"
158
-
159
- assert Supertokens .get_instance ()._telemetry_status == "SKIPPED" # type: ignore pylint: disable=W0212
80
+ assert not Supertokens .get_instance ().telemetry
0 commit comments