From 459e33cb3359f516bb2458be6f83dc3e3e71cd09 Mon Sep 17 00:00:00 2001 From: amerkurev Date: Mon, 15 Jan 2024 01:01:17 +0300 Subject: [PATCH] fix: remove unsupported default_browser_type option and improve tests --- app/internal/browser.py | 1 + app/routers/query_params.py | 3 ++- app/routers/test_query_params.py | 31 +++++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/app/internal/browser.py b/app/internal/browser.py index b0d8579..1ada805 100644 --- a/app/internal/browser.py +++ b/app/internal/browser.py @@ -31,6 +31,7 @@ async def new_context( # PlaywrightError: options.isMobile is not supported in Firefox del options['is_mobile'] + del options['default_browser_type'] options |= { 'bypass_csp': True, diff --git a/app/routers/query_params.py b/app/routers/query_params.py index ee881f2..136d55c 100644 --- a/app/routers/query_params.py +++ b/app/routers/query_params.py @@ -234,7 +234,8 @@ def __init__( 'and whether it has touch enabled.
Individual parameters like `user-agent`, `viewport-width`, and `viewport-height` ' 'can also be used; in such cases, they will override the `device` settings.
' 'List of [available devices]' - '(https://github.com/microsoft/playwright/blob/main/packages/playwright-core/src/server/deviceDescriptorsSource.json).

' + '(https://github.com/microsoft/playwright/blob/main/packages/playwright-core/src/server/deviceDescriptorsSource.json).' + '

' ), ), ] = 'iPhone 12', diff --git a/app/routers/test_query_params.py b/app/routers/test_query_params.py index 9f348a4..c86c23c 100644 --- a/app/routers/test_query_params.py +++ b/app/routers/test_query_params.py @@ -103,6 +103,37 @@ def test_various_query_params(): 'url': 'https://en.wikipedia.org/wiki/African_humid_period', 'cache': False, 'screenshot': True, + 'device': 'Desktop Firefox', # to raise (Page.screenshot): Cannot take screenshot larger than 32767 } response = client.get(api_url, params=params) assert response.status_code == 200 + + # test viewport and screen settings + url = 'https://en.wikipedia.org/wiki/World_Wide_Web' + params = { + 'url': url, + 'cache': False, + 'viewport-width': 390, + 'viewport-height': 844, + 'screen-width': 1170, + 'screen-height': 2532, + 'user-agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_4 like Mac OS X) ' + } + response = client.get(api_url, params=params) + assert response.status_code == 200 + + # test wrong device name + params = { + 'url': url, + 'device': 'not-exists', + } + response = client.get(api_url, params=params) + assert response.status_code == 422 + assert response.json() == { + 'detail': [{ + 'input': 'not-exists', + 'loc': ['query', 'device'], + 'msg': 'Device not found', + 'type': 'device_parsing', + }] + }