Skip to content

Commit

Permalink
feat: ios and android fullscreen layout params for manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
kutuzov13 committed Aug 30, 2024
1 parent 8f9600d commit bb66cc6
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pybotx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down Expand Up @@ -235,6 +237,8 @@
"SmartApp",
"SmartAppEvent",
"SmartappManifest",
"SmartappManifestIosParams",
"SmartappManifestAndroidParams",
"SmartappManifestWebLayoutChoices",
"SmartappManifestUnreadCounterParams",
"SmartappManifestWebParams",
Expand Down
8 changes: 8 additions & 0 deletions pybotx/bot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@
from pybotx.client.smartapps_api.smartapp_manifest import (
BotXAPISmartAppManifestRequestPayload,
SmartappManifest,
SmartappManifestAndroidParams,
SmartappManifestIosParams,
SmartAppManifestMethod,
SmartappManifestUnreadCounterParams,
SmartappManifestWebParams,
Expand Down Expand Up @@ -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.
Expand All @@ -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,
)
Expand Down
16 changes: 16 additions & 0 deletions pybotx/client/smartapps_api/smartapp_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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":
Expand All @@ -45,6 +59,8 @@ def from_domain(

return cls(
manifest=SmartappManifestPayload(
ios=ios,
android=android,
web=web_layout,
unread_counter_link=unread_counter,
),
Expand Down
38 changes: 38 additions & 0 deletions tests/client/smartapps_api/test_smartapp_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
lifespan_wrapper,
)
from pybotx.client.smartapps_api.smartapp_manifest import (
SmartappManifestAndroidParams,
SmartappManifestIosParams,
SmartappManifestUnreadCounterParams,
)

Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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",
Expand All @@ -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,
Expand Down

0 comments on commit bb66cc6

Please sign in to comment.