Skip to content

Commit 414c016

Browse files
committed
fix: preserve body option validation under python -O
1 parent e2f9ad0 commit 414c016

3 files changed

Lines changed: 5 additions & 78 deletions

File tree

‎playwright/_impl/_fetch.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,9 @@ async def _inner_fetch(
396396
+ (1 if form is not None else 0)
397397
+ (1 if multipart is not None else 0)
398398
) > 1:
399-
raise Error("Only one of 'data', 'form' or 'multipart' can be specified")
399+
raise AssertionError(
400+
"Only one of 'data', 'form' or 'multipart' can be specified"
401+
)
400402
assert (
401403
maxRedirects is None or maxRedirects >= 0
402404
), "'max_redirects' must be greater than or equal to '0'"

‎tests/async/test_fetch_global.py‎

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import base64
1717
import json
1818
import re
19-
import subprocess
2019
import sys
2120
from pathlib import Path
2221
from typing import Any, List
@@ -508,7 +507,7 @@ async def test_should_reject_empty_data_with_form(
508507
) -> None:
509508
request = await playwright.request.new_context()
510509
with pytest.raises(
511-
Error,
510+
AssertionError,
512511
match="Only one of 'data', 'form' or 'multipart' can be specified",
513512
):
514513
await request.post(
@@ -519,44 +518,6 @@ async def test_should_reject_empty_data_with_form(
519518
await request.dispose()
520519

521520

522-
async def test_should_reject_multiple_body_options_under_python_optimization(
523-
server: Server,
524-
) -> None:
525-
script = f"""
526-
import asyncio
527-
from playwright.async_api import async_playwright, Error
528-
529-
async def main():
530-
async with async_playwright() as p:
531-
request = await p.request.new_context()
532-
try:
533-
await request.post(
534-
"{server.EMPTY_PAGE}",
535-
data="",
536-
form={{"name": "value"}},
537-
)
538-
except Error as e:
539-
expected = "Only one of 'data', 'form' or 'multipart' can be specified"
540-
if expected not in str(e):
541-
raise
542-
else:
543-
raise RuntimeError("Conflicting body options were accepted")
544-
finally:
545-
await request.dispose()
546-
547-
asyncio.run(main())
548-
"""
549-
550-
result = subprocess.run(
551-
[sys.executable, "-O", "-c", script],
552-
capture_output=True,
553-
text=True,
554-
timeout=60,
555-
)
556-
557-
assert result.returncode == 0, result.stdout + result.stderr
558-
559-
560521
async def test_should_retry_ECONNRESET(playwright: Playwright, server: Server) -> None:
561522
request_count = 0
562523

‎tests/sync/test_fetch_global.py‎

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414

1515
import json
1616
import re
17-
import subprocess
18-
import sys
1917
from pathlib import Path
2018
from typing import List
2119
from urllib.parse import urlparse
@@ -353,7 +351,7 @@ def test_should_reject_empty_data_with_form(
353351
) -> None:
354352
request = playwright.request.new_context()
355353
with pytest.raises(
356-
Error,
354+
AssertionError,
357355
match="Only one of 'data', 'form' or 'multipart' can be specified",
358356
):
359357
request.post(
@@ -364,40 +362,6 @@ def test_should_reject_empty_data_with_form(
364362
request.dispose()
365363

366364

367-
def test_should_reject_multiple_body_options_under_python_optimization(
368-
server: Server,
369-
) -> None:
370-
script = f"""
371-
from playwright.sync_api import sync_playwright, Error
372-
373-
with sync_playwright() as p:
374-
request = p.request.new_context()
375-
try:
376-
request.post(
377-
"{server.EMPTY_PAGE}",
378-
data="",
379-
form={{"name": "value"}},
380-
)
381-
except Error as e:
382-
expected = "Only one of 'data', 'form' or 'multipart' can be specified"
383-
if expected not in str(e):
384-
raise
385-
else:
386-
raise RuntimeError("Conflicting body options were accepted")
387-
finally:
388-
request.dispose()
389-
"""
390-
391-
result = subprocess.run(
392-
[sys.executable, "-O", "-c", script],
393-
capture_output=True,
394-
text=True,
395-
timeout=60,
396-
)
397-
398-
assert result.returncode == 0, result.stdout + result.stderr
399-
400-
401365
def test_should_throw_when_fail_on_status_code_is_true(
402366
playwright: Playwright, server: Server
403367
) -> None:

0 commit comments

Comments
 (0)