forked from slackapi/python-slack-sdk
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add aiohttp version validation (ref slackapi#912)
- Loading branch information
Showing
4 changed files
with
72 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import logging | ||
from typing import Callable | ||
|
||
|
||
def _print_warning_log(message: str) -> None: | ||
logging.getLogger(__name__).warning(message) | ||
|
||
|
||
def validate_aiohttp_version( | ||
aiohttp_version: str, print_warning: Callable[[str], None] = _print_warning_log, | ||
): | ||
if aiohttp_version is not None: | ||
elements = aiohttp_version.split(".") | ||
if len(elements) >= 3: | ||
# patch version can be a non-numeric value | ||
major, minor, patch = int(elements[0]), int(elements[1]), elements[2] | ||
if major <= 2 or ( | ||
major == 3 and (minor == 6 or (minor == 7 and patch == "0")) | ||
): | ||
print_warning( | ||
"We highly recommend upgrading aiohttp to 3.7.3 or higher versions." | ||
"An older version of the library may not work with the Slack server-side in the future." | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import logging | ||
import unittest | ||
|
||
from slack_sdk.aiohttp_version_checker import validate_aiohttp_version | ||
|
||
|
||
class TestAiohttpVersionChecker(unittest.TestCase): | ||
def setUp(self): | ||
self.logger = logging.getLogger(__name__) | ||
|
||
def tearDown(self): | ||
pass | ||
|
||
def test_not_recommended_versions(self): | ||
state = {"counter": 0} | ||
|
||
def print(message: str): | ||
state["counter"] = state["counter"] + 1 | ||
|
||
validate_aiohttp_version("2.1.3", print) | ||
self.assertEqual(state["counter"], 1) | ||
validate_aiohttp_version("3.6.3", print) | ||
self.assertEqual(state["counter"], 2) | ||
validate_aiohttp_version("3.7.0", print) | ||
self.assertEqual(state["counter"], 3) | ||
|
||
def test_recommended_versions(self): | ||
state = {"counter": 0} | ||
|
||
def print(message: str): | ||
state["counter"] = state["counter"] + 1 | ||
|
||
validate_aiohttp_version("3.7.1", print) | ||
self.assertEqual(state["counter"], 0) | ||
validate_aiohttp_version("3.7.3", print) | ||
self.assertEqual(state["counter"], 0) | ||
validate_aiohttp_version("3.8.0", print) | ||
self.assertEqual(state["counter"], 0) | ||
validate_aiohttp_version("4.0.0", print) | ||
self.assertEqual(state["counter"], 0) | ||
validate_aiohttp_version("4.0.0rc1", print) | ||
self.assertEqual(state["counter"], 0) |