Skip to content

Commit

Permalink
remove code to support python versions < 3.8
Browse files Browse the repository at this point in the history
  • Loading branch information
mishaschwartz committed Apr 26, 2024
1 parent c8385c9 commit bd2da76
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 59 deletions.
16 changes: 0 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -539,14 +539,6 @@ check-security-only: check-security-code-only check-security-deps-only ## run s
# ignored codes:
# 42194: https://github.com/kvesteri/sqlalchemy-utils/issues/166 # not fixed since 2015
# 51668: https://github.com/sqlalchemy/sqlalchemy/pull/8563 # still in beta + major version change sqlalchemy 2.0.0b1
# 51021: This is patched in jwcrypto>=1.4.0 but that version is not available for python version < 3.6
# 66713: This is patched in jwcrypto>=1.5.1 but that version is not available for python version < 3.6
# 63154: This is patched in jwcrypto>=1.5.1 but that version is not available for python version < 3.6
# 64484: This is patched in bandit>=1.7.8 but that version is not available for python version < 3.8
# 43407: This is an advisory that support for python < 3.6 is no longer supported in the next version
# 43452: This is a duplicate of 43407
# 43450: This is a duplicate of 43407
# 43451: This is a duplicate of 43407
.PHONY: check-security-deps-only
check-security-deps-only: mkdir-reports ## run security checks on package dependencies
@echo "Running security checks of dependencies..."
Expand All @@ -559,14 +551,6 @@ check-security-deps-only: mkdir-reports ## run security checks on package depen
-r "$(APP_ROOT)/requirements-sys.txt" \
-i 42194 \
-i 51668 \
-i 51021 \
-i 66713 \
-i 63154 \
-i 64484 \
-i 43407 \
-i 43452 \
-i 43450 \
-i 43451 \
1> >(tee "$(REPORTS_DIR)/check-security-deps.txt")'

.PHONY: check-security-code-only
Expand Down
10 changes: 0 additions & 10 deletions magpie/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,21 +256,11 @@ def protected_group_name_regex(include_admin=True,
return re.compile("^({})$".format("|".join(patterns)))


def network_mode_supported():
# type: () -> bool
"""
Return whether the current python version supports network mode.
"""
return (sys.version_info.major, sys.version_info.minor) > (3, 5)


def network_enabled(settings_container=None):
# type: (Optional[AnySettingsContainer]) -> bool
"""
Return whether network mode is enabled.
"""
if not network_mode_supported():
return False
return asbool(get_constant("MAGPIE_NETWORK_ENABLED", settings_container=settings_container))


Expand Down
54 changes: 23 additions & 31 deletions tests/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from magpie import __meta__
from magpie.api import schemas as s
from magpie.api.webhooks import webhook_update_error_status
from magpie.constants import MAGPIE_ROOT, get_constant, network_mode_supported
from magpie.constants import MAGPIE_ROOT, get_constant
from magpie.models import RESOURCE_TYPE_DICT, Directory, File, Layer, Process, Route, Service, UserStatuses, Workspace
from magpie.permissions import (
PERMISSION_REASON_DEFAULT,
Expand Down Expand Up @@ -205,28 +205,27 @@ def cleanup(cls):
for res in list(cls.extra_resource_ids): # copy to update removed ones
utils.TestSetup.delete_TestResource(cls, res)
cls.extra_resource_ids.discard(res)
if network_mode_supported(): # This check is required when the python version is < 3.6
for node in list(cls.extra_node_names):
check_network_mode(utils.TestSetup.delete_TestNetworkNode,
enable=True)(cls, override_name=node, allow_missing=True)
cls.extra_node_names.discard(node)
for remote_user_name, node_name in list(cls.extra_network_tokens):
check_network_mode(utils.TestSetup.delete_TestNetworkToken,
enable=True)(cls,
override_remote_user_name=remote_user_name,
override_node_name=node_name,
allow_missing=True) # should already be deleted with associated models
cls.extra_network_tokens.discard((remote_user_name, node_name))
for remote_user_name, node_name in list(cls.extra_remote_user_names):
check_network_mode(utils.TestSetup.delete_TestNetworkRemoteUser,
enable=True)(cls, override_remote_user_name=remote_user_name,
override_node_name=node_name,
allow_missing=True) # should already be deleted with associated models
cls.extra_remote_user_names.discard((remote_user_name, node_name))
for host_port, server in list(cls.extra_remote_servers.items()):
if server.is_running():
server.stop()
cls.extra_remote_servers.pop(host_port)
for node in list(cls.extra_node_names):
check_network_mode(utils.TestSetup.delete_TestNetworkNode,
enable=True)(cls, override_name=node, allow_missing=True)
cls.extra_node_names.discard(node)
for remote_user_name, node_name in list(cls.extra_network_tokens):
check_network_mode(utils.TestSetup.delete_TestNetworkToken,
enable=True)(cls,
override_remote_user_name=remote_user_name,
override_node_name=node_name,
allow_missing=True) # should already be deleted with associated models
cls.extra_network_tokens.discard((remote_user_name, node_name))
for remote_user_name, node_name in list(cls.extra_remote_user_names):
check_network_mode(utils.TestSetup.delete_TestNetworkRemoteUser,
enable=True)(cls, override_remote_user_name=remote_user_name,
override_node_name=node_name,
allow_missing=True) # should already be deleted with associated models
cls.extra_remote_user_names.discard((remote_user_name, node_name))
for host_port, server in list(cls.extra_remote_servers.items()):
if server.is_running():
server.stop()
cls.extra_remote_servers.pop(host_port)

@property
def update_method(self):
Expand Down Expand Up @@ -1341,14 +1340,7 @@ def test_PostNetworkToken_InvalidNodeCredentials(self):
token = utils.TestSetup.create_TestNetworkToken(self, expect_errors=True)
utils.check_val_equal(token.get("token"), None)
utils.check_val_equal(token.get("code"), 500)
# python version < 3.7 uses pyjwt version < 2.5.0
# pyjwt 2.5.0 changed the error type from HTTPError to PyJWKClientConnectionError if a valid JWKS could not
# be found at the given uri.
if (sys.version_info.major, sys.version_info.minor) < (3, 7):
error_type = "HTTPError"
else:
error_type = "PyJWKClientConnectionError"
utils.check_val_equal(token.get("call", {}).get("exception"), error_type)
utils.check_val_equal(token.get("call", {}).get("exception"), "PyJWKClientConnectionError")

@runner.MAGPIE_TEST_NETWORK
@utils.check_network_mode
Expand Down
4 changes: 2 additions & 2 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
from magpie import __meta__, app, services
from magpie.api import schemas
from magpie.compat import LooseVersion
from magpie.constants import get_constant, network_mode_supported
from magpie.constants import get_constant
from magpie.permissions import Access, PermissionSet, Scope
from magpie.services import SERVICE_TYPE_DICT, ServiceAccess
from magpie.utils import (
Expand Down Expand Up @@ -759,7 +759,7 @@ def check_network_mode(_test_func=None, enable=True):
:param _test_func: Test function being decorated.
:param enable: Boolean value indicating whether ``_test_func`` expects network mode to be enabled in order to pass.
"""
if enable and network_mode_supported():
if enable:
settings = {"magpie.network_enabled": True}
else:
settings = {"magpie.network_enabled": False}
Expand Down

0 comments on commit bd2da76

Please sign in to comment.