From bb66cc6b64dd670fab34f19f9fdd7955afb6a613 Mon Sep 17 00:00:00 2001 From: kutuzov13 Date: Fri, 30 Aug 2024 17:31:24 +0300 Subject: [PATCH] feat: ios and android fullscreen layout params for manifest --- pybotx/__init__.py | 4 ++ pybotx/bot/bot.py | 8 ++++ .../client/smartapps_api/smartapp_manifest.py | 16 ++++++++ .../smartapps_api/test_smartapp_manifest.py | 38 +++++++++++++++++++ 4 files changed, 66 insertions(+) diff --git a/pybotx/__init__.py b/pybotx/__init__.py index e760ac43..f8cd2192 100644 --- a/pybotx/__init__.py +++ b/pybotx/__init__.py @@ -62,6 +62,8 @@ from pybotx.client.smartapps_api.exceptions import SyncSmartAppEventHandlerNotFoundError from pybotx.client.smartapps_api.smartapp_manifest import ( SmartappManifest, + SmartappManifestAndroidParams, + SmartappManifestIosParams, SmartappManifestUnreadCounterParams, SmartappManifestWebParams, ) @@ -235,6 +237,8 @@ "SmartApp", "SmartAppEvent", "SmartappManifest", + "SmartappManifestIosParams", + "SmartappManifestAndroidParams", "SmartappManifestWebLayoutChoices", "SmartappManifestUnreadCounterParams", "SmartappManifestWebParams", diff --git a/pybotx/bot/bot.py b/pybotx/bot/bot.py index 013fb3da..e1e8ce3d 100644 --- a/pybotx/bot/bot.py +++ b/pybotx/bot/bot.py @@ -138,6 +138,8 @@ from pybotx.client.smartapps_api.smartapp_manifest import ( BotXAPISmartAppManifestRequestPayload, SmartappManifest, + SmartappManifestAndroidParams, + SmartappManifestIosParams, SmartAppManifestMethod, SmartappManifestUnreadCounterParams, SmartappManifestWebParams, @@ -1548,12 +1550,16 @@ async def send_smartapp_manifest( self, *, bot_id: UUID, + ios: Missing[SmartappManifestIosParams] = Undefined, + android: Missing[SmartappManifestAndroidParams] = Undefined, web_layout: Missing[SmartappManifestWebParams] = Undefined, unread_counter: Missing[SmartappManifestUnreadCounterParams] = Undefined, ) -> SmartappManifest: """Send smartapp manifest with given parameters. :param bot_id: Bot which should perform the request. + :param ios: Smartapp layout for ios clients. + :param android: Smartapp layout for android clients. :param web_layout: Smartapp layout for web clients. :param unread_counter: Entities that can be subscribed to in the unread counter. @@ -1566,6 +1572,8 @@ async def send_smartapp_manifest( self._bot_accounts_storage, ) payload = BotXAPISmartAppManifestRequestPayload.from_domain( + ios=ios, + android=android, web_layout=web_layout, unread_counter=unread_counter, ) diff --git a/pybotx/client/smartapps_api/smartapp_manifest.py b/pybotx/client/smartapps_api/smartapp_manifest.py index b315b7fb..bd839ed5 100644 --- a/pybotx/client/smartapps_api/smartapp_manifest.py +++ b/pybotx/client/smartapps_api/smartapp_manifest.py @@ -9,6 +9,14 @@ from pybotx.models.enums import SmartappManifestWebLayoutChoices as WebLayoutChoices +class SmartappManifestIosParams(VerifiedPayloadBaseModel): + fullscreen_layout: bool = False + + +class SmartappManifestAndroidParams(VerifiedPayloadBaseModel): + fullscreen_layout: bool = False + + class SmartappManifestWebParams(VerifiedPayloadBaseModel): default_layout: WebLayoutChoices = WebLayoutChoices.minimal expanded_layout: WebLayoutChoices = WebLayoutChoices.half @@ -22,11 +30,15 @@ class SmartappManifestUnreadCounterParams(VerifiedPayloadBaseModel): class SmartappManifest(VerifiedPayloadBaseModel): + ios: SmartappManifestIosParams + android: SmartappManifestAndroidParams web: SmartappManifestWebParams unread_counter_link: SmartappManifestUnreadCounterParams class SmartappManifestPayload(UnverifiedPayloadBaseModel): + ios: Missing[SmartappManifestIosParams] + android: Missing[SmartappManifestAndroidParams] web: Missing[SmartappManifestWebParams] = Undefined unread_counter_link: Missing[SmartappManifestUnreadCounterParams] = Undefined @@ -37,6 +49,8 @@ class BotXAPISmartAppManifestRequestPayload(UnverifiedPayloadBaseModel): @classmethod def from_domain( cls, + ios: Missing[SmartappManifestIosParams] = Undefined, + android: Missing[SmartappManifestAndroidParams] = Undefined, web_layout: Missing[SmartappManifestWebParams] = Undefined, unread_counter: Missing[SmartappManifestUnreadCounterParams] = Undefined, ) -> "BotXAPISmartAppManifestRequestPayload": @@ -45,6 +59,8 @@ def from_domain( return cls( manifest=SmartappManifestPayload( + ios=ios, + android=android, web=web_layout, unread_counter_link=unread_counter, ), diff --git a/tests/client/smartapps_api/test_smartapp_manifest.py b/tests/client/smartapps_api/test_smartapp_manifest.py index d906cfd6..6916882c 100644 --- a/tests/client/smartapps_api/test_smartapp_manifest.py +++ b/tests/client/smartapps_api/test_smartapp_manifest.py @@ -15,6 +15,8 @@ lifespan_wrapper, ) from pybotx.client.smartapps_api.smartapp_manifest import ( + SmartappManifestAndroidParams, + SmartappManifestIosParams, SmartappManifestUnreadCounterParams, ) @@ -37,6 +39,12 @@ async def test__send_smartapp_manifest__all_params_provided__succeed( headers={"Authorization": "Bearer token", "Content-Type": "application/json"}, json={ "manifest": { + "ios": { + "fullscreen_layout": False, + }, + "android": { + "fullscreen_layout": False, + }, "web": { "always_pinned": True, "default_layout": "full", @@ -54,6 +62,12 @@ async def test__send_smartapp_manifest__all_params_provided__succeed( HTTPStatus.ACCEPTED, json={ "result": { + "ios": { + "fullscreen_layout": False, + }, + "android": { + "fullscreen_layout": False, + }, "web": { "always_pinned": True, "default_layout": "full", @@ -76,6 +90,12 @@ async def test__send_smartapp_manifest__all_params_provided__succeed( async with lifespan_wrapper(built_bot) as bot: smartapp_manifest = await bot.send_smartapp_manifest( bot_id=bot_id, + ios=SmartappManifestIosParams( + fullscreen_layout=False, + ), + android=SmartappManifestAndroidParams( + fullscreen_layout=False, + ), web_layout=SmartappManifestWebParams( default_layout=SmartappManifestWebLayoutChoices.full, expanded_layout=SmartappManifestWebLayoutChoices.full, @@ -91,6 +111,12 @@ async def test__send_smartapp_manifest__all_params_provided__succeed( # - Assert - assert endpoint.called assert smartapp_manifest == SmartappManifest( + ios=SmartappManifestIosParams( + fullscreen_layout=False, + ), + android=SmartappManifestAndroidParams( + fullscreen_layout=False, + ), web=SmartappManifestWebParams( default_layout=SmartappManifestWebLayoutChoices.full, expanded_layout=SmartappManifestWebLayoutChoices.full, @@ -122,6 +148,12 @@ async def test__send_smartapp_manifest__only_default_params_provided__succeed( HTTPStatus.ACCEPTED, json={ "result": { + "ios": { + "fullscreen_layout": False, + }, + "android": { + "fullscreen_layout": False, + }, "web": { "always_pinned": False, "default_layout": "minimal", @@ -147,6 +179,12 @@ async def test__send_smartapp_manifest__only_default_params_provided__succeed( # - Assert - assert endpoint.called assert smartapp_manifest == SmartappManifest( + ios=SmartappManifestIosParams( + fullscreen_layout=False, + ), + android=SmartappManifestAndroidParams( + fullscreen_layout=False, + ), web=SmartappManifestWebParams( default_layout=SmartappManifestWebLayoutChoices.minimal, expanded_layout=SmartappManifestWebLayoutChoices.half,