2121
2222
2323@pytest .fixture
24- def x_me (browser_session_declarations ):
25- class XMe :
26- name = "x_me "
27- x = BrowserSession (site = "x.com " , persist = True )
24+ def night_watch (browser_session_declarations ):
25+ class NightWatch :
26+ name = "night_watch "
27+ acme = BrowserSession (site = "acme.example " , persist = True )
2828 docs = BrowserSession (site = "docs.example" )
2929
30- return XMe
30+ return NightWatch
3131
3232
3333class FakeListener :
@@ -115,16 +115,16 @@ def stored_session(
115115 return row
116116
117117
118- def test_declaration_carries_the_extension_namespace (x_me ):
119- assert x_me . x .name == "x_me.x "
120- assert x_me .docs .name == "x_me .docs"
118+ def test_declaration_carries_the_extension_namespace (night_watch ):
119+ assert night_watch . acme .name == "night_watch.acme "
120+ assert night_watch .docs .name == "night_watch .docs"
121121
122122
123- async def test_borrow_yields_a_tunneled_cdp_url (borrow , x_me ):
123+ async def test_borrow_yields_a_tunneled_cdp_url (borrow , night_watch ):
124124 browser , redis = borrow
125- stored_session (x_me .docs )
125+ stored_session (night_watch .docs )
126126
127- async with x_me .docs .cdp () as cdp_url :
127+ async with night_watch .docs .cdp () as cdp_url :
128128 assert cdp_url == "http://127.0.0.1:43987"
129129
130130 assert browser .forwarded_port == 9222
@@ -138,14 +138,14 @@ async def test_borrow_yields_a_tunneled_cdp_url(borrow, x_me):
138138 launch_script = browser .commands [0 ][2 ]
139139 assert "session-launch --headed" in launch_script
140140 assert not redis .values
141- assert StoredBrowserSession .get_for_name (x_me .docs .name ).last_used_at
141+ assert StoredBrowserSession .get_for_name (night_watch .docs .name ).last_used_at
142142
143143
144144async def test_headless_declaration_launches_headless (borrow ):
145145 browser , _ = borrow
146146 quiet = BrowserSession (site = "docs.example" )
147147 quiet .headless = True
148- quiet .name = "x_me .quiet"
148+ quiet .name = "night_watch .quiet"
149149 stored_session (quiet )
150150
151151 async with quiet .cdp ():
@@ -154,92 +154,96 @@ async def test_headless_declaration_launches_headless(borrow):
154154 assert "session-launch --headless" in browser .commands [0 ][2 ]
155155
156156
157- async def test_persisting_borrow_locks_exports_and_stores (borrow , x_me ):
157+ async def test_persisting_borrow_locks_exports_and_stores (borrow , night_watch ):
158158 browser , redis = borrow
159- row = stored_session (x_me . x )
159+ row = stored_session (night_watch . acme )
160160
161- async with x_me . x .cdp ():
161+ async with night_watch . acme .cdp ():
162162 assert redis .values
163163
164164 assert not redis .values
165165 assert browser .commands [- 1 ] == ["session-export" ]
166166 db_session ().expire_all ()
167- stored = StoredBrowserSession .get_for_name (x_me . x .name )
167+ stored = StoredBrowserSession .get_for_name (night_watch . acme .name )
168168 assert stored .payload .decrypt () == b"exported-profile"
169169 assert stored .payload_format == BrowserSessionPayloadFormat .PROFILE_DIR .value
170170 assert stored .id == row .id
171171
172172
173- async def test_persisting_borrow_refuses_a_second_writer (borrow , x_me ):
173+ async def test_persisting_borrow_refuses_a_second_writer (borrow , night_watch ):
174174 browser , redis = borrow
175- stored_session (x_me .x )
176- redis .values [f"browser_session:{ StoredBrowserSession .get_for_name (x_me .x .name ).id } " ] = "other"
175+ stored_session (night_watch .acme )
176+ redis .values [
177+ f"browser_session:{ StoredBrowserSession .get_for_name (night_watch .acme .name ).id } "
178+ ] = "other"
177179
178180 with pytest .raises (BrowserSessionWriterLockedError ):
179- async with x_me . x .cdp ():
181+ async with night_watch . acme .cdp ():
180182 pass
181183
182184 assert browser .commands == []
183185
184186
185187async def test_first_borrow_writes_the_declared_session_and_asks_for_a_login (
186- borrow , x_me , druks_db
188+ borrow , night_watch , druks_db
187189):
188190 """The first borrow materializes the row and refuses to open a browser:
189191 the session is declared, but nobody has signed into it yet."""
190- assert not StoredBrowserSession .get_for_name (x_me .docs .name )
192+ assert not StoredBrowserSession .get_for_name (night_watch .docs .name )
191193
192194 with pytest .raises (BrowserSessionNotReadyError ):
193- async with x_me .docs .cdp ():
195+ async with night_watch .docs .cdp ():
194196 pass
195197
196- row = StoredBrowserSession .get_for_name (x_me .docs .name )
198+ row = StoredBrowserSession .get_for_name (night_watch .docs .name )
197199 assert row .status == BrowserSessionStatus .NEEDS_LOGIN .value
198- assert row .site == x_me .docs .site
200+ assert row .site == night_watch .docs .site
199201
200202 with pytest .raises (BrowserSessionNotReadyError ):
201- async with x_me .docs .cdp ():
203+ async with night_watch .docs .cdp ():
202204 pass
203205
204206 assert StoredBrowserSession .list_all () == [row ]
205207
206208
207- async def test_launch_failure_raises_and_releases_the_lock (borrow , x_me ):
209+ async def test_launch_failure_raises_and_releases_the_lock (borrow , night_watch ):
208210 browser , redis = borrow
209- stored_session (x_me . x )
211+ stored_session (night_watch . acme )
210212 browser .launch_exit = 1
211213
212214 with pytest .raises (BrowserLaunchError , match = "launch stderr" ):
213- async with x_me . x .cdp ():
215+ async with night_watch . acme .cdp ():
214216 pass
215217
216218 assert not redis .values
217219
218220
219- async def test_signed_out_borrow_stamps_the_session_and_stores_nothing (borrow , x_me ):
221+ async def test_signed_out_borrow_stamps_the_session_and_stores_nothing (borrow , night_watch ):
220222 """The extension raises through the borrow when the site bounced the login:
221223 the door stamps which session bounced, and the dead state is never stored."""
222224 browser , redis = borrow
223- stored_session (x_me . x , payload = b"live-state" )
225+ stored_session (night_watch . acme , payload = b"live-state" )
224226
225227 with pytest .raises (BrowserSessionSignedOutError ) as caught :
226- async with x_me . x .cdp ():
228+ async with night_watch . acme .cdp ():
227229 raise BrowserSessionSignedOutError ("the site bounced the login" )
228230
229- assert caught .value .session_name == "x_me.x "
231+ assert caught .value .session_name == "night_watch.acme "
230232 db_session ().expire_all ()
231- assert StoredBrowserSession .get_for_name (x_me .x .name ).payload .decrypt () == b"live-state"
233+ assert (
234+ StoredBrowserSession .get_for_name (night_watch .acme .name ).payload .decrypt () == b"live-state"
235+ )
232236 assert ["session-export" ] not in browser .commands
233237 assert not redis .values # the writer lock released on the way out
234238
235239
236- async def test_playwright_yields_the_logged_in_context (borrow , x_me , monkeypatch ):
240+ async def test_playwright_yields_the_logged_in_context (borrow , night_watch , monkeypatch ):
237241 import sys
238242 import types
239243 from contextlib import asynccontextmanager as acm
240244
241245 browser , _ = borrow
242- stored_session (x_me .docs )
246+ stored_session (night_watch .docs )
243247 seen = {}
244248 logged_in_context = object ()
245249
@@ -263,19 +267,19 @@ async def fake_playwright():
263267 monkeypatch .setitem (sys .modules , "playwright" , types .ModuleType ("playwright" ))
264268 monkeypatch .setitem (sys .modules , "playwright.async_api" , playwright_module )
265269
266- async with x_me .docs .playwright () as context :
270+ async with night_watch .docs .playwright () as context :
267271 assert context is logged_in_context
268272
269273 assert seen == {"url" : "http://127.0.0.1:43987" , "closed" : True }
270274
271275
272- async def test_playwright_without_the_dependency_names_the_fix (borrow , x_me , monkeypatch ):
276+ async def test_playwright_without_the_dependency_names_the_fix (borrow , night_watch , monkeypatch ):
273277 import sys
274278
275- stored_session (x_me .docs )
279+ stored_session (night_watch .docs )
276280 monkeypatch .setitem (sys .modules , "playwright" , None )
277281 monkeypatch .setitem (sys .modules , "playwright.async_api" , None )
278282
279283 with pytest .raises (BrowserClientMissingError , match = "add playwright" ):
280- async with x_me .docs .playwright ():
284+ async with night_watch .docs .playwright ():
281285 pass
0 commit comments