8000 pylint fixes for connector code and tests (#271) · sherlock666/botbuilder-python@9546e07 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9546e07

Browse files
authored
pylint fixes for connector code and tests (microsoft#271)
1 parent a25be28 commit 9546e07

25 files changed

+130
-94
lines changed

.pylintrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,8 @@ disable=print-statement,
154154
too-many-public-methods,
155155
cyclic-import,
156156
too-many-locals,
157-
too-many-function-args
157+
too-many-function-args,
158+
too-many-return-statements
158159

159160
# Enable the message, report, category or checker with the given id(s). You can
160161
# either give multiple identifier separated by comma (,) or put this option

libraries/botframework-connector/botframework/connector/aio/_connector_client_async.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
from msrest import Serializer, Deserializer
1414

1515
from .._configuration import ConnectorClientConfiguration
16-
from msrest.exceptions import HttpOperationError
1716
from .operations_async import AttachmentsOperations
1817
from .operations_async import ConversationsOperations
1918
from .. import models
@@ -24,14 +23,16 @@ class ConnectorClient(SDKClientAsync):
2423
[Bot Framework Developer Portal](https://dev.botframework.com). The Connector service uses industry-standard REST
2524
and JSON over HTTPS.
2625
Client libraries for this REST API are available. See below for a list.
27-
Many bots will use both the Bot Connector REST API and the associated [Bot State REST API](/en-us/restapi/state). The
28-
Bot State REST API allows a bot to store and retrieve state associated with users and conversations.
26+
Many bots will use both the Bot Connector REST API and the associated [Bot State REST API](/en-us/restapi/state).
27+
The Bot State REST API allows a bot to store and retrieve state associated with users and conversations.
2928
Authentication for both the Bot Connector and Bot State REST APIs is accomplished with JWT Bearer tokens, and is
3029
described in detail in the [Connector Authentication](/en-us/restapi/authentication) document.
3130
# Client Libraries for the Bot Connector REST API
3231
* [Bot Builder for C#](/en-us/csharp/builder/sdkreference/)
3332
* [Bot Builder for Node.js](/en-us/node/builder/overview/)
34-
* Generate your own from the [Connector API Swagger file](https://raw.githubusercontent.com/Microsoft/BotBuilder/master/CSharp/Library/Microsoft.Bot.Connector.Shared/Swagger/ConnectorAPI.json)
33+
* Generate your own from the
34+
[Connector API Swagger file](https://raw.githubusercontent.com/Microsoft/BotBuilder/master/CSharp/Library/
35+
Microsoft.Bot.Connector.Shared/Swagger/ConnectorAPI.json)
3536
© 2016 Microsoft
3637
3738
:ivar config: Configuration for client.

libraries/botframework-connector/botframework/connector/aio/operations_async/_attachments_operations_async.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
class AttachmentsOperations:
1818
"""AttachmentsOperations async operations.
1919
20-
You should not instantiate directly this class, but create a Client instance that will create it for you and attach it as attribute.
20+
You should not instantiate directly this class, but create a Client instance that will create it for you and attach
21+
it as attribute.
2122
2223
:param client: Client for service requests.
2324
:param config: Configuration of service client.

libraries/botframework-connector/botframework/connector/aio/operations_async/_conversations_operations_async.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
class ConversationsOperations:
1919
"""ConversationsOperations async operations.
2020
21-
You should not instantiate directly this class, but create a Client instance that will create it for you and attach it as attribute.
21+
You should not instantiate directly this class, but create a Client instance that will create it for you and attach
22+
it as attribute.
2223
2324
:param client: Client for service requests.
2425
:param config: Configuration of service client.

libraries/botframework-connector/botframework/connector/auth/endorsements_validator.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
14
from typing import List
25

36

@@ -9,7 +12,7 @@ def validate(channel_id: str, endorsements: List[str]):
912
if not channel_id:
1013
return True
1114

12-
if endorsements == None:
15+
if endorsements is None:
1316
raise ValueError("Argument endorsements is null.")
1417

1518
# The Call path to get here is:
@@ -28,5 +31,5 @@ def validate(channel_id: str, endorsements: List[str]):
2831
# of scope, tokens from WebChat have about 10 endorsements, and
2932
# tokens coming from Teams have about 20.
3033

31-
endorsementPresent = channel_id in endorsements
32-
return endorsementPresent
34+
endorsement_present = channel_id in endorsements
35+
return endorsement_present

libraries/botframework-connector/botframework/connector/auth/government_constants.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ class GovernmentConstants(ABC):
1414
"""
1515
TO CHANNEL FROM BOT: Login URL
1616
"""
17-
TO_CHANNEL_FROM_BOT_LOGIN_URL = "https://login.microsoftonline.us/cab8a31a-1906-4287-a0d8-4eef66b95f6e/oauth2/v2.0/token"
17+
TO_CHANNEL_FROM_BOT_LOGIN_URL = \
18+
"https://login.microsoftonline.us/cab8a31a-1906-4287-a0d8-4eef66b95f6e/oauth2/v2.0/token"
1819

1920
"""
2021
TO CHANNEL FROM BOT: OAuth scope to request
@@ -36,4 +37,5 @@ class GovernmentConstants(ABC):
3637
"""
3738
TO BOT FROM GOV EMULATOR: OpenID metadata document for tokens coming from MSA
3839
"""
39-
TO_BOT_FROM_EMULATOR_OPEN_ID_METADATA_URL = "https://login.microsoftonline.us/cab8a31a-1906-4287-a0d8-4eef66b95f6e/v2.0/.well-known/openid-configuration"
40+
TO_BOT_FROM_EMULATOR_OPEN_ID_METADATA_URL = \
41+
"https://login.microsoftonline.us/cab8a31a-1906-4287-a0d8-4eef66b95f6e/v2.0/.well-known/openid-configuration"

libraries/botframework-connector/botframework/connector/auth/jwt_token_extractor.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import asyncio
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
24
import json
35
from datetime import datetime, timedelta
46
import requests

libraries/botframework-connector/botframework/connector/auth/jwt_token_validation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ async def authenticate_request(
1919
channel_service: str = "",
2020
) -> ClaimsIdentity:
2121
"""Authenticates the request and sets the service url in the set of trusted urls.
22-
2322
:param activity: The incoming Activity from the Bot Framework or the Emulator
2423
:type activity: ~botframework.connector.models.Activity
2524
:param auth_header: The Bearer token included as part of the request
2625
:type auth_header: str
2726
:param credentials: The set of valid credentials, such as the Bot Application ID
27+
:param channel_service: String for the channel service
2828
:type credentials: CredentialProvider
2929
3030
:raises Exception:

libraries/botframework-connector/botframework/connector/auth/microsoft_app_credentials.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from urllib.parse import urlparse
33
from msrest.authentication import BasicTokenAuthentication, Authentication
44
import requests
5-
import aiohttp
65
from .constants import Constants
76

87
# TODO: Decide to move this to Constants or viceversa (when porting OAuth)
@@ -11,7 +10,8 @@
1110
"refreshScope": "https://api.botframework.com/.default",
1211
"botConnectorOpenIdMetadata": "https://login.botframework.com/v1/.well-known/openidconfiguration",
1312
"botConnectorIssuer": "https://api.botframework.com",
14-
"emulatorOpenIdMetadata": "https://login.microsoftonline.com/botframework.com/v2.0/.well-known/openid-configuration",
13+
"emulatorOpenIdMetadata":
14+
"https://login.microsoftonline.com/botframework.com/v2.0/.well-known/openid-configuration",
1515
"emulatorAuthV31IssuerV1": "https://sts.windows.net/d6d49420-f39b-4df7-a1dc-d59a935871db/",
1616
"emulatorAuthV31IssuerV2": "https://login.microsoftonline.com/d6d49420-f39b-4df7-a1dc-d59a935871db/v2.0",
1717
"emulatorAuthV32IssuerV1": "https://sts.windows.net/f8cdef31-a31e-4b4a-93e4-5f571e91255a/",
@@ -63,7 +63,7 @@ def __init__(self, app_id: str, password: str, channel_auth_tenant: str = None):
6363
self.microsoft_app_password = password
6464
tenant = (
6565
channel_auth_tenant
66-
if channel_auth_tenant is not None and len(channel_auth_tenant) > 0
66+
if channel_auth_tenant
6767
else Constants.DEFAULT_CHANNEL_AUTH_TENANT
6868
)
6969
self.oauth_endpoint = (
@@ -73,7 +73,7 @@ def __init__(self, app_id: str, password: str, channel_auth_tenant: str = None):
7373
)
7474
self.token_cache_key = app_id + "-cache"
7575

76-
def signed_session(self) -> requests.Session:
76+
def signed_session(self) -> requests.Session: # pylint: disable=arguments-differ
7777
"""
7878
Gets the signed session.
7979
:returns: Signed requests.Session object
@@ -113,8 +113,7 @@ def get_access_token(self, force_refresh: bool = False) -> str:
113113
oauth_token = self.refresh_token()
114114
MicrosoftAppCredentials.cache.setdefault(self.token_cache_key, oauth_token)
115115
return oauth_token.access_token
116-
else:
117-
return ""
116+
return ""
118117

119118
def refresh_token(self) -> _OAuthResponse:
120119
"""

libraries/botframework-connector/botframework/connector/connector_client.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
from msrest import Serializer, Deserializer
1414

1515
from ._configuration import ConnectorClientConfiguration
16-
from msrest.exceptions import HttpOperationError
1716
from .operations import AttachmentsOperations
1817
from .operations import ConversationsOperations
1918
from . import models
@@ -24,14 +23,16 @@ class ConnectorClient(SDKClient):
2423
[Bot Framework Developer Portal](https://dev.botframework.com). The Connector service uses industry-standard REST
2524
and JSON over HTTPS.
2625
Client libraries for this REST API are available. See below for a list.
27-
Many bots will use both the Bot Connector REST API and the associated [Bot State REST API](/en-us/restapi/state). The
28-
Bot State REST API allows a bot to store and retrieve state associated with users and conversations.
26+
Many bots will use both the Bot Connector REST API and the associated [Bot State REST API](/en-us/restapi/state).
27+
The Bot State REST API allows a bot to store and retrieve state associated with users and conversations.
2928
Authentication for both the Bot Connector and Bot State REST APIs is accomplished with JWT Bearer tokens, and is
3029
described in detail in the [Connector Authentication](/en-us/restapi/authentication) document.
3130
# Client Libraries for the Bot Connector REST API
3231
* [Bot Builder for C#](/en-us/csharp/builder/sdkreference/)
3332
* [Bot Builder for Node.js](/en-us/node/builder/overview/)
34-
* Generate your own from the [Connector API Swagger file](https://raw.githubusercontent.com/Microsoft/BotBuilder/master/CSharp/Library/Microsoft.Bot.Connector.Shared/Swagger/ConnectorAPI.json)
33+
* Generate your own from the
34+
[Connector API Swagger file](https://raw.githubusercontent.com/Microsoft/BotBuilder/master/CSharp/Library
35+
/Microsoft.Bot.Connector.Shared/Swagger/ConnectorAPI.json)
3536
© 2016 Microsoft
3637
3738
:ivar config: Configuration for client.

libraries/botframework-connector/botframework/connector/emulator_api_client.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ async def emulate_oauth_cards(
2121

2222
if res.status_code == 200:
2323
return True
24-
else:
25-
raise Exception(
26-
f"EmulateOAuthCards failed with status code: { res.status_code }"
27-
)
24+
25+
raise Exception(
26+
f"EmulateOAuthCards failed with status code: { res.status_code }"
27+
)

libraries/botframework-connector/botframework/connector/operations/_attachments_operations.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@
1414
from .. import models
1515

1616

17-
class AttachmentsOperations(object):
17+
class AttachmentsOperations:
1818
"""AttachmentsOperations operations.
1919
20-
You should not instantiate directly this class, but create a Client instance that will create it for you and attach it as attribute.
20+
You should not instantiate directly this class, but create a Client instance that will create it for you and attach
21+
it as attribute.
2122
2223
:param client: Client for service requests.
2324
:param config: Configuration of service client.

libraries/botframework-connector/botframework/connector/operations/_conversations_operations.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@
1515
from .. import models
1616

1717

18-
class ConversationsOperations(object):
18+
class ConversationsOperations:
1919
"""ConversationsOperations operations.
2020
21-
You should not instantiate directly this class, but create a Client instance that will create it for you and attach it as attribute.
21+
You should not instantiate directly this class, but create a Client instance that will create it for you and attach
22+
it as attribute.
2223
2324
:param client: Client for service requests.
2425
:param config: Configuration of service client.
@@ -532,7 +533,7 @@ def reply_to_activity(
532533
"url": "/v3/conversations/{conversationId}/activities/{activityId}"
533534
}
534535

535-
def delete_activity(
536+
def delete_activity( # pylint: disable=inconsistent-return-statements
536537
self,
537538
conversation_id,
538539
activity_id,
@@ -744,7 +745,7 @@ def get_conversation_paged_members(
744745
"url": "/v3/conversations/{conversationId}/pagedmembers"
745746
}
746747

747-
def delete_conversation_member(
748+
def delete_conversation_member( # pylint: disable=inconsistent-return-statements
748749
self,
749750
conversation_id,
750751
member_id,

libraries/botframework-connector/botframework/connector/token_api/_token_api_client.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
from msrest import Serializer, Deserializer
1414

1515
from ._configuration import TokenApiClientConfiguration
16-
from msrest.exceptions import HttpOperationError
1716
from .operations import BotSignInOperations
1817
from .operations import UserTokenOperations
1918
from . import models

libraries/botframework-connector/botframework/connector/token_api/aio/_token_api_client_async.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
from msrest import Serializer, Deserializer
1414

1515
from .._configuration import TokenApiClientConfiguration
16-
from msrest.exceptions import HttpOperationError
1716
from .operations_async import BotSignInOperations
1817
from .operations_async import UserTokenOperations
1918
from .. import models

libraries/botframework-connector/botframework/connector/token_api/aio/operations_async/_bot_sign_in_operations_async.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
class BotSignInOperations:
1919
"""BotSignInOperations async operations.
2020
21-
You should not instantiate directly this class, but create a Client instance that will create it for you and attach it as attribute.
21+
You should not instantiate directly this class, but create a Client instance that will create it for you and attach
22+
it as attribute.
2223
2324
:param client: Client for service requests.
2425
:param config: Configuration of service client.

libraries/botframework-connector/botframework/connector/token_api/aio/operations_async/_user_token_operations_async.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
class UserTokenOperations:
1818
"""UserTokenOperations async operations.
1919
20-
You should not instantiate directly this class, but create a Client instance that will create it for you and attach it as attribute.
20+
You should not instantiate directly this class, but create a Client instance that will create it for you and attach
21+
it as attribute.
2122
2223
:param client: Client for service requests.
2324
:param config: Configuration of service client.

libraries/botframework-connector/botframework/connector/token_api/operations/_bot_sign_in_operations.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@
1515
from .. import models
1616

1717

18-
class BotSignInOperations(object):
18+
class BotSignInOperations:
1919
"""BotSignInOperations operations.
2020
21-
You should not instantiate directly this class, but create a Client instance that will create it for you and attach it as attribute.
21+
You should not instantiate directly this class, but create a Client instance that will create it for you and attach
22+
it as attribute.
2223
2324
:param client: Client for service requests.
2425
:param config: Configuration of service client.

libraries/botframework-connector/botframework/connector/token_api/operations/_user_token_operations.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@
1414
from .. import models
1515

1616

17-
class UserTokenOperations(object):
17+
class UserTokenOperations:
1818
"""UserTokenOperations operations.
1919
20-
You should not instantiate directly this class, but create a Client instance that will create it for you and attach it as attribute.
20+
You should not instantiate directly this class, but create a Client instance that will create it for you and attach
21+
it as attribute.
2122
2223
:param client: Client for service requests.
2324
:param config: Configuration of service client.
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
14
from msrest.authentication import BasicTokenAuthentication, Authentication
25

36

47
class MicrosoftTokenAuthenticationStub(Authentication):
58
def __init__(self, access_token):
69
self.access_token = access_token
710

8-
def signed_session(self):
9-
basicAuthentication = BasicTokenAuthentication(
11+
def signed_session(self, session=None):
12+
basic_authentication = BasicTokenAuthentication(
1013
{"access_token": self.access_token}
1114
)
12-
return basicAuthentication.signed_session()
15+
return session or basic_authentication.signed_session()

libraries/botframework-connector/tests/test_attachments.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
14
import os
25
import base64
3-
import pytest
46
import asyncio
7+
import pytest
58
from azure_devtools.scenario_tests import ReplayableTest
69

710
import msrest
8-
from botbuilder.schema import *
11+
from botbuilder.schema import AttachmentData, ErrorResponseException
912
from botframework.connector import ConnectorClient
1013
from botframework.connector.auth import MicrosoftAppCredentials
1114

@@ -43,8 +46,8 @@ def read_base64(path_to_file):
4346
return encoded_string
4447

4548

46-
loop = asyncio.get_event_loop()
47-
auth_token = loop.run_until_complete(get_auth_token())
49+
LOOP = asyncio.get_event_loop()
50+
AUTH_TOKEN = LOOP.run_until_complete(get_auth_token())
4851

4952

5053
class AttachmentsTest(ReplayableTest):
@@ -53,7 +56,7 @@ def __init__(self, method_name):
5356

5457
@property
5558
def credentials(self):
56-
return MicrosoftTokenAuthenticationStub(auth_token)
59+
return MicrosoftTokenAuthenticationStub(AUTH_TOKEN)
5760

5861
def test_attachments_upload_and_get_attachment(self):
5962
attachment = AttachmentData(
@@ -124,7 +127,7 @@ def test_attachments_get_attachment_view_with_invalid_view_id_fails(self):
124127
CONVERSATION_ID, attachment
125128
)
126129
attachment_id = response.id
127-
attachment_view = connector.attachments.get_attachment(
130+
connector.attachments.get_attachment(
128131
attachment_id, "invalid"
129132
)
130133

0 commit comments

Comments
 (0)
0