diff --git a/.pubnub.yml b/.pubnub.yml index 3c065c7e..fea0b11c 100644 --- a/.pubnub.yml +++ b/.pubnub.yml @@ -1,5 +1,5 @@ name: python -version: 10.0.1 +version: 10.1.0 schema: 1 scm: github.com/pubnub/python sdks: @@ -18,7 +18,7 @@ sdks: distributions: - distribution-type: library distribution-repository: package - package-name: pubnub-10.0.1 + package-name: pubnub-10.1.0 location: https://pypi.org/project/pubnub/ supported-platforms: supported-operating-systems: @@ -91,8 +91,8 @@ sdks: - distribution-type: library distribution-repository: git release - package-name: pubnub-10.0.1 - location: https://github.com/pubnub/python/releases/download/10.0.1/pubnub-10.0.1.tar.gz + package-name: pubnub-10.1.0 + location: https://github.com/pubnub/python/releases/download/10.1.0/pubnub-10.1.0.tar.gz supported-platforms: supported-operating-systems: Linux: @@ -163,6 +163,11 @@ sdks: license-url: https://github.com/encode/httpx/blob/master/LICENSE.md is-required: Required changelog: + - date: 2025-01-30 + version: 10.1.0 + changes: + - type: feature + text: "Extended functionality of Channel Members and User Membership. Now it's possible to use fine-grade includes and set member/membership status and type." - date: 2025-01-28 version: 10.0.1 changes: diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ec8167c..46dc73dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## 10.1.0 +January 30 2025 + +#### Added +- Extended functionality of Channel Members and User Membership. Now it's possible to use fine-grade includes and set member/membership status and type. + ## 10.0.1 January 28 2025 diff --git a/pubnub/endpoints/endpoint.py b/pubnub/endpoints/endpoint.py index ace9375d..856e1dfb 100644 --- a/pubnub/endpoints/endpoint.py +++ b/pubnub/endpoints/endpoint.py @@ -97,7 +97,7 @@ def request_headers(self): headers = {} if self.__compress_request(): headers["Content-Encoding"] = "gzip" - if self.http_method() == HttpMethod.POST: + if self.http_method() in [HttpMethod.POST, HttpMethod.PATCH]: headers["Content-type"] = "application/json" return headers diff --git a/pubnub/endpoints/objects_v2/members/get_channel_members.py b/pubnub/endpoints/objects_v2/members/get_channel_members.py index 26217d57..ca8afc70 100644 --- a/pubnub/endpoints/objects_v2/members/get_channel_members.py +++ b/pubnub/endpoints/objects_v2/members/get_channel_members.py @@ -1,9 +1,10 @@ -from pubnub.endpoints.objects_v2.objects_endpoint import ObjectsEndpoint, IncludeCustomEndpoint, \ - ChannelEndpoint, ListEndpoint, UUIDIncludeEndpoint +from pubnub.endpoints.objects_v2.objects_endpoint import IncludeCapableEndpoint, ObjectsEndpoint, \ + IncludeCustomEndpoint, ChannelEndpoint, ListEndpoint, UUIDIncludeEndpoint from pubnub.enums import PNOperationType from pubnub.enums import HttpMethod from pubnub.models.consumer.common import PNStatus from pubnub.models.consumer.objects_v2.channel_members import PNGetChannelMembersResult +from pubnub.models.consumer.objects_v2.common import MemberIncludes from pubnub.models.consumer.objects_v2.page import PNPage from pubnub.structures import Envelope @@ -14,12 +15,14 @@ class PNGetChannelMembersResultEnvelope(Envelope): class GetChannelMembers(ObjectsEndpoint, ChannelEndpoint, ListEndpoint, IncludeCustomEndpoint, - UUIDIncludeEndpoint): + UUIDIncludeEndpoint, IncludeCapableEndpoint): GET_CHANNEL_MEMBERS_PATH = "/v2/objects/%s/channels/%s/uuids" - def __init__(self, pubnub, channel: str = None, include_custom: bool = None, limit: int = None, filter: str = None, - include_total_count: bool = None, sort_keys: list = None, page: PNPage = None): + def __init__(self, pubnub, channel: str = None, include_custom: bool = None, + limit: int = None, filter: str = None, include_total_count: bool = None, sort_keys: list = None, + page: PNPage = None, include: MemberIncludes = None): ObjectsEndpoint.__init__(self, pubnub) + IncludeCapableEndpoint.__init__(self, include) ChannelEndpoint.__init__(self, channel=channel) ListEndpoint.__init__(self, limit=limit, filter=filter, include_total_count=include_total_count, sort_keys=sort_keys, page=page) @@ -32,6 +35,10 @@ def build_path(self): def validate_specific_params(self): self._validate_channel() + def include(self, includes: MemberIncludes) -> 'GetChannelMembers': + super().include(includes) + return self + def create_response(self, envelope) -> PNGetChannelMembersResult: return PNGetChannelMembersResult(envelope) diff --git a/pubnub/endpoints/objects_v2/members/manage_channel_members.py b/pubnub/endpoints/objects_v2/members/manage_channel_members.py index 81c0ffe3..24716626 100644 --- a/pubnub/endpoints/objects_v2/members/manage_channel_members.py +++ b/pubnub/endpoints/objects_v2/members/manage_channel_members.py @@ -1,11 +1,12 @@ from typing import List from pubnub import utils -from pubnub.endpoints.objects_v2.objects_endpoint import ObjectsEndpoint, ListEndpoint, \ +from pubnub.endpoints.objects_v2.objects_endpoint import IncludeCapableEndpoint, ObjectsEndpoint, ListEndpoint, \ IncludeCustomEndpoint, ChannelEndpoint, UUIDIncludeEndpoint from pubnub.enums import PNOperationType from pubnub.enums import HttpMethod from pubnub.models.consumer.common import PNStatus -from pubnub.models.consumer.objects_v2.channel_members import PNManageChannelMembersResult +from pubnub.models.consumer.objects_v2.channel_members import PNUUID, PNManageChannelMembersResult +from pubnub.models.consumer.objects_v2.common import MembershipIncludes from pubnub.models.consumer.objects_v2.page import PNPage from pubnub.structures import Envelope @@ -16,13 +17,15 @@ class PNManageChannelMembersResultEnvelope(Envelope): class ManageChannelMembers(ObjectsEndpoint, ChannelEndpoint, ListEndpoint, IncludeCustomEndpoint, - UUIDIncludeEndpoint): + IncludeCapableEndpoint, UUIDIncludeEndpoint): MANAGE_CHANNELS_MEMBERS_PATH = "/v2/objects/%s/channels/%s/uuids" - def __init__(self, pubnub, channel: str = None, uuids_to_set: List[str] = None, uuids_to_remove: List[str] = None, - include_custom: bool = None, limit: int = None, filter: str = None, include_total_count: bool = None, - sort_keys: list = None, page: PNPage = None): + def __init__(self, pubnub, channel: str = None, uuids_to_set: List[PNUUID] = None, + uuids_to_remove: List[PNUUID] = None, include_custom: bool = None, limit: int = None, + filter: str = None, include_total_count: bool = None, sort_keys: list = None, page: PNPage = None, + include: MembershipIncludes = None): ObjectsEndpoint.__init__(self, pubnub) + IncludeCapableEndpoint.__init__(self, include) ChannelEndpoint.__init__(self, channel=channel) ListEndpoint.__init__(self, limit=limit, filter=filter, include_total_count=include_total_count, sort_keys=sort_keys, page=page) @@ -36,17 +39,21 @@ def __init__(self, pubnub, channel: str = None, uuids_to_set: List[str] = None, if uuids_to_remove: utils.extend_list(self._uuids_to_remove, uuids_to_remove) - def set(self, uuids_to_set: List[str]) -> 'ManageChannelMembers': + def set(self, uuids_to_set: List[PNUUID]) -> 'ManageChannelMembers': self._uuids_to_set = list(uuids_to_set) return self - def remove(self, uuids_to_remove: List[str]) -> 'ManageChannelMembers': + def remove(self, uuids_to_remove: List[PNUUID]) -> 'ManageChannelMembers': self._uuids_to_remove = list(uuids_to_remove) return self def validate_specific_params(self): self._validate_channel() + def include(self, includes: MembershipIncludes) -> 'ManageChannelMembers': + super().include(includes) + return self + def build_path(self): return ManageChannelMembers.MANAGE_CHANNELS_MEMBERS_PATH % (self.pubnub.config.subscribe_key, self._channel) diff --git a/pubnub/endpoints/objects_v2/members/remove_channel_members.py b/pubnub/endpoints/objects_v2/members/remove_channel_members.py index 67cd4627..7375d098 100644 --- a/pubnub/endpoints/objects_v2/members/remove_channel_members.py +++ b/pubnub/endpoints/objects_v2/members/remove_channel_members.py @@ -1,11 +1,12 @@ from typing import List from pubnub import utils -from pubnub.endpoints.objects_v2.objects_endpoint import ObjectsEndpoint, ChannelEndpoint, ListEndpoint, \ - IncludeCustomEndpoint, UUIDIncludeEndpoint +from pubnub.endpoints.objects_v2.objects_endpoint import IncludeCapableEndpoint, ObjectsEndpoint, ChannelEndpoint, \ + ListEndpoint, IncludeCustomEndpoint, UUIDIncludeEndpoint from pubnub.enums import PNOperationType from pubnub.enums import HttpMethod from pubnub.models.consumer.common import PNStatus -from pubnub.models.consumer.objects_v2.channel_members import PNRemoveChannelMembersResult +from pubnub.models.consumer.objects_v2.channel_members import PNUUID, PNRemoveChannelMembersResult +from pubnub.models.consumer.objects_v2.common import MemberIncludes from pubnub.models.consumer.objects_v2.page import PNPage from pubnub.structures import Envelope @@ -16,13 +17,14 @@ class PNRemoveChannelMembersResultEnvelope(Envelope): class RemoveChannelMembers(ObjectsEndpoint, ChannelEndpoint, ListEndpoint, IncludeCustomEndpoint, - UUIDIncludeEndpoint): + UUIDIncludeEndpoint, IncludeCapableEndpoint): REMOVE_CHANNEL_MEMBERS_PATH = "/v2/objects/%s/channels/%s/uuids" - def __init__(self, pubnub, channel: str = None, uuids: List[str] = None, include_custom: bool = None, + def __init__(self, pubnub, channel: str = None, uuids: List[PNUUID] = None, include_custom: bool = None, limit: int = None, filter: str = None, include_total_count: bool = None, sort_keys: list = None, - page: PNPage = None): + page: PNPage = None, include: MemberIncludes = None): ObjectsEndpoint.__init__(self, pubnub) + IncludeCapableEndpoint.__init__(self, include) ListEndpoint.__init__(self, limit=limit, filter=filter, include_total_count=include_total_count, sort_keys=sort_keys, page=page) ChannelEndpoint.__init__(self, channel=channel) diff --git a/pubnub/endpoints/objects_v2/members/set_channel_members.py b/pubnub/endpoints/objects_v2/members/set_channel_members.py index 242e210d..9c5a7a8f 100644 --- a/pubnub/endpoints/objects_v2/members/set_channel_members.py +++ b/pubnub/endpoints/objects_v2/members/set_channel_members.py @@ -1,11 +1,12 @@ from typing import List from pubnub import utils -from pubnub.endpoints.objects_v2.objects_endpoint import ObjectsEndpoint, IncludeCustomEndpoint, \ - UUIDIncludeEndpoint, ChannelEndpoint, ListEndpoint +from pubnub.endpoints.objects_v2.objects_endpoint import IncludeCapableEndpoint, ObjectsEndpoint, \ + IncludeCustomEndpoint, UUIDIncludeEndpoint, ChannelEndpoint, ListEndpoint from pubnub.enums import PNOperationType from pubnub.enums import HttpMethod from pubnub.models.consumer.common import PNStatus -from pubnub.models.consumer.objects_v2.channel_members import PNSetChannelMembersResult +from pubnub.models.consumer.objects_v2.channel_members import PNUUID, PNSetChannelMembersResult +from pubnub.models.consumer.objects_v2.common import MemberIncludes from pubnub.models.consumer.objects_v2.page import PNPage from pubnub.structures import Envelope @@ -15,14 +16,15 @@ class PNSetChannelMembersResultEnvelope(Envelope): status: PNStatus -class SetChannelMembers(ObjectsEndpoint, ChannelEndpoint, ListEndpoint, IncludeCustomEndpoint, +class SetChannelMembers(ObjectsEndpoint, ChannelEndpoint, ListEndpoint, IncludeCustomEndpoint, IncludeCapableEndpoint, UUIDIncludeEndpoint): SET_CHANNEL_MEMBERS_PATH = "/v2/objects/%s/channels/%s/uuids" - def __init__(self, pubnub, channel: str = None, uuids: List[str] = None, include_custom: bool = None, + def __init__(self, pubnub, channel: str = None, uuids: List[PNUUID] = None, include_custom: bool = None, limit: int = None, filter: str = None, include_total_count: bool = None, sort_keys: list = None, - page: PNPage = None): + page: PNPage = None, include: MemberIncludes = None): ObjectsEndpoint.__init__(self, pubnub) + IncludeCapableEndpoint.__init__(self, include) ListEndpoint.__init__(self, limit=limit, filter=filter, include_total_count=include_total_count, sort_keys=sort_keys, page=page) ChannelEndpoint.__init__(self, channel=channel) @@ -30,7 +32,7 @@ def __init__(self, pubnub, channel: str = None, uuids: List[str] = None, include UUIDIncludeEndpoint.__init__(self) self._uuids = [] - if self._uuids: + if uuids: utils.extend_list(self._uuids, uuids) def uuids(self, uuids) -> 'SetChannelMembers': @@ -40,6 +42,26 @@ def uuids(self, uuids) -> 'SetChannelMembers': def validate_specific_params(self): self._validate_channel() + def include(self, includes: MemberIncludes) -> 'SetChannelMembers': + """ + Include additional information in the members response. + + Parameters + ---------- + includes : MemberIncludes + The additional information to include in the member response. + + See Also + -------- + pubnub.models.consumer.objects_v2.common.MemberIncludese : For details on the available includes. + + Returns + ------- + self : SetChannelMembers + """ + super().include(includes) + return self + def build_path(self): return SetChannelMembers.SET_CHANNEL_MEMBERS_PATH % (self.pubnub.config.subscribe_key, self._channel) diff --git a/pubnub/endpoints/objects_v2/memberships/get_memberships.py b/pubnub/endpoints/objects_v2/memberships/get_memberships.py index 12a331c6..96faeb5c 100644 --- a/pubnub/endpoints/objects_v2/memberships/get_memberships.py +++ b/pubnub/endpoints/objects_v2/memberships/get_memberships.py @@ -1,8 +1,9 @@ -from pubnub.endpoints.objects_v2.objects_endpoint import ObjectsEndpoint, IncludeCustomEndpoint, \ - UuidEndpoint, ListEndpoint, ChannelIncludeEndpoint +from pubnub.endpoints.objects_v2.objects_endpoint import IncludeCapableEndpoint, ObjectsEndpoint, \ + IncludeCustomEndpoint, UuidEndpoint, ListEndpoint, ChannelIncludeEndpoint from pubnub.enums import PNOperationType from pubnub.enums import HttpMethod from pubnub.models.consumer.common import PNStatus +from pubnub.models.consumer.objects_v2.common import MembershipIncludes from pubnub.models.consumer.objects_v2.memberships import PNGetMembershipsResult from pubnub.models.consumer.objects_v2.page import PNPage from pubnub.structures import Envelope @@ -13,13 +14,15 @@ class PNGetMembershipsResultEnvelope(Envelope): status: PNStatus -class GetMemberships(ObjectsEndpoint, UuidEndpoint, ListEndpoint, IncludeCustomEndpoint, +class GetMemberships(ObjectsEndpoint, UuidEndpoint, ListEndpoint, IncludeCustomEndpoint, IncludeCapableEndpoint, ChannelIncludeEndpoint): GET_MEMBERSHIPS_PATH = "/v2/objects/%s/uuids/%s/channels" def __init__(self, pubnub, uuid: str = None, include_custom: bool = False, limit: int = None, filter: str = None, - include_total_count: bool = None, sort_keys: list = None, page: PNPage = None): + include_total_count: bool = None, sort_keys: list = None, page: PNPage = None, + include: MembershipIncludes = None): ObjectsEndpoint.__init__(self, pubnub) + IncludeCapableEndpoint.__init__(self, include=include) UuidEndpoint.__init__(self, uuid=uuid) ListEndpoint.__init__(self, limit=limit, filter=filter, include_total_count=include_total_count, sort_keys=sort_keys, page=page) @@ -32,6 +35,26 @@ def build_path(self): def validate_specific_params(self): self._validate_uuid() + def include(self, includes: MembershipIncludes) -> 'GetMemberships': + """ + Include additional information in the membership response. + + Parameters + ---------- + includes : MembershipIncludes + The additional information to include in the membership response. + + See Also + -------- + pubnub.models.consumer.objects_v2.common.MembershipIncludese : For details on the available includes. + + Returns + ------- + self : GetMemberships + """ + super().include(includes) + return self + def create_response(self, envelope) -> PNGetMembershipsResult: return PNGetMembershipsResult(envelope) diff --git a/pubnub/endpoints/objects_v2/memberships/manage_memberships.py b/pubnub/endpoints/objects_v2/memberships/manage_memberships.py index 0664cc2a..15947e0e 100644 --- a/pubnub/endpoints/objects_v2/memberships/manage_memberships.py +++ b/pubnub/endpoints/objects_v2/memberships/manage_memberships.py @@ -1,12 +1,13 @@ from typing import List from pubnub import utils -from pubnub.endpoints.objects_v2.objects_endpoint import ObjectsEndpoint, ListEndpoint, \ +from pubnub.endpoints.objects_v2.objects_endpoint import IncludeCapableEndpoint, ObjectsEndpoint, ListEndpoint, \ IncludeCustomEndpoint, UuidEndpoint, ChannelIncludeEndpoint from pubnub.enums import PNOperationType from pubnub.enums import HttpMethod from pubnub.models.consumer.common import PNStatus -from pubnub.models.consumer.objects_v2.memberships import PNManageMembershipsResult +from pubnub.models.consumer.objects_v2.common import MembershipIncludes +from pubnub.models.consumer.objects_v2.memberships import PNChannelMembership, PNManageMembershipsResult from pubnub.models.consumer.objects_v2.page import PNPage from pubnub.structures import Envelope @@ -16,14 +17,17 @@ class PNManageMembershipsResultEnvelope(Envelope): status: PNStatus -class ManageMemberships(ObjectsEndpoint, UuidEndpoint, ListEndpoint, IncludeCustomEndpoint, +class ManageMemberships(ObjectsEndpoint, UuidEndpoint, ListEndpoint, IncludeCustomEndpoint, IncludeCapableEndpoint, ChannelIncludeEndpoint): MANAGE_MEMBERSHIPS_PATH = "/v2/objects/%s/uuids/%s/channels" - def __init__(self, pubnub, uuid: str = None, channel_memberships_to_set: List[str] = None, - channel_memberships_to_remove: List[str] = None, include_custom: bool = False, limit: int = None, - filter: str = None, include_total_count: bool = None, sort_keys: list = None, page: PNPage = None): + def __init__(self, pubnub, uuid: str = None, channel_memberships_to_set: List[PNChannelMembership] = None, + channel_memberships_to_remove: List[PNChannelMembership] = None, include_custom: bool = False, + limit: int = None, filter: str = None, include_total_count: bool = None, sort_keys: list = None, + page: PNPage = None, include: MembershipIncludes = None): + ObjectsEndpoint.__init__(self, pubnub) + IncludeCapableEndpoint.__init__(self, include=include) UuidEndpoint.__init__(self, uuid=uuid) ListEndpoint.__init__(self, limit=limit, filter=filter, include_total_count=include_total_count, sort_keys=sort_keys, page=page) @@ -38,14 +42,34 @@ def __init__(self, pubnub, uuid: str = None, channel_memberships_to_set: List[st if channel_memberships_to_remove: utils.extend_list(self._channel_memberships_to_remove, channel_memberships_to_remove) - def set(self, channel_memberships_to_set: List[str]) -> 'ManageMemberships': + def set(self, channel_memberships_to_set: List[PNChannelMembership]) -> 'ManageMemberships': self._channel_memberships_to_set = list(channel_memberships_to_set) return self - def remove(self, channel_memberships_to_remove: List[str]) -> 'ManageMemberships': + def remove(self, channel_memberships_to_remove: List[PNChannelMembership]) -> 'ManageMemberships': self._channel_memberships_to_remove = list(channel_memberships_to_remove) return self + def include(self, includes: MembershipIncludes) -> 'ManageMemberships': + """ + Include additional information in the membership response. + + Parameters + ---------- + includes : MembershipIncludes + The additional information to include in the membership response. + + See Also + -------- + pubnub.models.consumer.objects_v2.common.MembershipIncludese : For details on the available includes. + + Returns + ------- + self : GetMemberships + """ + super().include(includes) + return self + def validate_specific_params(self): self._validate_uuid() diff --git a/pubnub/endpoints/objects_v2/memberships/remove_memberships.py b/pubnub/endpoints/objects_v2/memberships/remove_memberships.py index 511b6485..fe806166 100644 --- a/pubnub/endpoints/objects_v2/memberships/remove_memberships.py +++ b/pubnub/endpoints/objects_v2/memberships/remove_memberships.py @@ -1,26 +1,65 @@ +from typing import List from pubnub import utils -from pubnub.endpoints.objects_v2.objects_endpoint import ObjectsEndpoint, ListEndpoint, \ - IncludeCustomEndpoint, UuidEndpoint, ChannelIncludeEndpoint +from pubnub.endpoints.objects_v2.objects_endpoint import IncludeCapableEndpoint, ObjectsEndpoint, \ + IncludeCustomEndpoint, ListEndpoint, ChannelIncludeEndpoint, UuidEndpoint from pubnub.enums import PNOperationType from pubnub.enums import HttpMethod -from pubnub.models.consumer.objects_v2.memberships import PNRemoveMembershipsResult +from pubnub.models.consumer.common import PNStatus +from pubnub.models.consumer.objects_v2.common import MembershipIncludes +from pubnub.models.consumer.objects_v2.memberships import PNChannelMembership, PNRemoveMembershipsResult +from pubnub.models.consumer.objects_v2.page import PNPage +from pubnub.structures import Envelope -class RemoveMemberships(ObjectsEndpoint, UuidEndpoint, ListEndpoint, IncludeCustomEndpoint, - ChannelIncludeEndpoint): +class PNRemoveMembershipsResultEnvelope(Envelope): + result: PNRemoveMembershipsResult + status: PNStatus + + +class RemoveMemberships(ObjectsEndpoint, ListEndpoint, IncludeCustomEndpoint, IncludeCapableEndpoint, + ChannelIncludeEndpoint, UuidEndpoint): REMOVE_MEMBERSHIPS_PATH = "/v2/objects/%s/uuids/%s/channels" - def __init__(self, pubnub): + def __init__(self, pubnub, uuid: str = None, channel_memberships: List[PNChannelMembership] = None, + include_custom: bool = False, limit: int = None, filter: str = None, include_total_count: bool = None, + sort_keys: list = None, page: PNPage = None, include: MembershipIncludes = None): ObjectsEndpoint.__init__(self, pubnub) - ListEndpoint.__init__(self) - UuidEndpoint.__init__(self) - IncludeCustomEndpoint.__init__(self) + IncludeCapableEndpoint.__init__(self, include=include) + UuidEndpoint.__init__(self, uuid=uuid) + ListEndpoint.__init__(self, limit=limit, filter=filter, include_total_count=include_total_count, + sort_keys=sort_keys, page=page) + IncludeCustomEndpoint.__init__(self, include_custom=include_custom) ChannelIncludeEndpoint.__init__(self) self._channel_memberships = [] + if channel_memberships: + utils.extend_list(self._channel_memberships, channel_memberships) def channel_memberships(self, channel_memberships): - self._channel_memberships = list(channel_memberships) + utils.extend_list(self._channel_memberships, channel_memberships) + return self + + def validate_specific_params(self): + self._validate_uuid() + + def include(self, includes: MembershipIncludes) -> 'RemoveMemberships': + """ + Include additional information in the membership response. + + Parameters + ---------- + includes : MembershipIncludes + The additional information to include in the membership response. + + See Also + -------- + pubnub.models.consumer.objects_v2.common.MembershipIncludese : For details on the available includes. + + Returns + ------- + self : RemoveMemberships + """ + super().include(includes) return self def build_path(self): @@ -38,12 +77,12 @@ def build_data(self): } return utils.write_value_as_string(payload) - def validate_specific_params(self): - self._validate_uuid() - - def create_response(self, envelope): + def create_response(self, envelope) -> PNRemoveMembershipsResult: return PNRemoveMembershipsResult(envelope) + def sync(self) -> PNRemoveMembershipsResultEnvelope: + return PNRemoveMembershipsResultEnvelope(super().sync()) + def operation_type(self): return PNOperationType.PNRemoveMembershipsOperation diff --git a/pubnub/endpoints/objects_v2/memberships/set_memberships.py b/pubnub/endpoints/objects_v2/memberships/set_memberships.py index 1d777cfd..056313b6 100644 --- a/pubnub/endpoints/objects_v2/memberships/set_memberships.py +++ b/pubnub/endpoints/objects_v2/memberships/set_memberships.py @@ -1,11 +1,12 @@ from typing import List from pubnub import utils -from pubnub.endpoints.objects_v2.objects_endpoint import ObjectsEndpoint, IncludeCustomEndpoint, \ - ListEndpoint, ChannelIncludeEndpoint, UuidEndpoint +from pubnub.endpoints.objects_v2.objects_endpoint import IncludeCapableEndpoint, ObjectsEndpoint, \ + IncludeCustomEndpoint, ListEndpoint, ChannelIncludeEndpoint, UuidEndpoint from pubnub.enums import PNOperationType from pubnub.enums import HttpMethod from pubnub.models.consumer.common import PNStatus -from pubnub.models.consumer.objects_v2.memberships import PNSetMembershipsResult +from pubnub.models.consumer.objects_v2.common import MembershipIncludes +from pubnub.models.consumer.objects_v2.memberships import PNChannelMembership, PNSetMembershipsResult from pubnub.models.consumer.objects_v2.page import PNPage from pubnub.structures import Envelope @@ -15,14 +16,15 @@ class PNSetMembershipsResultEnvelope(Envelope): status: PNStatus -class SetMemberships(ObjectsEndpoint, ListEndpoint, IncludeCustomEndpoint, +class SetMemberships(ObjectsEndpoint, ListEndpoint, IncludeCustomEndpoint, IncludeCapableEndpoint, ChannelIncludeEndpoint, UuidEndpoint): SET_MEMBERSHIP_PATH = "/v2/objects/%s/uuids/%s/channels" - def __init__(self, pubnub, uuid: str = None, channel_memberships: List[str] = None, include_custom: bool = False, - limit: int = None, filter: str = None, include_total_count: bool = None, sort_keys: list = None, - page: PNPage = None): + def __init__(self, pubnub, uuid: str = None, channel_memberships: List[PNChannelMembership] = None, + include_custom: bool = False, limit: int = None, filter: str = None, include_total_count: bool = None, + sort_keys: list = None, page: PNPage = None, include: MembershipIncludes = None): ObjectsEndpoint.__init__(self, pubnub) + IncludeCapableEndpoint.__init__(self, include=include) UuidEndpoint.__init__(self, uuid=uuid) ListEndpoint.__init__(self, limit=limit, filter=filter, include_total_count=include_total_count, sort_keys=sort_keys, page=page) @@ -40,6 +42,26 @@ def channel_memberships(self, channel_memberships): def validate_specific_params(self): self._validate_uuid() + def include(self, includes: MembershipIncludes) -> 'SetMemberships': + """ + Include additional information in the membership response. + + Parameters + ---------- + includes : MembershipIncludes + The additional information to include in the membership response. + + See Also + -------- + pubnub.models.consumer.objects_v2.common.MembershipIncludese : For details on the available includes. + + Returns + ------- + self : SetMemberships + """ + super().include(includes) + return self + def build_path(self): return SetMemberships.SET_MEMBERSHIP_PATH % (self.pubnub.config.subscribe_key, self._effective_uuid()) diff --git a/pubnub/endpoints/objects_v2/objects_endpoint.py b/pubnub/endpoints/objects_v2/objects_endpoint.py index 9efa556c..9ed2de3b 100644 --- a/pubnub/endpoints/objects_v2/objects_endpoint.py +++ b/pubnub/endpoints/objects_v2/objects_endpoint.py @@ -1,11 +1,13 @@ import logging -from abc import ABCMeta +from abc import ABCMeta from pubnub import utils from pubnub.endpoints.endpoint import Endpoint from pubnub.errors import PNERR_UUID_MISSING, PNERR_CHANNEL_MISSING from pubnub.exceptions import PubNubException from pubnub.models.consumer.objects_v2.page import Next, PNPage, Previous +from pubnub.models.consumer.objects_v2.common import PNIncludes +from pubnub.utils import deprecated logger = logging.getLogger("pubnub") @@ -13,6 +15,8 @@ class ObjectsEndpoint(Endpoint): __metaclass__ = ABCMeta + _includes: PNIncludes = None + def __init__(self, pubnub): Endpoint.__init__(self, pubnub) @@ -41,31 +45,11 @@ def encoded_params(self): def custom_params(self): params = {} - inclusions = [] - - if isinstance(self, IncludeCustomEndpoint): - if self._include_custom: - inclusions.append("custom") - - if isinstance(self, IncludeStatusTypeEndpoint): - if self._include_status: - inclusions.append("status") - if self._include_type: - inclusions.append("type") - if isinstance(self, UUIDIncludeEndpoint): - if self._uuid_details_level: - if self._uuid_details_level == UUIDIncludeEndpoint.UUID: - inclusions.append("uuid") - elif self._uuid_details_level == UUIDIncludeEndpoint.UUID_WITH_CUSTOM: - inclusions.append("uuid.custom") - - if isinstance(self, ChannelIncludeEndpoint): - if self._channel_details_level: - if self._channel_details_level == ChannelIncludeEndpoint.CHANNEL: - inclusions.append("channel") - elif self._channel_details_level == ChannelIncludeEndpoint.CHANNEL_WITH_CUSTOM: - inclusions.append("channel.custom") + if self._includes: + params["include"] = str(self._includes) + elif inclusions := self._legacy_inclusions(): + params["include"] = inclusions if isinstance(self, ListEndpoint): if self._filter: @@ -92,23 +76,54 @@ def custom_params(self): else: raise ValueError() - if len(inclusions) > 0: - params["include"] = ",".join(inclusions) - return params + def _legacy_inclusions(self): + inclusions = [] + + if isinstance(self, IncludeCustomEndpoint): + if self._include_custom: + inclusions.append("custom") + + if isinstance(self, IncludeStatusTypeEndpoint): + if self._include_status: + inclusions.append("status") + if self._include_type: + inclusions.append("type") + + if isinstance(self, UUIDIncludeEndpoint): + if self._uuid_details_level: + if self._uuid_details_level == UUIDIncludeEndpoint.UUID: + inclusions.append("uuid") + elif self._uuid_details_level == UUIDIncludeEndpoint.UUID_WITH_CUSTOM: + inclusions.append("uuid.custom") + + if isinstance(self, ChannelIncludeEndpoint): + if self._channel_details_level: + if self._channel_details_level == ChannelIncludeEndpoint.CHANNEL: + inclusions.append("channel") + elif self._channel_details_level == ChannelIncludeEndpoint.CHANNEL_WITH_CUSTOM: + inclusions.append("channel.custom") + + return ",".join(inclusions) + class CustomAwareEndpoint: __metaclass__ = ABCMeta def __init__(self, custom: dict = None): - self._custom = None + self._custom = custom def custom(self, custom: dict): self._custom = dict(custom) self._include_custom = True return self + def build_data(self, payload): + if self._custom: + payload["custom"] = self._custom + return payload + class StatusTypeAwareEndpoint: __metaclass__ = ABCMeta @@ -188,7 +203,24 @@ def filter(self, filter: str): self._filter = str(filter) return self + @deprecated(alternative="Include Object") def include_total_count(self, include_total_count: bool): + """DEPRECATED: + Sets whether to include total count of retrievable objects in the response. + + .. deprecated:: 10.1.0 + .. note:: Deprecated in 10_1_0 + Use `Include Object` instead. + + Parameters + ---------- + include_total_count : boolean + Sets whether to include total count of retrievable objects in the response. + + Returns + ------- + self + """ self._include_total_count = bool(include_total_count) return self @@ -201,13 +233,40 @@ def page(self, page: PNPage): return self +class IncludeCapableEndpoint: + _includes: PNIncludes = None + + def __init__(self, include: PNIncludes = None): + self.include(include) + + def include(self, includes: PNIncludes): + self._includes = includes + return self + + class IncludeCustomEndpoint: __metaclass__ = ABCMeta def __init__(self, include_custom: bool = None): self._include_custom = include_custom + @deprecated(alternative="Include Object") def include_custom(self, include_custom: bool): + """DEPRECATED: + Sets whether to include custom data in the response. + + .. deprecated:: 10.1.0 + Use `Include Object` instead. + + Parameters + ---------- + include_custom : boolean + whether to include custom data in the response + + Returns + ------- + self + """ self._include_custom = bool(include_custom) return self @@ -219,11 +278,43 @@ def __init__(self, include_status: bool = None, include_type: bool = None): self._include_status = include_status self._include_type = include_type + @deprecated(alternative="Include Object") def include_status(self, include_status: bool): + """DEPRECATED: + Sets whether to include status data in the response. + + .. deprecated:: 10.1.0 + Use `Include Object` instead. + + Parameters + ---------- + include_status : boolean + whether whether to include status data in the response. + + Returns + ------- + self + """ self._include_status = bool(include_status) return self + @deprecated(alternative="Include Object") def include_type(self, include_type: bool): + """DEPRECATED: + Sets whether to include type in the response. + + .. deprecated:: 10.1.0 + Use `Include Object` instead. + + Parameters + ---------- + include_type : boolean + whether to include type in the response + + Returns + ------- + self + """ self._include_type = bool(include_type) return self @@ -237,7 +328,23 @@ class UUIDIncludeEndpoint: def __init__(self): self._uuid_details_level = None + @deprecated(alternative="Include Object") def include_uuid(self, uuid_details_level): + """DEPRECATED: + Sets whether to include userid data in the response. + + .. deprecated:: 10.1.0 + Use `Include Object` instead. + + Parameters + ---------- + include_uuid : boolean + whether to include userid data in the response + + Returns + ------- + self + """ self._uuid_details_level = uuid_details_level return self @@ -251,6 +358,22 @@ class ChannelIncludeEndpoint: def __init__(self): self._channel_details_level = None + @deprecated(alternative="Include Object") def include_channel(self, channel_details_level): + """DEPRECATED: + Sets whether to include channel data in the response. + + .. deprecated:: 10.1.0 + Use `Include Object` instead. + + Parameters + ---------- + include_channel : boolean + whether to include channel data in the response + + Returns + ------- + self + """ self._channel_details_level = channel_details_level return self diff --git a/pubnub/endpoints/objects_v2/uuid/set_uuid.py b/pubnub/endpoints/objects_v2/uuid/set_uuid.py index c1d17c1f..81297cd1 100644 --- a/pubnub/endpoints/objects_v2/uuid/set_uuid.py +++ b/pubnub/endpoints/objects_v2/uuid/set_uuid.py @@ -57,8 +57,9 @@ def build_data(self): "email": self._email, "externalId": self._external_id, "profileUrl": self._profile_url, - "custom": self._custom } + + payload = CustomAwareEndpoint.build_data(self, payload) payload = StatusTypeAwareEndpoint.build_data(self, payload) return utils.write_value_as_string(payload) diff --git a/pubnub/models/consumer/objects_v2/channel_members.py b/pubnub/models/consumer/objects_v2/channel_members.py index d32c8926..60d593bc 100644 --- a/pubnub/models/consumer/objects_v2/channel_members.py +++ b/pubnub/models/consumer/objects_v2/channel_members.py @@ -1,6 +1,7 @@ from abc import abstractmethod, ABCMeta from pubnub.models.consumer.objects_v2.page import PNPageable +from pubnub.utils import deprecated class PNUUID: @@ -10,10 +11,12 @@ def __init__(self, uuid): self._uuid = uuid @staticmethod + @deprecated(alternative='PNUserMember class') def uuid(uuid): return JustUUID(uuid) @staticmethod + @deprecated(alternative='PNUserMember class') def uuid_with_custom(uuid, custom): return UUIDWithCustom(uuid, custom) @@ -45,6 +48,88 @@ def to_payload_dict(self): } +class PNUserMember(PNUUID): + """ + PNUser represents a user object with associated attributes and methods to convert it to a payload dictionary. + + Attributes + ---------- + _user_id : str + The unique identifier for the user. + _type : str + The type of the user. + _status : str + The status of the user. + _custom : any + Custom attributes associated with the user. + + Methods + ------- + __init__(user_id: str = None, type: str = None, status: str = None, custom: any = None) + Initializes a new instance of PNUser with required user_id, and optional type, status, and custom attributes. + to_payload_dict() + Converts the PNUser instance to a dictionary payload suitable for transmission. + """ + + _user_id: str + _type: str + _status: str + _custom: any + + @property + def _uuuid(self): + return self._user_id + + def __init__(self, user_id: str, type: str = None, status: str = None, custom: any = None): + """ + Initialize a PNUser object. If optional values are omitted then they won't be included in the payload. + + Parameters + ---------- + user_id : str + The unique identifier for the user. + type : str, optional + The type of the channel member (default is None). + status : str, optional + The status of the channel member (default is None). + custom : any, optional + Custom data associated with the channel member (default is None). + """ + + self._user_id = user_id + self._type = type + self._status = status + self._custom = custom + + def to_payload_dict(self): + """ + Convert the objects attributes to a dictionary payload. + + Returns + + ------- + dict + A dictionary containing the objects attributes: + - "uuid": A dictionary with the member's UUID. + - "type": The type of the member, if available. + - "status": The status of the member, if available. + - "custom": Custom attributes of the member, if available. + """ + + payload = { + "uuid": { + "id": str(self._user_id) + }, + } + if self._type: + payload["type"] = str(self._type) + if self._status: + payload["status"] = str(self._status) + if self._custom: + payload["custom"] = dict(self._custom) + return payload + + class PNSetChannelMembersResult(PNPageable): def __init__(self, result): PNPageable.__init__(self, result) diff --git a/pubnub/models/consumer/objects_v2/common.py b/pubnub/models/consumer/objects_v2/common.py new file mode 100644 index 00000000..726872cf --- /dev/null +++ b/pubnub/models/consumer/objects_v2/common.py @@ -0,0 +1,153 @@ +""" +This module defines classes for handling inclusion fields in PubNub objects. + +Classes: + PNIncludes: Base class for managing field mappings and string representation of included fields. + MembershipIncludes: Inherits from PNIncludes, manages inclusion fields specific to membership objects. + MemberIncludes: Inherits from PNIncludes, manages inclusion fields specific to member objects. +""" + + +class PNIncludes: + """ + Base class for specific include classes that handles field mapping for all child classes. + + Attributes + ---------- + field_mapping : dict + A dictionary that maps internal field names to their corresponding external representations. + + Methods + ------- + __str__(): + Returns a string representation of the object, consisting of the mapped field names that have non-false values. + """ + + field_mapping = { + 'custom': 'custom', + 'status': 'status', + 'type': 'type', + 'total_count': 'totalCount', + 'channel': 'channel', + 'channel_id': 'channel.id', + 'channel_custom': 'channel.custom', + 'channel_type': 'channel.type', + 'channel_status': 'channel.status', + 'user': 'uuid', + 'user_id': 'uuid.id', + 'user_custom': 'uuid.custom', + 'user_type': 'uuid.type', + 'user_status': 'uuid.status', + } + + def __str__(self): + """String formated to be used in requests.""" + return ','.join([self.field_mapping[k] for k, v in self.__dict__.items() if v]) + + +class MembershipIncludes(PNIncludes): + """ + MembershipIncludes is a class used to define what can be included in the objects membership endpoints. + + Attributes + ---------- + custom : bool + Indicates whether custom data should be included in the response. + status : bool + Indicates whether the status should be included in the response. + type : bool + Indicates whether the type should be included in the response. + total_count : bool + Indicates whether the total count should be included in the response. + channel : bool + Indicates whether the channel information should be included in the response. + channel_custom : bool + Indicates whether custom data for the channel should be included in the response. + channel_type : bool + Indicates whether the type of the channel should be included in the response. + channel_status : bool + Indicates whether the status of the channel should be included in the response. + + Methods + ------- + __init__(self, custom: bool = False, status: bool = False, type: bool = False, + channel_type: bool = False, channel_status: bool = False) + """ + def __init__(self, custom: bool = False, status: bool = False, type: bool = False, + total_count: bool = False, channel: bool = False, channel_custom: bool = False, + channel_type: bool = False, channel_status: bool = False): + """ + Initialize the Membership values to include within the response. By default, no values are included. + + Parameters + ---------- + custom : bool, optional + status : bool, optional + type : bool, optional + total_count : bool, optional + channel : bool, optional + channel_custom : bool, optional + channel_type : bool, optional + channel_status : bool, optional + """ + + self.custom = custom + self.status = status + self.type = type + self.total_count = total_count + self.channel = channel + self.channel_custom = channel_custom + self.channel_type = channel_type + self.channel_status = channel_status + + +class MemberIncludes(PNIncludes): + """ + MemberIncludes is a class used to define the values to include within the response for members requests. + + Attributes + ---------- + custom : bool + Indicates whether custom data should be included in the response. + status : bool + Indicates whether the status should be included in the response. + type : bool + Indicates whether the type should be included in the response. + total_count : bool + Indicates whether the total count should be included in the response. + user : bool + Indicates whether the user id should be included in the response. + user_custom : bool + Indicates whether custom data defined for the user should be included in the response. + user_type : bool + Indicates whether the type of the user should be included in the response. + user_status : bool + Indicates whether the status of the user should be included in the response. + """ + + def __init__(self, custom: bool = False, status: bool = False, type: bool = False, + total_count: bool = False, user: bool = False, user_custom: bool = False, + user_type: bool = False, user_status: bool = False): + """ + Initialize the Member values to include within the response. By default, no values are included. + + Parameters + ---------- + custom : bool, optional + status : bool, optional + type : bool, optional + total_count : bool, optional + channel : bool, optional + channel_custom : bool, optional + channel_type : bool, optional + channel_status : bool, optional + """ + + self.custom = custom + self.status = status + self.type = type + self.total_count = total_count + self.user = user + self.user_custom = user_custom + self.user_type = user_type + self.user_status = user_status diff --git a/pubnub/models/consumer/objects_v2/memberships.py b/pubnub/models/consumer/objects_v2/memberships.py index 9ab819d0..ba195686 100644 --- a/pubnub/models/consumer/objects_v2/memberships.py +++ b/pubnub/models/consumer/objects_v2/memberships.py @@ -6,8 +6,11 @@ class PNChannelMembership: __metaclass__ = ABCMeta - def __init__(self, channel): + def __init__(self, channel: str, custom: dict = None, status: str = None, type: str = None): self._channel = channel + self._custom = custom + self._status = status + self._type = type @staticmethod def channel(channel): @@ -19,7 +22,18 @@ def channel_with_custom(channel, custom): @abstractmethod def to_payload_dict(self): - return None + result = { + "channel": { + "id": str(self._channel) + } + } + if self._custom: + result["custom"] = dict(self._custom) + if self._status: + result["status"] = str(self._status) + if self._type: + result["type"] = str(self._type) + return result class JustChannel(PNChannelMembership): diff --git a/pubnub/pubnub_core.py b/pubnub/pubnub_core.py index 6383532a..f0afaede 100644 --- a/pubnub/pubnub_core.py +++ b/pubnub/pubnub_core.py @@ -24,6 +24,8 @@ from pubnub.features import feature_flag from pubnub.crypto import PubNubCryptoModule from pubnub.models.consumer.message_actions import PNMessageAction +from pubnub.models.consumer.objects_v2.channel_members import PNUUID +from pubnub.models.consumer.objects_v2.common import MemberIncludes, MembershipIncludes from pubnub.models.consumer.objects_v2.page import PNPage from pubnub.models.subscription import PubNubChannel, PubNubChannelGroup, PubNubChannelMetadata, PubNubUserMetadata, \ PNSubscriptionRegistry, PubNubSubscriptionSet @@ -94,7 +96,7 @@ class PubNubCore: """A base class for PubNub Python API implementations""" - SDK_VERSION = "10.0.1" + SDK_VERSION = "10.1.0" SDK_NAME = "PubNub-Python" TIMESTAMP_DIVIDER = 1000 @@ -322,53 +324,93 @@ def get_all_channel_metadata(self, include_custom=False, include_status=True, in include_type=include_type, limit=limit, filter=filter, include_total_count=include_total_count, sort_keys=sort_keys, page=page) - def set_channel_members(self, channel: str = None, uuids: List[str] = None, include_custom: bool = None, + def set_channel_members(self, channel: str = None, uuids: List[PNUUID] = None, include_custom: bool = None, limit: int = None, filter: str = None, include_total_count: bool = None, - sort_keys: list = None, page: PNPage = None) -> SetChannelMembers: + sort_keys: list = None, page: PNPage = None, include: MemberIncludes = None + ) -> SetChannelMembers: + """ Creates a builder for setting channel members. Can be used both as a builder or as a single call with + named parameters. + + Parameters + ---------- + channel : str + The channel for which members are being set. + uuids : List[PNUUID] + List of users to be set as members of the channel. + include_custom : bool, optional + Whether to include custom fields in the response. + limit : int, optional + Maximum number of results to return. + filter : str, optional + Filter expression to apply to the results. + include_total_count : bool, optional + Whether to include the total count of results. + sort_keys : list, optional + List of keys to sort the results by. + page : PNPage, optional + Pagination information. + include : MemberIncludes, optional + Additional fields to include in the response. + :return: An instance of SetChannelMembers builder. + :rtype: SetChannelMembers + + Example: + -------- + pn = PubNub(config) + users = [PNUser("user1"), PNUser("user2", type="admin", status="offline")] + response = pn.set_channel_members(channel="my_channel", uuids=users).sync() + """ return SetChannelMembers(self, channel=channel, uuids=uuids, include_custom=include_custom, limit=limit, - filter=filter, include_total_count=include_total_count, sort_keys=sort_keys, page=page) + filter=filter, include_total_count=include_total_count, sort_keys=sort_keys, page=page, + include=include) def get_channel_members(self, channel: str = None, include_custom: bool = None, limit: int = None, filter: str = None, include_total_count: bool = None, sort_keys: list = None, - page: PNPage = None) -> GetChannelMembers: + page: PNPage = None, include: MemberIncludes = None) -> GetChannelMembers: return GetChannelMembers(self, channel=channel, include_custom=include_custom, limit=limit, filter=filter, - include_total_count=include_total_count, sort_keys=sort_keys, page=page) + include_total_count=include_total_count, sort_keys=sort_keys, page=page, + include=include) def remove_channel_members(self, channel: str = None, uuids: List[str] = None, include_custom: bool = None, limit: int = None, filter: str = None, include_total_count: bool = None, - sort_keys: list = None, page: PNPage = None) -> RemoveChannelMembers: + sort_keys: list = None, page: PNPage = None, include: MemberIncludes = None + ) -> RemoveChannelMembers: return RemoveChannelMembers(self, channel=channel, uuids=uuids, include_custom=include_custom, limit=limit, filter=filter, include_total_count=include_total_count, sort_keys=sort_keys, - page=page) + page=page, include=include) def manage_channel_members(self, channel: str = None, uuids_to_set: List[str] = None, uuids_to_remove: List[str] = None, include_custom: bool = None, limit: int = None, filter: str = None, include_total_count: bool = None, sort_keys: list = None, - page: PNPage = None) -> ManageChannelMembers: + page: PNPage = None, include: MemberIncludes = None) -> ManageChannelMembers: return ManageChannelMembers(self, channel=channel, uuids_to_set=uuids_to_set, uuids_to_remove=uuids_to_remove, include_custom=include_custom, limit=limit, filter=filter, - include_total_count=include_total_count, sort_keys=sort_keys, page=page) + include_total_count=include_total_count, sort_keys=sort_keys, page=page, + include=include) def set_memberships(self, uuid: str = None, channel_memberships: List[str] = None, include_custom: bool = False, limit: int = None, filter: str = None, include_total_count: bool = None, sort_keys: list = None, - page: PNPage = None) -> SetMemberships: + page: PNPage = None, include: MembershipIncludes = None) -> SetMemberships: return SetMemberships(self, uuid=uuid, channel_memberships=channel_memberships, include_custom=include_custom, limit=limit, filter=filter, include_total_count=include_total_count, sort_keys=sort_keys, - page=page) + page=page, include=include) def get_memberships(self, uuid: str = None, include_custom: bool = False, limit: int = None, filter: str = None, - include_total_count: bool = None, sort_keys: list = None, page: PNPage = None): + include_total_count: bool = None, sort_keys: list = None, page: PNPage = None, + include: MembershipIncludes = None): return GetMemberships(self, uuid=uuid, include_custom=include_custom, limit=limit, filter=filter, - include_total_count=include_total_count, sort_keys=sort_keys, page=page) + include_total_count=include_total_count, sort_keys=sort_keys, page=page, include=include) def manage_memberships(self, uuid: str = None, channel_memberships_to_set: List[str] = None, channel_memberships_to_remove: List[str] = None, include_custom: bool = False, limit: int = None, filter: str = None, include_total_count: bool = None, - sort_keys: list = None, page: PNPage = None) -> ManageMemberships: + sort_keys: list = None, page: PNPage = None, include: MembershipIncludes = None + ) -> ManageMemberships: return ManageMemberships(self, uuid=uuid, channel_memberships_to_set=channel_memberships_to_set, channel_memberships_to_remove=channel_memberships_to_remove, include_custom=include_custom, limit=limit, filter=filter, - include_total_count=include_total_count, sort_keys=sort_keys, page=page) + include_total_count=include_total_count, sort_keys=sort_keys, page=page, + include=include) def fetch_messages(self, channels: Union[str, List[str]] = None, start: int = None, end: int = None, count: int = None, include_meta: bool = None, include_message_actions: bool = None, @@ -693,15 +735,15 @@ def update_memberships( return membership def remove_memberships(self, **kwargs): - if len(kwargs) == 0: - return RemoveMemberships(self) + if len(kwargs) == 0 or ('user_id' not in kwargs.keys() and 'space_id' not in kwargs.keys()): + return RemoveMemberships(self, **kwargs) if 'user_id' in kwargs.keys() and 'space_id' in kwargs.keys(): raise (PubNubException(pn_error=PNERR_MISUSE_OF_USER_AND_SPACE)) - if kwargs['user_id'] and kwargs['spaces']: + if 'user_id' in kwargs.keys() and 'spaces' in kwargs.keys(): membership = RemoveUserSpaces(self).user_id(kwargs['user_id']).spaces(kwargs['spaces']) - elif kwargs['space_id'] and kwargs['users']: + elif 'space_id' in kwargs.keys() and 'users' in kwargs.keys(): membership = RemoveSpaceMembers(self).space_id(kwargs['space_id']).users(kwargs['users']) else: raise (PubNubException(pn_error=PNERR_USER_SPACE_PAIRS_MISSING)) diff --git a/pubnub/request_handlers/__init__.py b/pubnub/request_handlers/__init__.py index e69de29b..02d6bfb4 100644 --- a/pubnub/request_handlers/__init__.py +++ b/pubnub/request_handlers/__init__.py @@ -0,0 +1,16 @@ +""" +This module initializes the request handlers for the PubNub Python SDK. + +The request handlers are responsible for managing the communication between +the client and the PubNub service. They handle the construction, sending, +and receiving of HTTP requests and responses. + +Classes +------- +AsyncAiohttpRequestHandler +AsyncHttpxRequestHandler +BaseRequestHandler +HttpxRequestHandler +PubNubAsyncHTTPTransport +RequestsRequestHandler +""" diff --git a/pubnub/utils.py b/pubnub/utils.py index 2838bac8..42178bb1 100644 --- a/pubnub/utils.py +++ b/pubnub/utils.py @@ -1,15 +1,18 @@ import datetime +import functools import hmac import json import uuid as u import threading import urllib +import warnings + from hashlib import sha256 -from .enums import PNStatusCategory, PNOperationType, PNPushType, HttpMethod, PAMPermissions -from .models.consumer.common import PNStatus -from .errors import PNERR_JSON_NOT_SERIALIZABLE -from .exceptions import PubNubException +from pubnub.enums import PNStatusCategory, PNOperationType, PNPushType, HttpMethod, PAMPermissions +from pubnub.models.consumer.common import PNStatus +from pubnub.errors import PNERR_JSON_NOT_SERIALIZABLE +from pubnub.exceptions import PubNubException def get_data_for_user(data): @@ -321,3 +324,27 @@ def parse_pam_permissions(resource): } return new_res + + +def deprecated(alternative=None, warning_message=None): + """A decorator to mark functions as deprecated.""" + + def decorator(func): + if warning_message: + message = warning_message + else: + message = f"The function {func.__name__} is deprecated." + if alternative: + message += f" Use: {alternative} instead" + + @functools.wraps(func) + def wrapper(*args, **kwargs): + warnings.warn( + message, + category=DeprecationWarning, + stacklevel=2 + ) + return func(*args, **kwargs) + + return wrapper + return decorator diff --git a/setup.py b/setup.py index 2d95e496..ad61b695 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name='pubnub', - version='10.0.1', + version='10.1.0', description='PubNub Real-time push service in the cloud', author='PubNub', author_email='support@pubnub.com', diff --git a/tests/integrational/fixtures/native_sync/objects_v2/channel_members/channel_members_with_include_object.json b/tests/integrational/fixtures/native_sync/objects_v2/channel_members/channel_members_with_include_object.json new file mode 100644 index 00000000..a7edece5 --- /dev/null +++ b/tests/integrational/fixtures/native_sync/objects_v2/channel_members/channel_members_with_include_object.json @@ -0,0 +1,416 @@ +{ + "version": 1, + "interactions": [ + { + "request": { + "method": "PATCH", + "uri": "https://ps.pndsn.com/v2/objects/{PN_KEY_SUBSCRIBE}/uuids/someuuid?include=status%2Ctype", + "body": { + "pickle": "gASVjwAAAAAAAACMi3sibmFtZSI6ICJDYXJvbGluZSIsICJlbWFpbCI6IG51bGwsICJleHRlcm5hbElkIjogbnVsbCwgInByb2ZpbGVVcmwiOiBudWxsLCAiY3VzdG9tIjogeyJyZW1vdmVkIjogZmFsc2V9LCAic3RhdHVzIjogIm9ubGluZSIsICJ0eXBlIjogIlFBIn2ULg==" + }, + "headers": { + "host": [ + "ps.pndsn.com" + ], + "accept": [ + "*/*" + ], + "accept-encoding": [ + "gzip, deflate" + ], + "connection": [ + "keep-alive" + ], + "user-agent": [ + "PubNub-Python/10.0.0" + ], + "content-type": [ + "application/json" + ], + "content-length": [ + "139" + ] + } + }, + "response": { + "status": { + "code": 200, + "message": "OK" + }, + "headers": { + "Date": [ + "Sat, 18 Jan 2025 20:35:07 GMT" + ], + "Content-Type": [ + "application/json" + ], + "Content-Length": [ + "218" + ], + "Connection": [ + "keep-alive" + ], + "Access-Control-Allow-Credentials": [ + "true" + ], + "Access-Control-Expose-Headers": [ + "*" + ] + }, + "body": { + "pickle": "gASV6gAAAAAAAAB9lIwGc3RyaW5nlIzaeyJzdGF0dXMiOjIwMCwiZGF0YSI6eyJpZCI6InNvbWV1dWlkIiwibmFtZSI6IkNhcm9saW5lIiwiZXh0ZXJuYWxJZCI6bnVsbCwicHJvZmlsZVVybCI6bnVsbCwiZW1haWwiOm51bGwsInR5cGUiOiJRQSIsInN0YXR1cyI6Im9ubGluZSIsInVwZGF0ZWQiOiIyMDI1LTAxLTE4VDIwOjM1OjA3LjIzNjYxN1oiLCJlVGFnIjoiZjJiYmNkZjY5OWY4NjdkNjBiYzgxNmMxZWIyNTQ3YzkifX2Ucy4=" + } + } + }, + { + "request": { + "method": "PATCH", + "uri": "https://ps.pndsn.com/v2/objects/{PN_KEY_SUBSCRIBE}/channels/somechannel?include=status%2Ctype", + "body": { + "pickle": "gASViwAAAAAAAACMh3sibmFtZSI6ICJzb21lIG5hbWUiLCAiZGVzY3JpcHRpb24iOiAiVGhpcyBpcyBhIGJpdCBsb25nZXIgdGV4dCIsICJzdGF0dXMiOiAiYWN0aXZlIiwgInR5cGUiOiAiUUFDaGFubmVsIiwgImN1c3RvbSI6IHsicHVibGljIjogZmFsc2V9fZQu" + }, + "headers": { + "host": [ + "ps.pndsn.com" + ], + "accept": [ + "*/*" + ], + "accept-encoding": [ + "gzip, deflate" + ], + "connection": [ + "keep-alive" + ], + "user-agent": [ + "PubNub-Python/10.0.0" + ], + "content-type": [ + "application/json" + ], + "content-length": [ + "135" + ] + } + }, + "response": { + "status": { + "code": 200, + "message": "OK" + }, + "headers": { + "Date": [ + "Sat, 18 Jan 2025 20:35:07 GMT" + ], + "Content-Type": [ + "application/json" + ], + "Content-Length": [ + "222" + ], + "Connection": [ + "keep-alive" + ], + "Access-Control-Allow-Credentials": [ + "true" + ], + "Access-Control-Expose-Headers": [ + "*" + ] + }, + "body": { + "pickle": "gASV7gAAAAAAAAB9lIwGc3RyaW5nlIzeeyJzdGF0dXMiOjIwMCwiZGF0YSI6eyJpZCI6InNvbWVjaGFubmVsIiwibmFtZSI6InNvbWUgbmFtZSIsImRlc2NyaXB0aW9uIjoiVGhpcyBpcyBhIGJpdCBsb25nZXIgdGV4dCIsInR5cGUiOiJRQUNoYW5uZWwiLCJzdGF0dXMiOiJhY3RpdmUiLCJ1cGRhdGVkIjoiMjAyNS0wMS0xNlQyMTo1OTo0NC4yODkzODZaIiwiZVRhZyI6IjcwY2YxMTc3NmFhMDExZWZiMTRmYmU4Zjc3ZDdkMDQwIn19lHMu" + } + } + }, + { + "request": { + "method": "PATCH", + "uri": "https://ps.pndsn.com/v2/objects/{PN_KEY_SUBSCRIBE}/channels/somechannel/uuids?include=custom%2Cstatus%2Ctype%2CtotalCount%2Cuuid%2Cuuid.custom%2Cuuid.type%2Cuuid.status", + "body": { + "pickle": "gASVeQAAAAAAAACMdXsic2V0IjogW3sidXVpZCI6IHsiaWQiOiAic29tZXV1aWQifSwgInR5cGUiOiAiUUEiLCAic3RhdHVzIjogImFjdGl2ZSIsICJjdXN0b20iOiB7ImlzQ3VzdG9tIjogdHJ1ZX19XSwgImRlbGV0ZSI6IFtdfZQu" + }, + "headers": { + "host": [ + "ps.pndsn.com" + ], + "accept": [ + "*/*" + ], + "accept-encoding": [ + "gzip, deflate" + ], + "connection": [ + "keep-alive" + ], + "user-agent": [ + "PubNub-Python/10.0.0" + ], + "content-type": [ + "application/json" + ], + "content-length": [ + "117" + ] + } + }, + "response": { + "status": { + "code": 200, + "message": "OK" + }, + "headers": { + "Date": [ + "Sat, 18 Jan 2025 20:35:07 GMT" + ], + "Content-Type": [ + "application/json" + ], + "Content-Length": [ + "389" + ], + "Connection": [ + "keep-alive" + ], + "Access-Control-Allow-Credentials": [ + "true" + ], + "Access-Control-Expose-Headers": [ + "*" + ] + }, + "body": { + "pickle": "gASVmAEAAAAAAAB9lIwGc3RyaW5nlFiFAQAAeyJzdGF0dXMiOjIwMCwiZGF0YSI6W3sidXVpZCI6eyJpZCI6InNvbWV1dWlkIiwibmFtZSI6IkNhcm9saW5lIiwiZXh0ZXJuYWxJZCI6bnVsbCwicHJvZmlsZVVybCI6bnVsbCwiZW1haWwiOm51bGwsInR5cGUiOiJRQSIsInN0YXR1cyI6Im9ubGluZSIsImN1c3RvbSI6eyJyZW1vdmVkIjpmYWxzZX0sInVwZGF0ZWQiOiIyMDI1LTAxLTE4VDIwOjM1OjA3LjIzNjYxN1oiLCJlVGFnIjoiZjJiYmNkZjY5OWY4NjdkNjBiYzgxNmMxZWIyNTQ3YzkifSwidHlwZSI6IlFBIiwic3RhdHVzIjoiYWN0aXZlIiwiY3VzdG9tIjp7ImlzQ3VzdG9tIjp0cnVlfSwidXBkYXRlZCI6IjIwMjUtMDEtMThUMjA6MzU6MDcuODc2NDE0WiIsImVUYWciOiJBY1gzemE2dHdjaWdaQSJ9XSwibmV4dCI6Ik1RIn2Ucy4=" + } + } + }, + { + "request": { + "method": "GET", + "uri": "https://ps.pndsn.com/v2/objects/{PN_KEY_SUBSCRIBE}/channels/somechannel/uuids?include=custom%2Cstatus%2Ctype%2CtotalCount%2Cuuid%2Cuuid.custom%2Cuuid.type%2Cuuid.status", + "body": "", + "headers": { + "host": [ + "ps.pndsn.com" + ], + "accept": [ + "*/*" + ], + "accept-encoding": [ + "gzip, deflate" + ], + "connection": [ + "keep-alive" + ], + "user-agent": [ + "PubNub-Python/10.0.0" + ] + } + }, + "response": { + "status": { + "code": 200, + "message": "OK" + }, + "headers": { + "Date": [ + "Sat, 18 Jan 2025 20:35:08 GMT" + ], + "Content-Type": [ + "application/json" + ], + "Content-Length": [ + "389" + ], + "Connection": [ + "keep-alive" + ], + "Access-Control-Allow-Credentials": [ + "true" + ], + "Access-Control-Expose-Headers": [ + "*" + ] + }, + "body": { + "pickle": "gASVmAEAAAAAAAB9lIwGc3RyaW5nlFiFAQAAeyJzdGF0dXMiOjIwMCwiZGF0YSI6W3sidXVpZCI6eyJpZCI6InNvbWV1dWlkIiwibmFtZSI6IkNhcm9saW5lIiwiZXh0ZXJuYWxJZCI6bnVsbCwicHJvZmlsZVVybCI6bnVsbCwiZW1haWwiOm51bGwsInR5cGUiOiJRQSIsInN0YXR1cyI6Im9ubGluZSIsImN1c3RvbSI6eyJyZW1vdmVkIjpmYWxzZX0sInVwZGF0ZWQiOiIyMDI1LTAxLTE4VDIwOjM1OjA3LjIzNjYxN1oiLCJlVGFnIjoiZjJiYmNkZjY5OWY4NjdkNjBiYzgxNmMxZWIyNTQ3YzkifSwidHlwZSI6IlFBIiwic3RhdHVzIjoiYWN0aXZlIiwiY3VzdG9tIjp7ImlzQ3VzdG9tIjp0cnVlfSwidXBkYXRlZCI6IjIwMjUtMDEtMThUMjA6MzU6MDcuODc2NDE0WiIsImVUYWciOiJBY1gzemE2dHdjaWdaQSJ9XSwibmV4dCI6Ik1RIn2Ucy4=" + } + } + }, + { + "request": { + "method": "PATCH", + "uri": "https://ps.pndsn.com/v2/objects/{PN_KEY_SUBSCRIBE}/channels/somechannel/uuids", + "body": { + "pickle": "gASVlgAAAAAAAACMknsic2V0IjogW3sidXVpZCI6IHsiaWQiOiAib3RoZXJ1dWlkIn19XSwgImRlbGV0ZSI6IFt7InV1aWQiOiB7ImlkIjogInNvbWV1dWlkIn0sICJ0eXBlIjogIlFBIiwgInN0YXR1cyI6ICJhY3RpdmUiLCAiY3VzdG9tIjogeyJpc0N1c3RvbSI6IHRydWV9fV19lC4=" + }, + "headers": { + "host": [ + "ps.pndsn.com" + ], + "accept": [ + "*/*" + ], + "accept-encoding": [ + "gzip, deflate" + ], + "connection": [ + "keep-alive" + ], + "user-agent": [ + "PubNub-Python/10.0.0" + ], + "content-type": [ + "application/json" + ], + "content-length": [ + "146" + ] + } + }, + "response": { + "status": { + "code": 200, + "message": "OK" + }, + "headers": { + "Date": [ + "Sat, 18 Jan 2025 20:35:08 GMT" + ], + "Content-Type": [ + "application/json" + ], + "Content-Length": [ + "128" + ], + "Connection": [ + "keep-alive" + ], + "Access-Control-Allow-Credentials": [ + "true" + ], + "Access-Control-Expose-Headers": [ + "*" + ] + }, + "body": { + "pickle": "gASVkAAAAAAAAAB9lIwGc3RyaW5nlIyAeyJzdGF0dXMiOjIwMCwiZGF0YSI6W3sidXVpZCI6eyJpZCI6Im90aGVydXVpZCJ9LCJ1cGRhdGVkIjoiMjAyNS0wMS0xOFQyMDozNTowOC41MjYwMTZaIiwiZVRhZyI6IkFmYWgycVMxOTllNzRRRSJ9XSwibmV4dCI6Ik1RIn2Ucy4=" + } + } + }, + { + "request": { + "method": "PATCH", + "uri": "https://ps.pndsn.com/v2/objects/{PN_KEY_SUBSCRIBE}/channels/somechannel/uuids", + "body": { + "pickle": "gASVOgAAAAAAAACMNnsic2V0IjogW10sICJkZWxldGUiOiBbeyJ1dWlkIjogeyJpZCI6ICJvdGhlcnV1aWQifX1dfZQu" + }, + "headers": { + "host": [ + "ps.pndsn.com" + ], + "accept": [ + "*/*" + ], + "accept-encoding": [ + "gzip, deflate" + ], + "connection": [ + "keep-alive" + ], + "user-agent": [ + "PubNub-Python/10.0.0" + ], + "content-type": [ + "application/json" + ], + "content-length": [ + "54" + ] + } + }, + "response": { + "status": { + "code": 200, + "message": "OK" + }, + "headers": { + "Date": [ + "Sat, 18 Jan 2025 20:35:08 GMT" + ], + "Content-Type": [ + "application/json" + ], + "Content-Length": [ + "24" + ], + "Connection": [ + "keep-alive" + ], + "Access-Control-Allow-Credentials": [ + "true" + ], + "Access-Control-Expose-Headers": [ + "*" + ] + }, + "body": { + "pickle": "gASVKAAAAAAAAAB9lIwGc3RyaW5nlIwYeyJzdGF0dXMiOjIwMCwiZGF0YSI6W119lHMu" + } + } + }, + { + "request": { + "method": "GET", + "uri": "https://ps.pndsn.com/v2/objects/{PN_KEY_SUBSCRIBE}/channels/somechannel/uuids?include=custom%2Cstatus%2Ctype%2CtotalCount%2Cuuid%2Cuuid.custom%2Cuuid.type%2Cuuid.status", + "body": "", + "headers": { + "host": [ + "ps.pndsn.com" + ], + "accept": [ + "*/*" + ], + "accept-encoding": [ + "gzip, deflate" + ], + "connection": [ + "keep-alive" + ], + "user-agent": [ + "PubNub-Python/10.0.0" + ] + } + }, + "response": { + "status": { + "code": 200, + "message": "OK" + }, + "headers": { + "Date": [ + "Sat, 18 Jan 2025 20:35:09 GMT" + ], + "Content-Type": [ + "application/json" + ], + "Content-Length": [ + "24" + ], + "Connection": [ + "keep-alive" + ], + "Access-Control-Allow-Credentials": [ + "true" + ], + "Access-Control-Expose-Headers": [ + "*" + ] + }, + "body": { + "pickle": "gASVKAAAAAAAAAB9lIwGc3RyaW5nlIwYeyJzdGF0dXMiOjIwMCwiZGF0YSI6W119lHMu" + } + } + } + ] +} diff --git a/tests/integrational/fixtures/native_sync/objects_v2/channel_members/setup_module.json b/tests/integrational/fixtures/native_sync/objects_v2/channel_members/setup_module.json new file mode 100644 index 00000000..5d67dcce --- /dev/null +++ b/tests/integrational/fixtures/native_sync/objects_v2/channel_members/setup_module.json @@ -0,0 +1,225 @@ +{ + "version": 1, + "interactions": [ + { + "request": { + "method": "DELETE", + "uri": "https://ps.pndsn.com/v2/objects/{PN_KEY_SUBSCRIBE}/uuids/someuuid", + "body": "", + "headers": { + "host": [ + "ps.pndsn.com" + ], + "accept": [ + "*/*" + ], + "accept-encoding": [ + "gzip, deflate" + ], + "connection": [ + "keep-alive" + ], + "user-agent": [ + "PubNub-Python/10.0.0" + ] + } + }, + "response": { + "status": { + "code": 200, + "message": "OK" + }, + "headers": { + "Date": [ + "Sat, 18 Jan 2025 20:35:05 GMT" + ], + "Content-Type": [ + "application/json" + ], + "Content-Length": [ + "26" + ], + "Connection": [ + "keep-alive" + ], + "Access-Control-Allow-Credentials": [ + "true" + ], + "Access-Control-Expose-Headers": [ + "*" + ] + }, + "body": { + "pickle": "gASVKgAAAAAAAAB9lIwGc3RyaW5nlIwaeyJzdGF0dXMiOjIwMCwiZGF0YSI6bnVsbH2Ucy4=" + } + } + }, + { + "request": { + "method": "DELETE", + "uri": "https://ps.pndsn.com/v2/objects/{PN_KEY_SUBSCRIBE}/uuids/otheruuid", + "body": "", + "headers": { + "host": [ + "ps.pndsn.com" + ], + "accept": [ + "*/*" + ], + "accept-encoding": [ + "gzip, deflate" + ], + "connection": [ + "keep-alive" + ], + "user-agent": [ + "PubNub-Python/10.0.0" + ] + } + }, + "response": { + "status": { + "code": 200, + "message": "OK" + }, + "headers": { + "Date": [ + "Sat, 18 Jan 2025 20:35:05 GMT" + ], + "Content-Type": [ + "application/json" + ], + "Content-Length": [ + "26" + ], + "Connection": [ + "keep-alive" + ], + "Access-Control-Allow-Credentials": [ + "true" + ], + "Access-Control-Expose-Headers": [ + "*" + ] + }, + "body": { + "pickle": "gASVKgAAAAAAAAB9lIwGc3RyaW5nlIwaeyJzdGF0dXMiOjIwMCwiZGF0YSI6bnVsbH2Ucy4=" + } + } + }, + { + "request": { + "method": "DELETE", + "uri": "https://ps.pndsn.com/v2/objects/{PN_KEY_SUBSCRIBE}/channels/somechannelid", + "body": "", + "headers": { + "host": [ + "ps.pndsn.com" + ], + "accept": [ + "*/*" + ], + "accept-encoding": [ + "gzip, deflate" + ], + "connection": [ + "keep-alive" + ], + "user-agent": [ + "PubNub-Python/10.0.0" + ] + } + }, + "response": { + "status": { + "code": 200, + "message": "OK" + }, + "headers": { + "Date": [ + "Sat, 18 Jan 2025 20:35:05 GMT" + ], + "Content-Type": [ + "application/json" + ], + "Content-Length": [ + "26" + ], + "Connection": [ + "keep-alive" + ], + "Access-Control-Allow-Credentials": [ + "true" + ], + "Access-Control-Expose-Headers": [ + "*" + ] + }, + "body": { + "pickle": "gASVKgAAAAAAAAB9lIwGc3RyaW5nlIwaeyJzdGF0dXMiOjIwMCwiZGF0YSI6bnVsbH2Ucy4=" + } + } + }, + { + "request": { + "method": "PATCH", + "uri": "https://ps.pndsn.com/v2/objects/{PN_KEY_SUBSCRIBE}/channels/somechannelid/uuids", + "body": { + "pickle": "gASVfQAAAAAAAACMeXsic2V0IjogW10sICJkZWxldGUiOiBbeyJ1dWlkIjogeyJpZCI6ICJzb21ldXVpZCJ9fSwgeyJ1dWlkIjogeyJpZCI6ICJvdGhlcnV1aWQifX0sIHsidXVpZCI6IHsiaWQiOiAic29tZXV1aWRfc2ltcGxlIn19XX2ULg==" + }, + "headers": { + "host": [ + "ps.pndsn.com" + ], + "accept": [ + "*/*" + ], + "accept-encoding": [ + "gzip, deflate" + ], + "connection": [ + "keep-alive" + ], + "user-agent": [ + "PubNub-Python/10.0.0" + ], + "content-type": [ + "application/json" + ], + "content-length": [ + "121" + ] + } + }, + "response": { + "status": { + "code": 200, + "message": "OK" + }, + "headers": { + "Date": [ + "Sat, 18 Jan 2025 20:35:06 GMT" + ], + "Content-Type": [ + "application/json" + ], + "Content-Length": [ + "24" + ], + "Connection": [ + "keep-alive" + ], + "Access-Control-Allow-Credentials": [ + "true" + ], + "Access-Control-Expose-Headers": [ + "*" + ] + }, + "body": { + "pickle": "gASVKAAAAAAAAAB9lIwGc3RyaW5nlIwYeyJzdGF0dXMiOjIwMCwiZGF0YSI6W119lHMu" + } + } + } + ] +} diff --git a/tests/integrational/fixtures/native_sync/objects_v2/memberships/channel_memberships_with_include_object.json b/tests/integrational/fixtures/native_sync/objects_v2/memberships/channel_memberships_with_include_object.json new file mode 100644 index 00000000..97323eb1 --- /dev/null +++ b/tests/integrational/fixtures/native_sync/objects_v2/memberships/channel_memberships_with_include_object.json @@ -0,0 +1,416 @@ +{ + "version": 1, + "interactions": [ + { + "request": { + "method": "PATCH", + "uri": "https://ps.pndsn.com/v2/objects/{PN_KEY_SUBSCRIBE}/uuids/someuuid?include=status%2Ctype", + "body": { + "pickle": "gASVjwAAAAAAAACMi3sibmFtZSI6ICJDb3JuZWxpYSIsICJlbWFpbCI6IG51bGwsICJleHRlcm5hbElkIjogbnVsbCwgInByb2ZpbGVVcmwiOiBudWxsLCAiY3VzdG9tIjogeyJyZW1vdmVkIjogZmFsc2V9LCAic3RhdHVzIjogIm9ubGluZSIsICJ0eXBlIjogIlFBIn2ULg==" + }, + "headers": { + "host": [ + "ps.pndsn.com" + ], + "accept": [ + "*/*" + ], + "accept-encoding": [ + "gzip, deflate" + ], + "connection": [ + "keep-alive" + ], + "user-agent": [ + "PubNub-Python/10.0.0" + ], + "content-type": [ + "application/json" + ], + "content-length": [ + "139" + ] + } + }, + "response": { + "status": { + "code": 200, + "message": "OK" + }, + "headers": { + "Date": [ + "Sat, 18 Jan 2025 20:31:01 GMT" + ], + "Content-Type": [ + "application/json" + ], + "Content-Length": [ + "218" + ], + "Connection": [ + "keep-alive" + ], + "Access-Control-Allow-Credentials": [ + "true" + ], + "Access-Control-Expose-Headers": [ + "*" + ] + }, + "body": { + "pickle": "gASV6gAAAAAAAAB9lIwGc3RyaW5nlIzaeyJzdGF0dXMiOjIwMCwiZGF0YSI6eyJpZCI6InNvbWV1dWlkIiwibmFtZSI6IkNvcm5lbGlhIiwiZXh0ZXJuYWxJZCI6bnVsbCwicHJvZmlsZVVybCI6bnVsbCwiZW1haWwiOm51bGwsInR5cGUiOiJRQSIsInN0YXR1cyI6Im9ubGluZSIsInVwZGF0ZWQiOiIyMDI1LTAxLTE4VDIwOjMxOjAxLjI3OTcwOFoiLCJlVGFnIjoiOGI3NzRmYTFjMGU2ZGYzMzEyNDQzOTI1ZTExMmQ4MWMifX2Ucy4=" + } + } + }, + { + "request": { + "method": "PATCH", + "uri": "https://ps.pndsn.com/v2/objects/{PN_KEY_SUBSCRIBE}/channels/somechannel?include=status%2Ctype", + "body": { + "pickle": "gASViwAAAAAAAACMh3sibmFtZSI6ICJzb21lIG5hbWUiLCAiZGVzY3JpcHRpb24iOiAiVGhpcyBpcyBhIGJpdCBsb25nZXIgdGV4dCIsICJzdGF0dXMiOiAiYWN0aXZlIiwgInR5cGUiOiAiUUFDaGFubmVsIiwgImN1c3RvbSI6IHsicHVibGljIjogZmFsc2V9fZQu" + }, + "headers": { + "host": [ + "ps.pndsn.com" + ], + "accept": [ + "*/*" + ], + "accept-encoding": [ + "gzip, deflate" + ], + "connection": [ + "keep-alive" + ], + "user-agent": [ + "PubNub-Python/10.0.0" + ], + "content-type": [ + "application/json" + ], + "content-length": [ + "135" + ] + } + }, + "response": { + "status": { + "code": 200, + "message": "OK" + }, + "headers": { + "Date": [ + "Sat, 18 Jan 2025 20:31:01 GMT" + ], + "Content-Type": [ + "application/json" + ], + "Content-Length": [ + "222" + ], + "Connection": [ + "keep-alive" + ], + "Access-Control-Allow-Credentials": [ + "true" + ], + "Access-Control-Expose-Headers": [ + "*" + ] + }, + "body": { + "pickle": "gASV7gAAAAAAAAB9lIwGc3RyaW5nlIzeeyJzdGF0dXMiOjIwMCwiZGF0YSI6eyJpZCI6InNvbWVjaGFubmVsIiwibmFtZSI6InNvbWUgbmFtZSIsImRlc2NyaXB0aW9uIjoiVGhpcyBpcyBhIGJpdCBsb25nZXIgdGV4dCIsInR5cGUiOiJRQUNoYW5uZWwiLCJzdGF0dXMiOiJhY3RpdmUiLCJ1cGRhdGVkIjoiMjAyNS0wMS0xNlQyMTo1OTo0NC4yODkzODZaIiwiZVRhZyI6IjcwY2YxMTc3NmFhMDExZWZiMTRmYmU4Zjc3ZDdkMDQwIn19lHMu" + } + } + }, + { + "request": { + "method": "PATCH", + "uri": "https://ps.pndsn.com/v2/objects/{PN_KEY_SUBSCRIBE}/uuids/someuuid/channels?include=custom%2Cstatus%2Ctype%2CtotalCount%2Cchannel%2Cchannel.custom%2Cchannel.type%2Cchannel.status", + "body": { + "pickle": "gASVgwAAAAAAAACMf3sic2V0IjogW3siY2hhbm5lbCI6IHsiaWQiOiAic29tZWNoYW5uZWwifSwgImN1c3RvbSI6IHsiaXNEZWZhdWx0Q2hhbm5lbCI6IHRydWV9LCAic3RhdHVzIjogIk9GRiIsICJ0eXBlIjogIjEifV0sICJkZWxldGUiOiBbXX2ULg==" + }, + "headers": { + "host": [ + "ps.pndsn.com" + ], + "accept": [ + "*/*" + ], + "accept-encoding": [ + "gzip, deflate" + ], + "connection": [ + "keep-alive" + ], + "user-agent": [ + "PubNub-Python/10.0.0" + ], + "content-type": [ + "application/json" + ], + "content-length": [ + "127" + ] + } + }, + "response": { + "status": { + "code": 200, + "message": "OK" + }, + "headers": { + "Date": [ + "Sat, 18 Jan 2025 20:31:01 GMT" + ], + "Content-Type": [ + "application/json" + ], + "Content-Length": [ + "399" + ], + "Connection": [ + "keep-alive" + ], + "Access-Control-Allow-Credentials": [ + "true" + ], + "Access-Control-Expose-Headers": [ + "*" + ] + }, + "body": { + "pickle": "gASVogEAAAAAAAB9lIwGc3RyaW5nlFiPAQAAeyJzdGF0dXMiOjIwMCwiZGF0YSI6W3siY2hhbm5lbCI6eyJpZCI6InNvbWVjaGFubmVsIiwibmFtZSI6InNvbWUgbmFtZSIsImRlc2NyaXB0aW9uIjoiVGhpcyBpcyBhIGJpdCBsb25nZXIgdGV4dCIsInR5cGUiOiJRQUNoYW5uZWwiLCJzdGF0dXMiOiJhY3RpdmUiLCJjdXN0b20iOnsicHVibGljIjpmYWxzZX0sInVwZGF0ZWQiOiIyMDI1LTAxLTE2VDIxOjU5OjQ0LjI4OTM4NloiLCJlVGFnIjoiNzBjZjExNzc2YWEwMTFlZmIxNGZiZThmNzdkN2QwNDAifSwidHlwZSI6IjEiLCJzdGF0dXMiOiJPRkYiLCJjdXN0b20iOnsiaXNEZWZhdWx0Q2hhbm5lbCI6dHJ1ZX0sInVwZGF0ZWQiOiIyMDI1LTAxLTE4VDIwOjMxOjAxLjg5NzE4OFoiLCJlVGFnIjoiQVppdm05blgwb2pmS0EifV0sIm5leHQiOiJNUSJ9lHMu" + } + } + }, + { + "request": { + "method": "GET", + "uri": "https://ps.pndsn.com/v2/objects/{PN_KEY_SUBSCRIBE}/uuids/someuuid/channels?include=custom%2Cstatus%2Ctype%2CtotalCount%2Cchannel%2Cchannel.custom%2Cchannel.type%2Cchannel.status", + "body": "", + "headers": { + "host": [ + "ps.pndsn.com" + ], + "accept": [ + "*/*" + ], + "accept-encoding": [ + "gzip, deflate" + ], + "connection": [ + "keep-alive" + ], + "user-agent": [ + "PubNub-Python/10.0.0" + ] + } + }, + "response": { + "status": { + "code": 200, + "message": "OK" + }, + "headers": { + "Date": [ + "Sat, 18 Jan 2025 20:31:02 GMT" + ], + "Content-Type": [ + "application/json" + ], + "Content-Length": [ + "399" + ], + "Connection": [ + "keep-alive" + ], + "Access-Control-Allow-Credentials": [ + "true" + ], + "Access-Control-Expose-Headers": [ + "*" + ] + }, + "body": { + "pickle": "gASVogEAAAAAAAB9lIwGc3RyaW5nlFiPAQAAeyJzdGF0dXMiOjIwMCwiZGF0YSI6W3siY2hhbm5lbCI6eyJpZCI6InNvbWVjaGFubmVsIiwibmFtZSI6InNvbWUgbmFtZSIsImRlc2NyaXB0aW9uIjoiVGhpcyBpcyBhIGJpdCBsb25nZXIgdGV4dCIsInR5cGUiOiJRQUNoYW5uZWwiLCJzdGF0dXMiOiJhY3RpdmUiLCJjdXN0b20iOnsicHVibGljIjpmYWxzZX0sInVwZGF0ZWQiOiIyMDI1LTAxLTE2VDIxOjU5OjQ0LjI4OTM4NloiLCJlVGFnIjoiNzBjZjExNzc2YWEwMTFlZmIxNGZiZThmNzdkN2QwNDAifSwidHlwZSI6IjEiLCJzdGF0dXMiOiJPRkYiLCJjdXN0b20iOnsiaXNEZWZhdWx0Q2hhbm5lbCI6dHJ1ZX0sInVwZGF0ZWQiOiIyMDI1LTAxLTE4VDIwOjMxOjAxLjg5NzE4OFoiLCJlVGFnIjoiQVppdm05blgwb2pmS0EifV0sIm5leHQiOiJNUSJ9lHMu" + } + } + }, + { + "request": { + "method": "PATCH", + "uri": "https://ps.pndsn.com/v2/objects/{PN_KEY_SUBSCRIBE}/uuids/someuuid/channels", + "body": { + "pickle": "gASVpgAAAAAAAACMonsic2V0IjogW3siY2hhbm5lbCI6IHsiaWQiOiAib3R0ZXJjaGFubmVsIn19XSwgImRlbGV0ZSI6IFt7ImNoYW5uZWwiOiB7ImlkIjogInNvbWVjaGFubmVsIn0sICJjdXN0b20iOiB7ImlzRGVmYXVsdENoYW5uZWwiOiB0cnVlfSwgInN0YXR1cyI6ICJPRkYiLCAidHlwZSI6ICIxIn1dfZQu" + }, + "headers": { + "host": [ + "ps.pndsn.com" + ], + "accept": [ + "*/*" + ], + "accept-encoding": [ + "gzip, deflate" + ], + "connection": [ + "keep-alive" + ], + "user-agent": [ + "PubNub-Python/10.0.0" + ], + "content-type": [ + "application/json" + ], + "content-length": [ + "162" + ] + } + }, + "response": { + "status": { + "code": 200, + "message": "OK" + }, + "headers": { + "Date": [ + "Sat, 18 Jan 2025 20:31:02 GMT" + ], + "Content-Type": [ + "application/json" + ], + "Content-Length": [ + "134" + ], + "Connection": [ + "keep-alive" + ], + "Access-Control-Allow-Credentials": [ + "true" + ], + "Access-Control-Expose-Headers": [ + "*" + ] + }, + "body": { + "pickle": "gASVlgAAAAAAAAB9lIwGc3RyaW5nlIyGeyJzdGF0dXMiOjIwMCwiZGF0YSI6W3siY2hhbm5lbCI6eyJpZCI6Im90dGVyY2hhbm5lbCJ9LCJ1cGRhdGVkIjoiMjAyNS0wMS0xOFQyMDozMTowMi41MTkxOThaIiwiZVRhZyI6IkFmYWgycVMxOTllNzRRRSJ9XSwibmV4dCI6Ik1RIn2Ucy4=" + } + } + }, + { + "request": { + "method": "PATCH", + "uri": "https://ps.pndsn.com/v2/objects/{PN_KEY_SUBSCRIBE}/uuids/someuuid/channels", + "body": { + "pickle": "gASVQAAAAAAAAACMPHsic2V0IjogW10sICJkZWxldGUiOiBbeyJjaGFubmVsIjogeyJpZCI6ICJvdHRlcmNoYW5uZWwifX1dfZQu" + }, + "headers": { + "host": [ + "ps.pndsn.com" + ], + "accept": [ + "*/*" + ], + "accept-encoding": [ + "gzip, deflate" + ], + "connection": [ + "keep-alive" + ], + "user-agent": [ + "PubNub-Python/10.0.0" + ], + "content-type": [ + "application/json" + ], + "content-length": [ + "60" + ] + } + }, + "response": { + "status": { + "code": 200, + "message": "OK" + }, + "headers": { + "Date": [ + "Sat, 18 Jan 2025 20:31:02 GMT" + ], + "Content-Type": [ + "application/json" + ], + "Content-Length": [ + "24" + ], + "Connection": [ + "keep-alive" + ], + "Access-Control-Allow-Credentials": [ + "true" + ], + "Access-Control-Expose-Headers": [ + "*" + ] + }, + "body": { + "pickle": "gASVKAAAAAAAAAB9lIwGc3RyaW5nlIwYeyJzdGF0dXMiOjIwMCwiZGF0YSI6W119lHMu" + } + } + }, + { + "request": { + "method": "GET", + "uri": "https://ps.pndsn.com/v2/objects/{PN_KEY_SUBSCRIBE}/uuids/someuuid/channels?include=custom%2Cstatus%2Ctype%2CtotalCount%2Cchannel%2Cchannel.custom%2Cchannel.type%2Cchannel.status", + "body": "", + "headers": { + "host": [ + "ps.pndsn.com" + ], + "accept": [ + "*/*" + ], + "accept-encoding": [ + "gzip, deflate" + ], + "connection": [ + "keep-alive" + ], + "user-agent": [ + "PubNub-Python/10.0.0" + ] + } + }, + "response": { + "status": { + "code": 200, + "message": "OK" + }, + "headers": { + "Date": [ + "Sat, 18 Jan 2025 20:31:03 GMT" + ], + "Content-Type": [ + "application/json" + ], + "Content-Length": [ + "24" + ], + "Connection": [ + "keep-alive" + ], + "Access-Control-Allow-Credentials": [ + "true" + ], + "Access-Control-Expose-Headers": [ + "*" + ] + }, + "body": { + "pickle": "gASVKAAAAAAAAAB9lIwGc3RyaW5nlIwYeyJzdGF0dXMiOjIwMCwiZGF0YSI6W119lHMu" + } + } + } + ] +} diff --git a/tests/integrational/fixtures/native_sync/objects_v2/memberships/members_include_object.json b/tests/integrational/fixtures/native_sync/objects_v2/memberships/members_include_object.json new file mode 100644 index 00000000..39deb49a --- /dev/null +++ b/tests/integrational/fixtures/native_sync/objects_v2/memberships/members_include_object.json @@ -0,0 +1,416 @@ +{ + "version": 1, + "interactions": [ + { + "request": { + "method": "PATCH", + "uri": "https://ps.pndsn.com/v2/objects/{PN_KEY_SUBSCRIBE}/uuids/someuuid?include=status%2Ctype", + "body": { + "pickle": "gASVjwAAAAAAAACMi3sibmFtZSI6ICJDYXJvbGluZSIsICJlbWFpbCI6IG51bGwsICJleHRlcm5hbElkIjogbnVsbCwgInByb2ZpbGVVcmwiOiBudWxsLCAiY3VzdG9tIjogeyJyZW1vdmVkIjogZmFsc2V9LCAic3RhdHVzIjogIm9ubGluZSIsICJ0eXBlIjogIlFBIn2ULg==" + }, + "headers": { + "host": [ + "ps.pndsn.com" + ], + "accept": [ + "*/*" + ], + "accept-encoding": [ + "gzip, deflate" + ], + "connection": [ + "keep-alive" + ], + "user-agent": [ + "PubNub-Python/10.0.0" + ], + "content-type": [ + "application/json" + ], + "content-length": [ + "139" + ] + } + }, + "response": { + "status": { + "code": 200, + "message": "OK" + }, + "headers": { + "Date": [ + "Fri, 17 Jan 2025 08:38:50 GMT" + ], + "Content-Type": [ + "application/json" + ], + "Content-Length": [ + "218" + ], + "Connection": [ + "keep-alive" + ], + "Access-Control-Allow-Credentials": [ + "true" + ], + "Access-Control-Expose-Headers": [ + "*" + ] + }, + "body": { + "pickle": "gASV6gAAAAAAAAB9lIwGc3RyaW5nlIzaeyJzdGF0dXMiOjIwMCwiZGF0YSI6eyJpZCI6InNvbWV1dWlkIiwibmFtZSI6IkNhcm9saW5lIiwiZXh0ZXJuYWxJZCI6bnVsbCwicHJvZmlsZVVybCI6bnVsbCwiZW1haWwiOm51bGwsInR5cGUiOiJRQSIsInN0YXR1cyI6Im9ubGluZSIsInVwZGF0ZWQiOiIyMDI1LTAxLTE2VDIyOjA5OjAxLjQ4NjkzNFoiLCJlVGFnIjoiNTM1NmQ2ZjU2ZmEzYTQ3Y2JlMjU3ZjcyNmQ0YzMyMmQifX2Ucy4=" + } + } + }, + { + "request": { + "method": "PATCH", + "uri": "https://ps.pndsn.com/v2/objects/{PN_KEY_SUBSCRIBE}/channels/somechannel?include=status%2Ctype", + "body": { + "pickle": "gASViwAAAAAAAACMh3sibmFtZSI6ICJzb21lIG5hbWUiLCAiZGVzY3JpcHRpb24iOiAiVGhpcyBpcyBhIGJpdCBsb25nZXIgdGV4dCIsICJzdGF0dXMiOiAiYWN0aXZlIiwgInR5cGUiOiAiUUFDaGFubmVsIiwgImN1c3RvbSI6IHsicHVibGljIjogZmFsc2V9fZQu" + }, + "headers": { + "host": [ + "ps.pndsn.com" + ], + "accept": [ + "*/*" + ], + "accept-encoding": [ + "gzip, deflate" + ], + "connection": [ + "keep-alive" + ], + "user-agent": [ + "PubNub-Python/10.0.0" + ], + "content-type": [ + "application/json" + ], + "content-length": [ + "135" + ] + } + }, + "response": { + "status": { + "code": 200, + "message": "OK" + }, + "headers": { + "Date": [ + "Fri, 17 Jan 2025 08:38:51 GMT" + ], + "Content-Type": [ + "application/json" + ], + "Content-Length": [ + "222" + ], + "Connection": [ + "keep-alive" + ], + "Access-Control-Allow-Credentials": [ + "true" + ], + "Access-Control-Expose-Headers": [ + "*" + ] + }, + "body": { + "pickle": "gASV7gAAAAAAAAB9lIwGc3RyaW5nlIzeeyJzdGF0dXMiOjIwMCwiZGF0YSI6eyJpZCI6InNvbWVjaGFubmVsIiwibmFtZSI6InNvbWUgbmFtZSIsImRlc2NyaXB0aW9uIjoiVGhpcyBpcyBhIGJpdCBsb25nZXIgdGV4dCIsInR5cGUiOiJRQUNoYW5uZWwiLCJzdGF0dXMiOiJhY3RpdmUiLCJ1cGRhdGVkIjoiMjAyNS0wMS0xNlQyMTo1OTo0NC4yODkzODZaIiwiZVRhZyI6IjcwY2YxMTc3NmFhMDExZWZiMTRmYmU4Zjc3ZDdkMDQwIn19lHMu" + } + } + }, + { + "request": { + "method": "PATCH", + "uri": "https://ps.pndsn.com/v2/objects/{PN_KEY_SUBSCRIBE}/channels/somechannel/uuids?include=custom%2Cstatus%2Ctype%2CtotalCount%2Cuuid%2Cuuid.custom%2Cuuid.type%2Cuuid.status", + "body": { + "pickle": "gASVeQAAAAAAAACMdXsic2V0IjogW3sidXVpZCI6IHsiaWQiOiAic29tZXV1aWQifSwgInR5cGUiOiAiUUEiLCAic3RhdHVzIjogImFjdGl2ZSIsICJjdXN0b20iOiB7ImlzQ3VzdG9tIjogdHJ1ZX19XSwgImRlbGV0ZSI6IFtdfZQu" + }, + "headers": { + "host": [ + "ps.pndsn.com" + ], + "accept": [ + "*/*" + ], + "accept-encoding": [ + "gzip, deflate" + ], + "connection": [ + "keep-alive" + ], + "user-agent": [ + "PubNub-Python/10.0.0" + ], + "content-type": [ + "application/json" + ], + "content-length": [ + "117" + ] + } + }, + "response": { + "status": { + "code": 200, + "message": "OK" + }, + "headers": { + "Date": [ + "Fri, 17 Jan 2025 08:38:51 GMT" + ], + "Content-Type": [ + "application/json" + ], + "Content-Length": [ + "388" + ], + "Connection": [ + "keep-alive" + ], + "Access-Control-Allow-Credentials": [ + "true" + ], + "Access-Control-Expose-Headers": [ + "*" + ] + }, + "body": { + "pickle": "gASVlwEAAAAAAAB9lIwGc3RyaW5nlFiEAQAAeyJzdGF0dXMiOjIwMCwiZGF0YSI6W3sidXVpZCI6eyJpZCI6InNvbWV1dWlkIiwibmFtZSI6IkNhcm9saW5lIiwiZXh0ZXJuYWxJZCI6bnVsbCwicHJvZmlsZVVybCI6bnVsbCwiZW1haWwiOm51bGwsInR5cGUiOiJRQSIsInN0YXR1cyI6Im9ubGluZSIsImN1c3RvbSI6eyJyZW1vdmVkIjpmYWxzZX0sInVwZGF0ZWQiOiIyMDI1LTAxLTE2VDIyOjA5OjAxLjQ4NjkzNFoiLCJlVGFnIjoiNTM1NmQ2ZjU2ZmEzYTQ3Y2JlMjU3ZjcyNmQ0YzMyMmQifSwidHlwZSI6IlFBIiwic3RhdHVzIjoiYWN0aXZlIiwiY3VzdG9tIjp7ImlzQ3VzdG9tIjp0cnVlfSwidXBkYXRlZCI6IjIwMjUtMDEtMTdUMDg6Mzg6NTEuNTM1NDVaIiwiZVRhZyI6IkFjWDN6YTZ0d2NpZ1pBIn1dLCJuZXh0IjoiTVEifZRzLg==" + } + } + }, + { + "request": { + "method": "GET", + "uri": "https://ps.pndsn.com/v2/objects/{PN_KEY_SUBSCRIBE}/channels/somechannel/uuids?include=custom%2Cstatus%2Ctype%2CtotalCount%2Cuuid%2Cuuid.custom%2Cuuid.type%2Cuuid.status", + "body": "", + "headers": { + "host": [ + "ps.pndsn.com" + ], + "accept": [ + "*/*" + ], + "accept-encoding": [ + "gzip, deflate" + ], + "connection": [ + "keep-alive" + ], + "user-agent": [ + "PubNub-Python/10.0.0" + ] + } + }, + "response": { + "status": { + "code": 200, + "message": "OK" + }, + "headers": { + "Date": [ + "Fri, 17 Jan 2025 08:38:51 GMT" + ], + "Content-Type": [ + "application/json" + ], + "Content-Length": [ + "388" + ], + "Connection": [ + "keep-alive" + ], + "Access-Control-Allow-Credentials": [ + "true" + ], + "Access-Control-Expose-Headers": [ + "*" + ] + }, + "body": { + "pickle": "gASVlwEAAAAAAAB9lIwGc3RyaW5nlFiEAQAAeyJzdGF0dXMiOjIwMCwiZGF0YSI6W3sidXVpZCI6eyJpZCI6InNvbWV1dWlkIiwibmFtZSI6IkNhcm9saW5lIiwiZXh0ZXJuYWxJZCI6bnVsbCwicHJvZmlsZVVybCI6bnVsbCwiZW1haWwiOm51bGwsInR5cGUiOiJRQSIsInN0YXR1cyI6Im9ubGluZSIsImN1c3RvbSI6eyJyZW1vdmVkIjpmYWxzZX0sInVwZGF0ZWQiOiIyMDI1LTAxLTE2VDIyOjA5OjAxLjQ4NjkzNFoiLCJlVGFnIjoiNTM1NmQ2ZjU2ZmEzYTQ3Y2JlMjU3ZjcyNmQ0YzMyMmQifSwidHlwZSI6IlFBIiwic3RhdHVzIjoiYWN0aXZlIiwiY3VzdG9tIjp7ImlzQ3VzdG9tIjp0cnVlfSwidXBkYXRlZCI6IjIwMjUtMDEtMTdUMDg6Mzg6NTEuNTM1NDVaIiwiZVRhZyI6IkFjWDN6YTZ0d2NpZ1pBIn1dLCJuZXh0IjoiTVEifZRzLg==" + } + } + }, + { + "request": { + "method": "PATCH", + "uri": "https://ps.pndsn.com/v2/objects/{PN_KEY_SUBSCRIBE}/channels/somechannel/uuids", + "body": { + "pickle": "gASVnAAAAAAAAACMmHsic2V0IjogW3sidXVpZCI6IHsiaWQiOiAic29tZXV1aWRfc2ltcGxlIn19XSwgImRlbGV0ZSI6IFt7InV1aWQiOiB7ImlkIjogInNvbWV1dWlkIn0sICJ0eXBlIjogIlFBIiwgInN0YXR1cyI6ICJhY3RpdmUiLCAiY3VzdG9tIjogeyJpc0N1c3RvbSI6IHRydWV9fV19lC4=" + }, + "headers": { + "host": [ + "ps.pndsn.com" + ], + "accept": [ + "*/*" + ], + "accept-encoding": [ + "gzip, deflate" + ], + "connection": [ + "keep-alive" + ], + "user-agent": [ + "PubNub-Python/10.0.0" + ], + "content-type": [ + "application/json" + ], + "content-length": [ + "152" + ] + } + }, + "response": { + "status": { + "code": 200, + "message": "OK" + }, + "headers": { + "Date": [ + "Fri, 17 Jan 2025 08:38:52 GMT" + ], + "Content-Type": [ + "application/json" + ], + "Content-Length": [ + "134" + ], + "Connection": [ + "keep-alive" + ], + "Access-Control-Allow-Credentials": [ + "true" + ], + "Access-Control-Expose-Headers": [ + "*" + ] + }, + "body": { + "pickle": "gASVlgAAAAAAAAB9lIwGc3RyaW5nlIyGeyJzdGF0dXMiOjIwMCwiZGF0YSI6W3sidXVpZCI6eyJpZCI6InNvbWV1dWlkX3NpbXBsZSJ9LCJ1cGRhdGVkIjoiMjAyNS0wMS0xN1QwODozODo1Mi4xOTQ1MjlaIiwiZVRhZyI6IkFmYWgycVMxOTllNzRRRSJ9XSwibmV4dCI6Ik1RIn2Ucy4=" + } + } + }, + { + "request": { + "method": "PATCH", + "uri": "https://ps.pndsn.com/v2/objects/{PN_KEY_SUBSCRIBE}/channels/somechannel/uuids", + "body": { + "pickle": "gASVQAAAAAAAAACMPHsic2V0IjogW10sICJkZWxldGUiOiBbeyJ1dWlkIjogeyJpZCI6ICJzb21ldXVpZF9zaW1wbGUifX1dfZQu" + }, + "headers": { + "host": [ + "ps.pndsn.com" + ], + "accept": [ + "*/*" + ], + "accept-encoding": [ + "gzip, deflate" + ], + "connection": [ + "keep-alive" + ], + "user-agent": [ + "PubNub-Python/10.0.0" + ], + "content-type": [ + "application/json" + ], + "content-length": [ + "60" + ] + } + }, + "response": { + "status": { + "code": 200, + "message": "OK" + }, + "headers": { + "Date": [ + "Fri, 17 Jan 2025 08:38:52 GMT" + ], + "Content-Type": [ + "application/json" + ], + "Content-Length": [ + "24" + ], + "Connection": [ + "keep-alive" + ], + "Access-Control-Allow-Credentials": [ + "true" + ], + "Access-Control-Expose-Headers": [ + "*" + ] + }, + "body": { + "pickle": "gASVKAAAAAAAAAB9lIwGc3RyaW5nlIwYeyJzdGF0dXMiOjIwMCwiZGF0YSI6W119lHMu" + } + } + }, + { + "request": { + "method": "GET", + "uri": "https://ps.pndsn.com/v2/objects/{PN_KEY_SUBSCRIBE}/channels/somechannel/uuids?include=custom%2Cstatus%2Ctype%2CtotalCount%2Cuuid%2Cuuid.custom%2Cuuid.type%2Cuuid.status", + "body": "", + "headers": { + "host": [ + "ps.pndsn.com" + ], + "accept": [ + "*/*" + ], + "accept-encoding": [ + "gzip, deflate" + ], + "connection": [ + "keep-alive" + ], + "user-agent": [ + "PubNub-Python/10.0.0" + ] + } + }, + "response": { + "status": { + "code": 200, + "message": "OK" + }, + "headers": { + "Date": [ + "Fri, 17 Jan 2025 08:38:52 GMT" + ], + "Content-Type": [ + "application/json" + ], + "Content-Length": [ + "24" + ], + "Connection": [ + "keep-alive" + ], + "Access-Control-Allow-Credentials": [ + "true" + ], + "Access-Control-Expose-Headers": [ + "*" + ] + }, + "body": { + "pickle": "gASVKAAAAAAAAAB9lIwGc3RyaW5nlIwYeyJzdGF0dXMiOjIwMCwiZGF0YSI6W119lHMu" + } + } + } + ] +} diff --git a/tests/integrational/fixtures/native_sync/objects_v2/memberships/setup_module.json b/tests/integrational/fixtures/native_sync/objects_v2/memberships/setup_module.json new file mode 100644 index 00000000..95c112fe --- /dev/null +++ b/tests/integrational/fixtures/native_sync/objects_v2/memberships/setup_module.json @@ -0,0 +1,286 @@ +{ + "version": 1, + "interactions": [ + { + "request": { + "method": "DELETE", + "uri": "https://ps.pndsn.com/v2/objects/{PN_KEY_SUBSCRIBE}/uuids/someuuid", + "body": "", + "headers": { + "host": [ + "ps.pndsn.com" + ], + "accept": [ + "*/*" + ], + "accept-encoding": [ + "gzip, deflate" + ], + "connection": [ + "keep-alive" + ], + "user-agent": [ + "PubNub-Python/10.0.0" + ] + } + }, + "response": { + "status": { + "code": 200, + "message": "OK" + }, + "headers": { + "Date": [ + "Sat, 18 Jan 2025 20:30:59 GMT" + ], + "Content-Type": [ + "application/json" + ], + "Content-Length": [ + "26" + ], + "Connection": [ + "keep-alive" + ], + "Access-Control-Allow-Credentials": [ + "true" + ], + "Access-Control-Expose-Headers": [ + "*" + ] + }, + "body": { + "pickle": "gASVKgAAAAAAAAB9lIwGc3RyaW5nlIwaeyJzdGF0dXMiOjIwMCwiZGF0YSI6bnVsbH2Ucy4=" + } + } + }, + { + "request": { + "method": "DELETE", + "uri": "https://ps.pndsn.com/v2/objects/{PN_KEY_SUBSCRIBE}/uuids/otheruuid", + "body": "", + "headers": { + "host": [ + "ps.pndsn.com" + ], + "accept": [ + "*/*" + ], + "accept-encoding": [ + "gzip, deflate" + ], + "connection": [ + "keep-alive" + ], + "user-agent": [ + "PubNub-Python/10.0.0" + ] + } + }, + "response": { + "status": { + "code": 200, + "message": "OK" + }, + "headers": { + "Date": [ + "Sat, 18 Jan 2025 20:30:59 GMT" + ], + "Content-Type": [ + "application/json" + ], + "Content-Length": [ + "26" + ], + "Connection": [ + "keep-alive" + ], + "Access-Control-Allow-Credentials": [ + "true" + ], + "Access-Control-Expose-Headers": [ + "*" + ] + }, + "body": { + "pickle": "gASVKgAAAAAAAAB9lIwGc3RyaW5nlIwaeyJzdGF0dXMiOjIwMCwiZGF0YSI6bnVsbH2Ucy4=" + } + } + }, + { + "request": { + "method": "DELETE", + "uri": "https://ps.pndsn.com/v2/objects/{PN_KEY_SUBSCRIBE}/channels/somechannelid", + "body": "", + "headers": { + "host": [ + "ps.pndsn.com" + ], + "accept": [ + "*/*" + ], + "accept-encoding": [ + "gzip, deflate" + ], + "connection": [ + "keep-alive" + ], + "user-agent": [ + "PubNub-Python/10.0.0" + ] + } + }, + "response": { + "status": { + "code": 200, + "message": "OK" + }, + "headers": { + "Date": [ + "Sat, 18 Jan 2025 20:30:59 GMT" + ], + "Content-Type": [ + "application/json" + ], + "Content-Length": [ + "26" + ], + "Connection": [ + "keep-alive" + ], + "Access-Control-Allow-Credentials": [ + "true" + ], + "Access-Control-Expose-Headers": [ + "*" + ] + }, + "body": { + "pickle": "gASVKgAAAAAAAAB9lIwGc3RyaW5nlIwaeyJzdGF0dXMiOjIwMCwiZGF0YSI6bnVsbH2Ucy4=" + } + } + }, + { + "request": { + "method": "PATCH", + "uri": "https://ps.pndsn.com/v2/objects/{PN_KEY_SUBSCRIBE}/uuids/someuuid/channels", + "body": { + "pickle": "gASViwAAAAAAAACMh3sic2V0IjogW10sICJkZWxldGUiOiBbeyJjaGFubmVsIjogeyJpZCI6ICJzb21lY2hhbm5lbGlkIn19LCB7ImNoYW5uZWwiOiB7ImlkIjogInNvbWVfY2hhbm5lbCJ9fSwgeyJjaGFubmVsIjogeyJpZCI6ICJvdHRlcmNoYW5uZWwifX1dfZQu" + }, + "headers": { + "host": [ + "ps.pndsn.com" + ], + "accept": [ + "*/*" + ], + "accept-encoding": [ + "gzip, deflate" + ], + "connection": [ + "keep-alive" + ], + "user-agent": [ + "PubNub-Python/10.0.0" + ], + "content-type": [ + "application/json" + ], + "content-length": [ + "135" + ] + } + }, + "response": { + "status": { + "code": 200, + "message": "OK" + }, + "headers": { + "Date": [ + "Sat, 18 Jan 2025 20:30:59 GMT" + ], + "Content-Type": [ + "application/json" + ], + "Content-Length": [ + "24" + ], + "Connection": [ + "keep-alive" + ], + "Access-Control-Allow-Credentials": [ + "true" + ], + "Access-Control-Expose-Headers": [ + "*" + ] + }, + "body": { + "pickle": "gASVKAAAAAAAAAB9lIwGc3RyaW5nlIwYeyJzdGF0dXMiOjIwMCwiZGF0YSI6W119lHMu" + } + } + }, + { + "request": { + "method": "PATCH", + "uri": "https://ps.pndsn.com/v2/objects/{PN_KEY_SUBSCRIBE}/uuids/otheruuid/channels", + "body": { + "pickle": "gASViwAAAAAAAACMh3sic2V0IjogW10sICJkZWxldGUiOiBbeyJjaGFubmVsIjogeyJpZCI6ICJzb21lY2hhbm5lbGlkIn19LCB7ImNoYW5uZWwiOiB7ImlkIjogInNvbWVfY2hhbm5lbCJ9fSwgeyJjaGFubmVsIjogeyJpZCI6ICJvdHRlcmNoYW5uZWwifX1dfZQu" + }, + "headers": { + "host": [ + "ps.pndsn.com" + ], + "accept": [ + "*/*" + ], + "accept-encoding": [ + "gzip, deflate" + ], + "connection": [ + "keep-alive" + ], + "user-agent": [ + "PubNub-Python/10.0.0" + ], + "content-type": [ + "application/json" + ], + "content-length": [ + "135" + ] + } + }, + "response": { + "status": { + "code": 200, + "message": "OK" + }, + "headers": { + "Date": [ + "Sat, 18 Jan 2025 20:31:00 GMT" + ], + "Content-Type": [ + "application/json" + ], + "Content-Length": [ + "24" + ], + "Connection": [ + "keep-alive" + ], + "Access-Control-Allow-Credentials": [ + "true" + ], + "Access-Control-Expose-Headers": [ + "*" + ] + }, + "body": { + "pickle": "gASVKAAAAAAAAAB9lIwGc3RyaW5nlIwYeyJzdGF0dXMiOjIwMCwiZGF0YSI6W119lHMu" + } + } + } + ] +} diff --git a/tests/integrational/native_sync/objects_v2/test_channel_members.py b/tests/integrational/native_sync/objects_v2/test_channel_members.py index 23bc6c87..076dc1cb 100644 --- a/tests/integrational/native_sync/objects_v2/test_channel_members.py +++ b/tests/integrational/native_sync/objects_v2/test_channel_members.py @@ -5,8 +5,9 @@ from pubnub.endpoints.objects_v2.members.remove_channel_members import RemoveChannelMembers from pubnub.endpoints.objects_v2.members.set_channel_members import SetChannelMembers from pubnub.models.consumer.common import PNStatus -from pubnub.models.consumer.objects_v2.channel_members import PNUUID, JustUUID, PNSetChannelMembersResult, \ - PNGetChannelMembersResult, PNRemoveChannelMembersResult, PNManageChannelMembersResult +from pubnub.models.consumer.objects_v2.channel_members import PNUUID, JustUUID, PNGetChannelMembersResult, \ + PNSetChannelMembersResult, PNRemoveChannelMembersResult, PNManageChannelMembersResult, PNUserMember +from pubnub.models.consumer.objects_v2.common import MemberIncludes from pubnub.models.consumer.objects_v2.page import PNPage from pubnub.pubnub import PubNub from pubnub.structures import Envelope @@ -19,8 +20,24 @@ def _pubnub(): return PubNub(config) +@pn_vcr.use_cassette('tests/integrational/fixtures/native_sync/objects_v2/channel_members/setup_module.json', + filter_query_parameters=['uuid', 'pnsdk'], serializer='pn_json') +def setup_module(): + pubnub = _pubnub() + pubnub.remove_uuid_metadata("someuuid").sync() + pubnub.remove_uuid_metadata("otheruuid").sync() + pubnub.remove_channel_metadata("somechannelid").sync() + pubnub.remove_channel_members("somechannelid", [ + PNUserMember("someuuid"), + PNUserMember("otheruuid"), + PNUserMember('someuuid_simple') + ]).sync() + + class TestObjectsV2ChannelMembers: _some_channel_id = "somechannelid" + _some_uuid = 'someuuid' + _other_uuid = 'otheruuid' def test_set_channel_members_endpoint_available(self): pn = _pubnub() @@ -245,3 +262,99 @@ def test_manage_channel_members_happy_path(self): assert len([e for e in data if e['uuid']['id'] == some_uuid]) == 1 assert len([e for e in data if e['uuid']['id'] == some_uuid_with_custom]) == 0 + + @pn_vcr.use_cassette('tests/integrational/fixtures/native_sync/objects_v2/channel_members/' + 'channel_members_with_include_object.json', + filter_query_parameters=['uuid', 'pnsdk'], serializer='pn_json') + def test_channel_members_with_include_object(self): + config = pnconf_env_copy() + pubnub = PubNub(config) + + some_channel = "somechannel" + pubnub.set_uuid_metadata( + uuid=self._some_uuid, + name="Caroline", + type='QA', + status='online', + custom={"removed": False} + ).sync() + + pubnub.set_channel_metadata( + channel=some_channel, + name="some name", + description="This is a bit longer text", + type="QAChannel", + status="active", + custom={"public": False} + ).sync() + + full_include = MemberIncludes( + custom=True, + status=True, + type=True, + total_count=True, + user=True, + user_custom=True, + user_type=True, + user_status=True + ) + + member = PNUserMember( + self._some_uuid, + status="active", + type="QA", + custom={"isCustom": True} + ) + + set_response = pubnub.set_channel_members( + channel=some_channel, + uuids=[member], + include=full_include + ).sync() + + self.assert_expected_response(set_response) + + get_response = pubnub.get_channel_members(channel=some_channel, include=full_include).sync() + + self.assert_expected_response(get_response) + + # the old way to add a simple uuid + replacement = PNUUID.uuid(self._other_uuid) + + manage_response = pubnub.manage_channel_members( + channel=some_channel, + uuids_to_set=[replacement], + uuids_to_remove=[member] + ).sync() + + assert manage_response.status.is_error() is False + assert len(manage_response.result.data) == 1 + assert manage_response.result.data[0]['uuid']['id'] == replacement._uuid + + rem_response = pubnub.remove_channel_members(channel=some_channel, uuids=[replacement]).sync() + + assert rem_response.status.is_error() is False + + get_response = pubnub.get_channel_members(channel=some_channel, include=full_include).sync() + + assert get_response.status.is_error() is False + assert get_response.result.data == [] + + def assert_expected_response(self, response): + assert response is not None + assert response.status.is_error() is False + result = response.result.data + assert result is not None + assert len(result) == 1 + member_data = result[0] + assert member_data['status'] == 'active' + assert member_data['type'] == 'QA' + user_data = result[0]['uuid'] + assert user_data['id'] == self._some_uuid + assert user_data['name'] == 'Caroline' + assert user_data['externalId'] is None + assert user_data['profileUrl'] is None + assert user_data['email'] is None + assert user_data['type'] == 'QA' + assert user_data['status'] == 'online' + assert user_data['custom'] == {'removed': False} diff --git a/tests/integrational/native_sync/objects_v2/test_memberships.py b/tests/integrational/native_sync/objects_v2/test_memberships.py index 54d84839..5afc44be 100644 --- a/tests/integrational/native_sync/objects_v2/test_memberships.py +++ b/tests/integrational/native_sync/objects_v2/test_memberships.py @@ -5,6 +5,7 @@ from pubnub.endpoints.objects_v2.memberships.remove_memberships import RemoveMemberships from pubnub.endpoints.objects_v2.memberships.set_memberships import SetMemberships from pubnub.models.consumer.common import PNStatus +from pubnub.models.consumer.objects_v2.common import MembershipIncludes from pubnub.models.consumer.objects_v2.memberships import PNChannelMembership, PNSetMembershipsResult, \ PNGetMembershipsResult, PNRemoveMembershipsResult, PNManageMembershipsResult from pubnub.pubnub import PubNub @@ -18,8 +19,30 @@ def _pubnub(): return PubNub(config) +@pn_vcr.use_cassette('tests/integrational/fixtures/native_sync/objects_v2/memberships/setup_module.json', + filter_query_parameters=['uuid', 'pnsdk'], serializer='pn_json') +def setup_module(): + pubnub = _pubnub() + pubnub.remove_uuid_metadata("someuuid").sync() + pubnub.remove_uuid_metadata("otheruuid").sync() + pubnub.remove_channel_metadata("somechannelid").sync() + RemoveMemberships(pubnub).uuid("someuuid").channel_memberships([ + PNChannelMembership.channel("somechannelid"), + PNChannelMembership.channel("some_channel"), + PNChannelMembership("otterchannel") + ]).sync() + + RemoveMemberships(pubnub).uuid("otheruuid").channel_memberships([ + PNChannelMembership.channel("somechannelid"), + PNChannelMembership.channel("some_channel"), + PNChannelMembership("otterchannel") + ]).sync() + + class TestObjectsV2Memberships: _some_uuid = "someuuid" + _some_channel = "somechannel" + _other_channel = "otterchannel" # channel about otters, not a typo :D def test_set_memberships_endpoint_available(self): pn = _pubnub() @@ -211,3 +234,97 @@ def test_manage_memberships_happy_path(self): assert len([e for e in data if e['channel']['id'] == some_channel]) == 1 assert len([e for e in data if e['channel']['id'] == some_channel_with_custom]) == 0 + + @pn_vcr.use_cassette('tests/integrational/fixtures/native_sync/objects_v2/memberships/' + 'channel_memberships_with_include_object.json', + filter_query_parameters=['uuid', 'pnsdk'], serializer='pn_json') + def test_channel_memberships_with_include_object(self): + config = pnconf_env_copy() + pubnub = PubNub(config) + self._some_channel = "somechannel" + + pubnub.set_uuid_metadata( + uuid=self._some_uuid, + name="Cornelia", + type='QA', + status='online', + custom={"removed": False} + ).sync() + + pubnub.set_channel_metadata( + channel=self._some_channel, + name="some name", + description="This is a bit longer text", + type="QAChannel", + status="active", + custom={"public": False} + ).sync() + + full_include = MembershipIncludes( + custom=True, + status=True, + type=True, + total_count=True, + channel=True, + channel_custom=True, + channel_type=True, + channel_status=True + ) + + membership = PNChannelMembership(self._some_channel, custom={"isDefaultChannel": True}, status="OFF", type="1") + + set_response = pubnub.set_memberships( + uuid=self._some_uuid, + channel_memberships=[membership], + include=full_include + ).sync() + + self.assert_expected_response(set_response) + + get_response = pubnub.get_memberships( + uuid=self._some_uuid, + include=full_include + ).sync() + self.assert_expected_response(get_response) + + otters = PNChannelMembership(self._other_channel) + + manage_response = pubnub.manage_memberships( + uuid=self._some_uuid, + channel_memberships_to_set=[otters], + channel_memberships_to_remove=[membership] + ).sync() + + assert manage_response.status.is_error() is False + + assert len(manage_response.result.data) == 1 + assert manage_response.result.data[0]['channel']['id'] == self._other_channel + + rem_response = pubnub.remove_memberships(uuid=self._some_uuid, channel_memberships=[otters]).sync() + + assert rem_response.status.is_error() is False + + get_response = pubnub.get_memberships( + uuid=self._some_uuid, + include=full_include + ).sync() + + assert get_response.status.is_error() is False + assert get_response.result.data == [] + + def assert_expected_response(self, response): + assert response is not None + assert response.status.is_error() is False + result = response.result.data + assert result is not None + assert len(result) == 1 + membership_data = result[0] + assert membership_data['status'] == 'OFF' + assert membership_data['type'] == '1' + channel_data = result[0]['channel'] + assert channel_data['id'] == self._some_channel + assert channel_data['description'] == 'This is a bit longer text' + assert channel_data['name'] == 'some name' + assert channel_data['status'] == 'active' + assert channel_data['type'] == 'QAChannel' + assert channel_data['custom'] == {'public': False} diff --git a/tests/pytest.ini b/tests/pytest.ini index 4b96538c..2427aeeb 100644 --- a/tests/pytest.ini +++ b/tests/pytest.ini @@ -3,5 +3,7 @@ filterwarnings = ignore:Mutable config will be deprecated in the future.:DeprecationWarning ignore:Access management v2 is being deprecated.:DeprecationWarning ignore:.*Usage of local cipher_keys is discouraged.*:UserWarning + ignore:The function .* is deprecated. Use.* Include Object instead:DeprecationWarning + ignore:The function .* is deprecated. Use.* PNUserMember class instead:DeprecationWarning asyncio_default_fixture_loop_scope = module \ No newline at end of file