Skip to content

Commit 6b7e18d

Browse files
committed
removed irrelevant tested and added new tests
1 parent bde4655 commit 6b7e18d

File tree

1 file changed

+13
-92
lines changed

1 file changed

+13
-92
lines changed

tests/telemetry/test_telemetry.py

Lines changed: 13 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,20 @@
1212
# License for the specific language governing permissions and limitations
1313
# under the License.
1414

15+
import asyncio
16+
import os
17+
1518
import pytest
19+
1620
from supertokens_python import InputAppInfo, Supertokens, SupertokensConfig, init
1721
from supertokens_python.recipe import session
18-
import asyncio
1922
from tests.utils import reset
2023

2124

2225
@pytest.mark.asyncio
23-
async def test_asgi_telemetry():
26+
async def test_telemetry():
2427
reset()
25-
with pytest.warns(None) as record:
28+
with pytest.warns(None) as _:
2629
init(
2730
supertokens_config=SupertokensConfig("http://localhost:3567"),
2831
app_info=InputAppInfo(
@@ -44,20 +47,16 @@ async def test_asgi_telemetry():
4447
)
4548
await asyncio.sleep(1)
4649

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
5351

54-
assert Supertokens.get_instance()._telemetry_status == "SKIPPED" # type: ignore pylint: disable=W0212
52+
assert Supertokens.get_instance().telemetry
5553

5654

5755
@pytest.mark.asyncio
58-
async def test_asgi_telemetry_with_wrong_mode():
56+
async def test_read_from_env():
5957
reset()
60-
with pytest.warns(None) as record:
58+
os.environ["TEST_MODE"] = "testing"
59+
with pytest.warns(None) as _:
6160
init(
6261
supertokens_config=SupertokensConfig("http://localhost:3567"),
6362
app_info=InputAppInfo(
@@ -67,75 +66,6 @@ async def test_asgi_telemetry_with_wrong_mode():
6766
api_base_path="/auth",
6867
),
6968
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",
13969
mode="asgi",
14070
recipe_list=[
14171
session.init(
@@ -144,16 +74,7 @@ def test_wsgi_telemetry_with_wrong_mode():
14474
override=session.InputOverrideConfig(),
14575
)
14676
],
147-
telemetry=True,
14877
)
78+
await asyncio.sleep(1)
14979

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

Comments
 (0)