From c8eb41339c608426abc0237dceb9991df2e523ae Mon Sep 17 00:00:00 2001 From: turalf Date: Fri, 19 Feb 2021 16:49:25 -0800 Subject: [PATCH 1/8] Replace identifier with rawId --- .../azure/communication/chat/_shared/models.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sdk/communication/azure-communication-chat/azure/communication/chat/_shared/models.py b/sdk/communication/azure-communication-chat/azure/communication/chat/_shared/models.py index 4aff60e0c4df..d9cc45794a03 100644 --- a/sdk/communication/azure-communication-chat/azure/communication/chat/_shared/models.py +++ b/sdk/communication/azure-communication-chat/azure/communication/chat/_shared/models.py @@ -108,13 +108,13 @@ class UnknownIdentifier(object): Represents an identifier of an unknown type. It will be encountered in communications with endpoints that are not identifiable by this version of the SDK. - :ivar identifier: Unknown communication identifier. - :vartype identifier: str + :ivar rawId: Unknown communication identifier. + :vartype rawId: str :param identifier: Value to initialize UnknownIdentifier. :type identifier: str """ def __init__(self, identifier): - self.identifier = identifier + self.rawId = rawId class _CaseInsensitiveEnumMeta(EnumMeta): def __getitem__(self, name): From 019bdd261b4ae37dc770ec038413d362fa5b2f54 Mon Sep 17 00:00:00 2001 From: turalf Date: Fri, 19 Feb 2021 16:51:29 -0800 Subject: [PATCH 2/8] Change serilizer --- .../communication_identifier_serializer.py | 49 ++++++++++++++----- 1 file changed, 36 insertions(+), 13 deletions(-) diff --git a/sdk/communication/azure-communication-chat/azure/communication/chat/communication_identifier_serializer.py b/sdk/communication/azure-communication-chat/azure/communication/chat/communication_identifier_serializer.py index 972716b833be..9dd07a516274 100644 --- a/sdk/communication/azure-communication-chat/azure/communication/chat/communication_identifier_serializer.py +++ b/sdk/communication/azure-communication-chat/azure/communication/chat/communication_identifier_serializer.py @@ -3,26 +3,30 @@ # Licensed under the MIT License. See License.txt in the project root for # license information. # -------------------------------------------------------------------------- +from enum import Enum -from ._generated.models import ( +from .models import ( CommunicationIdentifierModel, - CommunicationUserIdentifierModel, - PhoneNumberIdentifierModel, - MicrosoftTeamsUserIdentifierModel -) -from ._shared.models import ( CommunicationUserIdentifier, PhoneNumberIdentifier, MicrosoftTeamsUserIdentifier, UnknownIdentifier, + CommunicationUserIdentifierModel, + PhoneNumberIdentifierModel, + MicrosoftTeamsUserIdentifierModel ) +class _IdentifierType(Enum): + COMMUNICATION_USER_IDENTIFIER = "COMMUNICATION_USER_IDENTIFIER" + PHONE_NUMBER_IDENTIFIER = "PHONE_NUMBER_IDENTIFIER" + UNKNOWN_IDENTIFIER = "UNKNOWN_IDENTIFIER" + MICROSOFT_TEAMS_IDENTIFIER = "MICROSOFT_TEAMS_IDENTIFIER" + class CommunicationUserIdentifierSerializer(object): @classmethod def serialize(cls, communicationIdentifier): """ Serialize the Communication identifier into CommunicationIdentifierModel - :param identifier: Identifier object :type identifier: Union[CommunicationUserIdentifier, PhoneNumberIdentifier, MicrosoftTeamsUserIdentifier, UnknownIdentifier] @@ -30,16 +34,18 @@ def serialize(cls, communicationIdentifier): :rtype: ~azure.communication.chat.CommunicationIdentifierModel :raises Union[TypeError, ValueError] """ - if isinstance(communicationIdentifier, CommunicationUserIdentifier): + identifierType = CommunicationUserIdentifierSerializer._getIdnetifierType(communicationIdentifier) + + if identifierType == _IdentifierType.COMMUNICATION_USER_IDENTIFIER: return CommunicationIdentifierModel( communication_user=CommunicationUserIdentifierModel(id=communicationIdentifier.identifier) ) - if isinstance(communicationIdentifier, PhoneNumberIdentifier): + if identifierType == _IdentifierType.PHONE_NUMBER_IDENTIFIER: return CommunicationIdentifierModel( raw_id=communicationIdentifier.raw_id, phone_number=PhoneNumberIdentifierModel(value=communicationIdentifier.phone_number) ) - if isinstance(communicationIdentifier, MicrosoftTeamsUserIdentifier): + if identifierType == _IdentifierType.MICROSOFT_TEAMS_IDENTIFIER: return CommunicationIdentifierModel( raw_id=communicationIdentifier.raw_id, microsoft_teams_user=MicrosoftTeamsUserIdentifierModel(user_id=communicationIdentifier.user_id, @@ -47,9 +53,9 @@ def serialize(cls, communicationIdentifier): cloud=communicationIdentifier.cloud) ) - if isinstance(communicationIdentifier, UnknownIdentifier): + if identifierType == _IdentifierType.UNKNOWN_IDENTIFIER: return CommunicationIdentifierModel( - raw_id=communicationIdentifier.identifier + raw_id=communicationIdentifier.unknownIdentifier ) raise TypeError("Unsupported identifier type " + communicationIdentifier.__class__.__name__) @@ -71,7 +77,6 @@ def assertMaximumOneNestedModel(cls, identifierModel): def deserialize(cls, identifierModel): """ Deserialize the CommunicationIdentifierModel into Communication Identifier - :param identifierModel: CommunicationIdentifierModel :type identifierModel: CommunicationIdentifierModel :return: Union[CommunicationUserIdentifier, CommunicationPhoneNumberIdentifier] @@ -106,3 +111,21 @@ def deserialize(cls, identifierModel): ) return UnknownIdentifier(raw_id) + + @classmethod + def _getIdentifierType(cls, communicationIdentifier): + def has_attributes(obj, attributes): + return all([hasattr(obj, attr) for attr in attributes]) + + if has_attributes(communicationIdentifier, ["identifier"]): + return _IdentifierType.COMMUNICATION_USER_IDENTIFIER + + if has_attributes(communicationIdentifier, ['phone_number', 'raw_id']): + return _IdentifierType.PHONE_NUMBER_IDENTIFIER + + if has_attributes(communicationIdentifier, ["raw_id", "user_id", "is_anonymous", "cloud"]): + return _IdentifierType.MICROSOFT_TEAMS_IDENTIFIER + + if has_attributes(communicationIdentifier, ["unknownIdentifier"]): + return _IdentifierType.UNKNOWN_IDENTIFIER + From 6df8f318383639654e864406fde4cca90a71ba3a Mon Sep 17 00:00:00 2001 From: turalf Date: Fri, 19 Feb 2021 16:55:01 -0800 Subject: [PATCH 3/8] Replace indentifier with rawId in test code --- .../tests/_shared/test_communication_identifier_serializer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/communication/azure-communication-chat/tests/_shared/test_communication_identifier_serializer.py b/sdk/communication/azure-communication-chat/tests/_shared/test_communication_identifier_serializer.py index 64bf4e403851..8b3e67e808db 100644 --- a/sdk/communication/azure-communication-chat/tests/_shared/test_communication_identifier_serializer.py +++ b/sdk/communication/azure-communication-chat/tests/_shared/test_communication_identifier_serializer.py @@ -94,7 +94,7 @@ def test_deserialize_unknown_identifier(self): unknown_identifier_expected = UnknownIdentifier("an id") assert isinstance(unknown_identifier_actual, UnknownIdentifier) - assert unknown_identifier_actual.identifier == unknown_identifier_expected.identifier + assert unknown_identifier_actual.rawId == unknown_identifier_expected.rawId def test_serialize_phone_number(self): phone_number_identifier_model = CommunicationUserIdentifierSerializer.serialize( From 7200c640e5ec1e963d14424f0f326789eab19261 Mon Sep 17 00:00:00 2001 From: turalf Date: Fri, 19 Feb 2021 16:57:57 -0800 Subject: [PATCH 4/8] Sync models across modules --- .../azure/communication/identity/_shared/models.py | 6 +++--- .../azure/communication/phonenumbers/_shared/models.py | 6 +++--- .../azure/communication/sms/_shared/models.py | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/sdk/communication/azure-communication-identity/azure/communication/identity/_shared/models.py b/sdk/communication/azure-communication-identity/azure/communication/identity/_shared/models.py index 83bab3945635..5405a3ecb2b8 100644 --- a/sdk/communication/azure-communication-identity/azure/communication/identity/_shared/models.py +++ b/sdk/communication/azure-communication-identity/azure/communication/identity/_shared/models.py @@ -37,13 +37,13 @@ class UnknownIdentifier(object): Represents an identifier of an unknown type. It will be encountered in communications with endpoints that are not identifiable by this version of the SDK. - :ivar identifier: Unknown communication identifier. - :vartype identifier: str + :ivar rawId: Unknown communication identifier. + :vartype rawId: str :param identifier: Value to initialize UnknownIdentifier. :type identifier: str """ def __init__(self, identifier): - self.identifier = identifier + self.rawId = rawId class _CaseInsensitiveEnumMeta(EnumMeta): def __getitem__(cls, name): diff --git a/sdk/communication/azure-communication-phonenumbers/azure/communication/phonenumbers/_shared/models.py b/sdk/communication/azure-communication-phonenumbers/azure/communication/phonenumbers/_shared/models.py index 83bab3945635..5405a3ecb2b8 100644 --- a/sdk/communication/azure-communication-phonenumbers/azure/communication/phonenumbers/_shared/models.py +++ b/sdk/communication/azure-communication-phonenumbers/azure/communication/phonenumbers/_shared/models.py @@ -37,13 +37,13 @@ class UnknownIdentifier(object): Represents an identifier of an unknown type. It will be encountered in communications with endpoints that are not identifiable by this version of the SDK. - :ivar identifier: Unknown communication identifier. - :vartype identifier: str + :ivar rawId: Unknown communication identifier. + :vartype rawId: str :param identifier: Value to initialize UnknownIdentifier. :type identifier: str """ def __init__(self, identifier): - self.identifier = identifier + self.rawId = rawId class _CaseInsensitiveEnumMeta(EnumMeta): def __getitem__(cls, name): diff --git a/sdk/communication/azure-communication-sms/azure/communication/sms/_shared/models.py b/sdk/communication/azure-communication-sms/azure/communication/sms/_shared/models.py index 2e64b18dc068..8e072c9e2b5f 100644 --- a/sdk/communication/azure-communication-sms/azure/communication/sms/_shared/models.py +++ b/sdk/communication/azure-communication-sms/azure/communication/sms/_shared/models.py @@ -37,13 +37,13 @@ class UnknownIdentifier(object): Represents an identifier of an unknown type. It will be encountered in communications with endpoints that are not identifiable by this version of the SDK. - :ivar identifier: Unknown communication identifier. - :vartype identifier: str + :ivar rawId: Unknown communication identifier. + :vartype rawId: str :param identifier: Value to initialize UnknownIdentifier. :type identifier: str """ def __init__(self, identifier): - self.identifier = identifier + self.rawId = rawId class CommunicationIdentifierModel(msrest.serialization.Model): """Communication Identifier Model. From 82a00c8c0886cd2108f66026ad0c67bfa27a0bf1 Mon Sep 17 00:00:00 2001 From: turalf Date: Fri, 19 Feb 2021 16:58:53 -0800 Subject: [PATCH 5/8] fix typo in serizliser --- .../communication/chat/communication_identifier_serializer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/communication/azure-communication-chat/azure/communication/chat/communication_identifier_serializer.py b/sdk/communication/azure-communication-chat/azure/communication/chat/communication_identifier_serializer.py index 9dd07a516274..ffc12b6603bd 100644 --- a/sdk/communication/azure-communication-chat/azure/communication/chat/communication_identifier_serializer.py +++ b/sdk/communication/azure-communication-chat/azure/communication/chat/communication_identifier_serializer.py @@ -34,7 +34,7 @@ def serialize(cls, communicationIdentifier): :rtype: ~azure.communication.chat.CommunicationIdentifierModel :raises Union[TypeError, ValueError] """ - identifierType = CommunicationUserIdentifierSerializer._getIdnetifierType(communicationIdentifier) + identifierType = CommunicationUserIdentifierSerializer._getIdentifierType(communicationIdentifier) if identifierType == _IdentifierType.COMMUNICATION_USER_IDENTIFIER: return CommunicationIdentifierModel( From e90809ba7e568a9a4a085b7fdbdb9152fb0d025e Mon Sep 17 00:00:00 2001 From: turalf Date: Fri, 19 Feb 2021 17:05:30 -0800 Subject: [PATCH 6/8] Rearrange imports --- .../chat/communication_identifier_serializer.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/sdk/communication/azure-communication-chat/azure/communication/chat/communication_identifier_serializer.py b/sdk/communication/azure-communication-chat/azure/communication/chat/communication_identifier_serializer.py index ffc12b6603bd..8d83d7728e49 100644 --- a/sdk/communication/azure-communication-chat/azure/communication/chat/communication_identifier_serializer.py +++ b/sdk/communication/azure-communication-chat/azure/communication/chat/communication_identifier_serializer.py @@ -5,15 +5,17 @@ # -------------------------------------------------------------------------- from enum import Enum -from .models import ( +from ._generated.models import ( CommunicationIdentifierModel, + CommunicationUserIdentifierModel, + PhoneNumberIdentifierModel, + MicrosoftTeamsUserIdentifierModel +) +from ._shared.models import ( CommunicationUserIdentifier, PhoneNumberIdentifier, MicrosoftTeamsUserIdentifier, UnknownIdentifier, - CommunicationUserIdentifierModel, - PhoneNumberIdentifierModel, - MicrosoftTeamsUserIdentifierModel ) class _IdentifierType(Enum): From 0d409e795d549d2295f63cabbc14f48f6a7de358 Mon Sep 17 00:00:00 2001 From: turalf Date: Fri, 19 Feb 2021 17:11:52 -0800 Subject: [PATCH 7/8] Replace rawId with raw_id --- .../azure/communication/chat/_shared/models.py | 8 ++++---- .../chat/communication_identifier_serializer.py | 4 ++-- .../_shared/test_communication_identifier_serializer.py | 2 +- .../azure/communication/identity/_shared/models.py | 6 +++--- .../azure/communication/phonenumbers/_shared/models.py | 6 +++--- .../azure/communication/sms/_shared/models.py | 6 +++--- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/sdk/communication/azure-communication-chat/azure/communication/chat/_shared/models.py b/sdk/communication/azure-communication-chat/azure/communication/chat/_shared/models.py index d9cc45794a03..30fa9d3327ac 100644 --- a/sdk/communication/azure-communication-chat/azure/communication/chat/_shared/models.py +++ b/sdk/communication/azure-communication-chat/azure/communication/chat/_shared/models.py @@ -108,13 +108,13 @@ class UnknownIdentifier(object): Represents an identifier of an unknown type. It will be encountered in communications with endpoints that are not identifiable by this version of the SDK. - :ivar rawId: Unknown communication identifier. - :vartype rawId: str + :ivar raw_id: Unknown communication identifier. + :vartype raw_id: str :param identifier: Value to initialize UnknownIdentifier. :type identifier: str """ def __init__(self, identifier): - self.rawId = rawId + self.raw_id = identifier class _CaseInsensitiveEnumMeta(EnumMeta): def __getitem__(self, name): @@ -148,7 +148,7 @@ class MicrosoftTeamsUserIdentifier(object): :vartype user_id: str :param user_id: Value to initialize MicrosoftTeamsUserIdentifier. :type user_id: str - :ivar rawId: Raw id of the Microsoft Teams user. + :ivar raw_id: Raw id of the Microsoft Teams user. :vartype raw_id: str :ivar cloud: Cloud environment that this identifier belongs to :vartype cloud: CommunicationCloudEnvironment diff --git a/sdk/communication/azure-communication-chat/azure/communication/chat/communication_identifier_serializer.py b/sdk/communication/azure-communication-chat/azure/communication/chat/communication_identifier_serializer.py index 8d83d7728e49..cdcce3af3694 100644 --- a/sdk/communication/azure-communication-chat/azure/communication/chat/communication_identifier_serializer.py +++ b/sdk/communication/azure-communication-chat/azure/communication/chat/communication_identifier_serializer.py @@ -57,7 +57,7 @@ def serialize(cls, communicationIdentifier): if identifierType == _IdentifierType.UNKNOWN_IDENTIFIER: return CommunicationIdentifierModel( - raw_id=communicationIdentifier.unknownIdentifier + raw_id=communicationIdentifier.raw_id ) raise TypeError("Unsupported identifier type " + communicationIdentifier.__class__.__name__) @@ -128,6 +128,6 @@ def has_attributes(obj, attributes): if has_attributes(communicationIdentifier, ["raw_id", "user_id", "is_anonymous", "cloud"]): return _IdentifierType.MICROSOFT_TEAMS_IDENTIFIER - if has_attributes(communicationIdentifier, ["unknownIdentifier"]): + if has_attributes(communicationIdentifier, ["raw_id"]): return _IdentifierType.UNKNOWN_IDENTIFIER diff --git a/sdk/communication/azure-communication-chat/tests/_shared/test_communication_identifier_serializer.py b/sdk/communication/azure-communication-chat/tests/_shared/test_communication_identifier_serializer.py index 8b3e67e808db..b6888d2f3826 100644 --- a/sdk/communication/azure-communication-chat/tests/_shared/test_communication_identifier_serializer.py +++ b/sdk/communication/azure-communication-chat/tests/_shared/test_communication_identifier_serializer.py @@ -94,7 +94,7 @@ def test_deserialize_unknown_identifier(self): unknown_identifier_expected = UnknownIdentifier("an id") assert isinstance(unknown_identifier_actual, UnknownIdentifier) - assert unknown_identifier_actual.rawId == unknown_identifier_expected.rawId + assert unknown_identifier_actual.raw_id == unknown_identifier_expected.raw_id def test_serialize_phone_number(self): phone_number_identifier_model = CommunicationUserIdentifierSerializer.serialize( diff --git a/sdk/communication/azure-communication-identity/azure/communication/identity/_shared/models.py b/sdk/communication/azure-communication-identity/azure/communication/identity/_shared/models.py index 5405a3ecb2b8..67e0a1ff6e2b 100644 --- a/sdk/communication/azure-communication-identity/azure/communication/identity/_shared/models.py +++ b/sdk/communication/azure-communication-identity/azure/communication/identity/_shared/models.py @@ -37,13 +37,13 @@ class UnknownIdentifier(object): Represents an identifier of an unknown type. It will be encountered in communications with endpoints that are not identifiable by this version of the SDK. - :ivar rawId: Unknown communication identifier. - :vartype rawId: str + :ivar raw_id: Unknown communication identifier. + :vartype raw_id: str :param identifier: Value to initialize UnknownIdentifier. :type identifier: str """ def __init__(self, identifier): - self.rawId = rawId + self.raw_id = identifier class _CaseInsensitiveEnumMeta(EnumMeta): def __getitem__(cls, name): diff --git a/sdk/communication/azure-communication-phonenumbers/azure/communication/phonenumbers/_shared/models.py b/sdk/communication/azure-communication-phonenumbers/azure/communication/phonenumbers/_shared/models.py index 5405a3ecb2b8..67e0a1ff6e2b 100644 --- a/sdk/communication/azure-communication-phonenumbers/azure/communication/phonenumbers/_shared/models.py +++ b/sdk/communication/azure-communication-phonenumbers/azure/communication/phonenumbers/_shared/models.py @@ -37,13 +37,13 @@ class UnknownIdentifier(object): Represents an identifier of an unknown type. It will be encountered in communications with endpoints that are not identifiable by this version of the SDK. - :ivar rawId: Unknown communication identifier. - :vartype rawId: str + :ivar raw_id: Unknown communication identifier. + :vartype raw_id: str :param identifier: Value to initialize UnknownIdentifier. :type identifier: str """ def __init__(self, identifier): - self.rawId = rawId + self.raw_id = identifier class _CaseInsensitiveEnumMeta(EnumMeta): def __getitem__(cls, name): diff --git a/sdk/communication/azure-communication-sms/azure/communication/sms/_shared/models.py b/sdk/communication/azure-communication-sms/azure/communication/sms/_shared/models.py index 8e072c9e2b5f..adb6f909dd23 100644 --- a/sdk/communication/azure-communication-sms/azure/communication/sms/_shared/models.py +++ b/sdk/communication/azure-communication-sms/azure/communication/sms/_shared/models.py @@ -37,13 +37,13 @@ class UnknownIdentifier(object): Represents an identifier of an unknown type. It will be encountered in communications with endpoints that are not identifiable by this version of the SDK. - :ivar rawId: Unknown communication identifier. - :vartype rawId: str + :ivar raw_id: Unknown communication identifier. + :vartype raw_id: str :param identifier: Value to initialize UnknownIdentifier. :type identifier: str """ def __init__(self, identifier): - self.rawId = rawId + self.raw_id = identifier class CommunicationIdentifierModel(msrest.serialization.Model): """Communication Identifier Model. From db65e8e6b01af105f5ade51fce8b9d3627de5b7f Mon Sep 17 00:00:00 2001 From: turalf Date: Fri, 19 Feb 2021 17:37:37 -0800 Subject: [PATCH 8/8] remove trailing newline --- .../communication/chat/communication_identifier_serializer.py | 1 - 1 file changed, 1 deletion(-) diff --git a/sdk/communication/azure-communication-chat/azure/communication/chat/communication_identifier_serializer.py b/sdk/communication/azure-communication-chat/azure/communication/chat/communication_identifier_serializer.py index cdcce3af3694..13e540c7a67c 100644 --- a/sdk/communication/azure-communication-chat/azure/communication/chat/communication_identifier_serializer.py +++ b/sdk/communication/azure-communication-chat/azure/communication/chat/communication_identifier_serializer.py @@ -130,4 +130,3 @@ def has_attributes(obj, attributes): if has_attributes(communicationIdentifier, ["raw_id"]): return _IdentifierType.UNKNOWN_IDENTIFIER -