77from selenium .common .exceptions import NoSuchElementException
88from selenium .webdriver .common .by import By
99
10+ from reflex import constants
11+ from reflex .config import environment
1012from reflex .testing import AppHarness , WebDriver
1113
1214from .utils import SessionStorage
1315
1416
15- def ConnectionBanner (is_reflex_cloud : bool = False ):
16- """App with a connection banner.
17-
18- Args:
19- is_reflex_cloud: The value for config.is_reflex_cloud.
20- """
17+ def ConnectionBanner ():
18+ """App with a connection banner."""
2119 import asyncio
2220
2321 import reflex as rx
2422
25- # Simulate reflex cloud deploy
26- rx .config .get_config ().is_reflex_cloud = is_reflex_cloud
27-
2823 class State (rx .State ):
2924 foo : int = 0
3025
@@ -49,42 +44,45 @@ def index():
4944
5045
5146@pytest .fixture (
52- params = [False , True ], ids = ["reflex_cloud_disabled" , "reflex_cloud_enabled" ]
47+ params = [constants .CompileContext .RUN , constants .CompileContext .DEPLOY ],
48+ ids = ["compile_context_run" , "compile_context_deploy" ],
5349)
54- def simulate_is_reflex_cloud (request ) -> bool :
50+ def simulate_compile_context (request ) -> constants . CompileContext :
5551 """Fixture to simulate reflex cloud deployment.
5652
5753 Args:
5854 request: pytest request fixture.
5955
6056 Returns:
61- True if reflex cloud is enabled, False otherwise .
57+ The context to run the app with .
6258 """
6359 return request .param
6460
6561
6662@pytest .fixture ()
6763def connection_banner (
6864 tmp_path ,
69- simulate_is_reflex_cloud : bool ,
65+ simulate_compile_context : constants . CompileContext ,
7066) -> Generator [AppHarness , None , None ]:
7167 """Start ConnectionBanner app at tmp_path via AppHarness.
7268
7369 Args:
7470 tmp_path: pytest tmp_path fixture
75- simulate_is_reflex_cloud: Whether is_reflex_cloud is set for the app.
71+ simulate_compile_context: Which context to run the app with .
7672
7773 Yields:
7874 running AppHarness instance
7975 """
76+ environment .REFLEX_COMPILE_CONTEXT .set (simulate_compile_context )
77+
8078 with AppHarness .create (
8179 root = tmp_path ,
82- app_source = functools .partial (
83- ConnectionBanner , is_reflex_cloud = simulate_is_reflex_cloud
80+ app_source = functools .partial (ConnectionBanner ),
81+ app_name = (
82+ "connection_banner_reflex_cloud"
83+ if simulate_compile_context == constants .CompileContext .DEPLOY
84+ else "connection_banner"
8485 ),
85- app_name = "connection_banner_reflex_cloud"
86- if simulate_is_reflex_cloud
87- else "connection_banner" ,
8886 ) as harness :
8987 yield harness
9088
@@ -194,13 +192,13 @@ async def test_connection_banner(connection_banner: AppHarness):
194192
195193@pytest .mark .asyncio
196194async def test_cloud_banner (
197- connection_banner : AppHarness , simulate_is_reflex_cloud : bool
195+ connection_banner : AppHarness , simulate_compile_context : constants . CompileContext
198196):
199197 """Test that the connection banner is displayed when the websocket drops.
200198
201199 Args:
202200 connection_banner: AppHarness instance.
203- simulate_is_reflex_cloud: Whether is_reflex_cloud is set for the app.
201+ simulate_compile_context: Which context to set for the app.
204202 """
205203 assert connection_banner .app_instance is not None
206204 assert connection_banner .backend is not None
@@ -213,7 +211,7 @@ async def test_cloud_banner(
213211
214212 driver .add_cookie ({"name" : "backend-enabled" , "value" : "false" })
215213 driver .refresh ()
216- if simulate_is_reflex_cloud :
214+ if simulate_compile_context == constants . CompileContext . DEPLOY :
217215 assert connection_banner ._poll_for (lambda : has_cloud_banner (driver ))
218216 else :
219217 _assert_token (connection_banner , driver )
0 commit comments