Skip to content

Commit

Permalink
[3.0.34] Fix python 3.8 syntax without black code format
Browse files Browse the repository at this point in the history
  • Loading branch information
mauricelambert committed May 23, 2024
1 parent e729be7 commit b30a3a2
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 47 deletions.
17 changes: 7 additions & 10 deletions test/TestUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -622,8 +622,8 @@ def st_mode(self):
getpwuid = getattr(WebScripts.utils, "getpwuid", None)

WebScripts.utils.user = "root"
WebScripts.utils.getpwuid = lambda x: (
Mock(pw_name="root") if x == 0 else Mock()
WebScripts.utils.getpwuid = (
lambda x: Mock(pw_name="root") if x == 0 else Mock()
)

class SpecialMock(Mock):
Expand All @@ -634,14 +634,11 @@ def __call__(self, file):
isfile = WebScripts.utils.isfile
mock = WebScripts.utils.isfile = SpecialMock()

with (
patch.object(
WebScripts.utils, "stat", return_value=stat_response
) as file,
patch.object(
WebScripts.utils, "isdir", return_value=True
) as mock2,
):
with patch.object(
WebScripts.utils, "stat", return_value=stat_response
) as file, patch.object(
WebScripts.utils, "isdir", return_value=True
) as mock2:
self.assertTrue(
check_file_permission(config, "test/test", False, False, True)
)
Expand Down
37 changes: 15 additions & 22 deletions test/TestWebScripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,9 +335,9 @@ def test_set_default_headers(self):

Server.set_default_headers(h, True, c)

headers["Strict-Transport-Security"] = (
"max-age=63072000; includeSubDomains; preload"
)
headers[
"Strict-Transport-Security"
] = "max-age=63072000; includeSubDomains; preload"
headers["Content-Security-Policy"] = (
"default-src 'self'; navigate-to 'self'; worker-src "
"'none'; style-src-elem 'self'; style-src-attr 'none';"
Expand All @@ -352,19 +352,19 @@ def test_set_default_headers(self):
headers["X-XSS-Protection"] = "1; mode=block"
headers["X-Content-Type-Options"] = "nosniff"
headers["Referrer-Policy"] = "origin-when-cross-origin"
headers["Cache-Control"] = (
"no-cache, no-store, must-revalidate, private"
)
headers[
"Cache-Control"
] = "no-cache, no-store, must-revalidate, private"
headers["Pragma"] = "no-cache"
headers["Expires"] = "0"
headers["Clear-Site-Data"] = '"cache", "executionContexts"'
headers["Feature-Policy"] = (
"payment 'none'; geolocation 'none'; "
"microphone 'none'; camera 'none'"
)
headers["Permissions-Policy"] = (
"microphone=(),camera=(),payment=(),geolocation=()"
)
headers[
"Permissions-Policy"
] = "microphone=(),camera=(),payment=(),geolocation=()"
headers["Cross-Origin-Embedder-Policy"] = "require-corp"
headers["Cross-Origin-Opener-Policy"] = "same-origin"
headers["Cross-Origin-Resource-Policy"] = "same-origin"
Expand Down Expand Up @@ -1538,11 +1538,9 @@ def test_get_server_config(self):
with patch.object(
WebScripts.WebScripts,
"system",
return_value=(
"Linux"
if WebScripts.WebScripts.system() == "Windows"
else "Windows"
),
return_value="Linux"
if WebScripts.WebScripts.system() == "Windows"
else "Windows",
) as mock_method:
for configurations in get_server_config(arguments):
self.assertTrue(isinstance(configurations, dict))
Expand All @@ -1568,14 +1566,9 @@ def test_logs_configuration(self):
def test_configure_logs_system(self):
global WebScripts

with (
patch.object(
WebScripts.WebScripts,
"check_file_permission",
return_value=False,
),
self.assertRaises(WebScriptsSecurityError),
):
with patch.object(
WebScripts.WebScripts, "check_file_permission", return_value=False
), self.assertRaises(WebScriptsSecurityError):
configure_logs_system()
self.assertTrue(path.isdir("logs"))
self.assertFalse(path.isfile(path.join("logs", "root.logs")))
Expand Down
26 changes: 11 additions & 15 deletions test/TestWebScriptsImports.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,9 @@ def isdir(directory):

sys.modules["os"].mkdir = OsModule.mkdir

with (
patch.object(sys.modules["os.path"], "isdir", return_value=False),
patch.object(sys.modules["path"], "isdir", return_value=False),
):
with patch.object(
sys.modules["os.path"], "isdir", return_value=False
), patch.object(sys.modules["path"], "isdir", return_value=False):
import WebScripts

real_check_file_permission = WebScripts.check_file_permission
Expand Down Expand Up @@ -375,17 +374,14 @@ def change_WINDOWS_LOGS(*args):
# lambda *x, **y: "Linux" if system() == "Windows" else "Windows"
# )

with (
patch.object(
sys.modules["platform"],
"system",
return_value=("Linux" if system() == "Windows" else "Windows"),
),
patch.object(
sys.modules["subprocess"],
"check_call",
return_value=0,
),
with patch.object(
sys.modules["platform"],
"system",
return_value=("Linux" if system() == "Windows" else "Windows"),
), patch.object(
sys.modules["subprocess"],
"check_call",
return_value=0,
):
utils.get_real_path("/test/whynot", no_error=True)
_exec(utils.__spec__, utils)
Expand Down

0 comments on commit b30a3a2

Please sign in to comment.