Skip to content

Commit

Permalink
Fix auth issue, rename user 'email, and password 'pw'
Browse files Browse the repository at this point in the history
  • Loading branch information
Kidev committed Feb 2, 2025
1 parent 409cb4b commit e8c5ccb
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 56 deletions.
28 changes: 14 additions & 14 deletions aqt/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ class InstallArgParser(CommonInstallArgParser):
qt_version: str
qt_version_spec: str
version: Optional[str]
user: Optional[str]
password: Optional[str]
email: Optional[str]
pw: Optional[str]
operation_does_not_exist_error: str
overwrite_target_dir: str
stop_processes_for_updates: str
Expand Down Expand Up @@ -696,8 +696,8 @@ def run_install_qt_commercial(self, args: InstallArgParser) -> None:
base_url=args.base if args.base is not None else Settings.baseurl,
override=override_args,
no_unattended=not Settings.qt_installer_unattended,
username=username or args.user,
password=password or args.password,
username=username or args.email,
password=password or args.pw,
)
else:
if not all([args.target, args.arch, args.version]):
Expand All @@ -707,8 +707,8 @@ def run_install_qt_commercial(self, args: InstallArgParser) -> None:
target=args.target,
arch=args.arch,
version=args.version,
username=args.user,
password=args.password,
username=args.email,
password=args.pw,
output_dir=args.outputdir,
logger=self.logger,
base_url=args.base if args.base is not None else Settings.baseurl,
Expand Down Expand Up @@ -847,11 +847,11 @@ def __call__(self, parser, namespace, values, option_string=None) -> None:
install_qt_commercial_parser.add_argument("version", nargs="?", help="Qt version", action=ConditionalRequiredAction)

install_qt_commercial_parser.add_argument(
"--user",
help="Qt account username",
"--email",
help="Qt account email",
)
install_qt_commercial_parser.add_argument(
"--password",
"--pw",
help="Qt account password",
)
install_qt_commercial_parser.add_argument(
Expand All @@ -866,11 +866,11 @@ def _set_list_qt_commercial_parser(self, list_qt_commercial_parser: argparse.Arg
list_qt_commercial_parser.set_defaults(func=self.run_list_qt_commercial)

list_qt_commercial_parser.add_argument(
"--user",
help="Qt account username",
"--email",
help="Qt account email",
)
list_qt_commercial_parser.add_argument(
"--password",
"--pw",
help="Qt account password",
)

Expand Down Expand Up @@ -920,8 +920,8 @@ def run_list_qt_commercial(self, args) -> None:
# Build command
cmd = [str(installer_path), "--accept-licenses", "--accept-obligations", "--confirm-command"]

if args.user and args.password:
cmd.extend(["--email", args.user, "--pw", args.password])
if args.email and args.pw:
cmd.extend(["--email", args.email, "--pw", args.pw])

cmd.append("search")

Expand Down
2 changes: 1 addition & 1 deletion ci/steps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ steps:
mkdir Qt
cd Qt
if [[ "$(SUBCOMMAND)" == "install-qt-commercial" ]]; then
opt+=" --user $(AQT_TEST_EMAIL) --password $(AQT_TEST_PASSWORD)"
opt+=" --email $(AQT_TEST_EMAIL) --pw $(AQT_TEST_PASSWORD)"
python -m aqt install-qt-commercial $opt $(TARGET) $(ARCH) $(QT_VERSION) --m $(MODULE)
fi
if [[ "$(SUBCOMMAND)" == "install-qt" ]]; then
Expand Down
110 changes: 69 additions & 41 deletions tests/test_commercial.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import logging
import os
import shutil
import sys
from pathlib import Path
from tempfile import TemporaryDirectory
from typing import Dict, List, Optional
from unittest.mock import MagicMock

import pytest
import requests
Expand Down Expand Up @@ -97,7 +99,7 @@ def test_cli_login_qt_commercial(capsys, monkeypatch, cmd, expected_arch, expect
cli.run(cmd.split())

out, err = capsys.readouterr()
assert expected_err in err or expected_arch in out
assert expected_err in err or expected_err in out


def test_package_manager_init():
Expand Down Expand Up @@ -250,7 +252,7 @@ def mock_gather_packages(self, installer_path: str) -> None:
"cmd, arch_dict, details, expected_command",
[
(
"install-qt-commercial desktop {} 6.8.1 " "--outputdir ./install-qt-commercial --user {} --password {}",
"install-qt-commercial desktop {} 6.8.1 " "--outputdir ./install-qt-commercial --email {} --pw {}",
{"windows": "win64_msvc2022_64", "linux": "linux_gcc_64", "mac": "clang_64"},
["./install-qt-commercial", "qt6", "681"],
"qt-unified-{}-x64-online.run --email ******** --pw ******** --root {} "
Expand All @@ -261,7 +263,7 @@ def mock_gather_packages(self, installer_path: str) -> None:
"AssociateCommonFiletypes=Yes,telemetry-question=No install qt.{}.{}.{}",
),
(
"install-qt-commercial desktop {} 6.8.1 --outputdir ./install-qt-commercial --user {} --password {}",
"install-qt-commercial desktop {} 6.8.1 --outputdir ./install-qt-commercial --email {} --pw {}",
{"windows": "win64_msvc2022_64", "linux": "linux_gcc_64", "mac": "clang_64"},
["./install-qt-commercial", "qt6", "681"],
"qt-unified-{}-x64-online.run --email ******** --pw ******** --root {} "
Expand Down Expand Up @@ -309,8 +311,8 @@ def mock_safely_run(*args, **kwargs):

# Create a new command with the temp directory
new_cmd = (
f"install-qt-commercial desktop {arch} 6.8.{str(details[2])[-1]} --outputdir {abs_out} --user {email} "
f"--password {password}"
f"install-qt-commercial desktop {arch} 6.8.{str(details[2])[-1]} --outputdir {abs_out} --email {email} "
f"--pw {password}"
)

# This should raise DiskAccessNotPermitted only for the first test (680)
Expand Down Expand Up @@ -360,45 +362,71 @@ def modify_qt_config(content):
shutil.rmtree(abs_out)


@pytest.mark.enable_socket
@pytest.mark.parametrize(
"args, expected_ret",
[
(
[
"list-qt-commercial",
"--user",
TEST_EMAIL,
"--password",
TEST_PASSWORD,
"6.8.1",
],
"INFO : [0] Arguments",
),
(
[
"install-qt-commercial",
"--override",
"search",
"6.8.0",
"--email",
TEST_EMAIL,
"--pw",
TEST_PASSWORD,
],
"INFO : Qt installation completed successfully",
),
],
)
def test_list_qt_commercial(capsys, args, expected_ret):
"""Test error handling in list-qt-commercial command"""
def create_mock_process(stdout):
mock = MagicMock()
mock.stdout = stdout
mock.returncode = 0
return mock


def test_commercial_commands(monkeypatch, caplog):
caplog.set_level(logging.INFO)

# Mock filesystem operations
def mock_mkdir(*args, **kwargs):
return None

monkeypatch.setattr(Path, "mkdir", mock_mkdir)
monkeypatch.setattr(Path, "exists", lambda x: False)

# Mock subprocess run to return our predefined output
sample_output = "Name: qt6.8.1-full"

def mock_safely_run_save_output(cmd, timeout):
return create_mock_process(sample_output)

def mock_safely_run(cmd, timeout):
return None

monkeypatch.setattr("aqt.helper.safely_run_save_output", mock_safely_run_save_output)
monkeypatch.setattr("aqt.helper.safely_run", mock_safely_run)

# Mock requests for installer download
def mock_get(*args, **kwargs):
mock_response = MagicMock()
mock_response.raise_for_status = lambda: None
mock_response.iter_content = lambda chunk_size: [b"mock data"]
return mock_response

monkeypatch.setattr("requests.get", mock_get)

# Mock file operations
mock_open = MagicMock()
monkeypatch.setattr("builtins.open", mock_open)

# Test list-qt-commercial command
from aqt.installer import Cli

Check warning on line 408 in tests/test_commercial.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

tests/test_commercial.py#L408

Reimport 'Cli' (imported line 16)

cli = Cli()
cli._setup_settings()
cli.run(args)
list_args = cli.parser.parse_args(["list-qt-commercial", "--email", TEST_EMAIL, "--pw", TEST_PASSWORD, "6.8.1"])
cli.run(list_args)

out, err = capsys.readouterr()
# Verify key outputs in logs
assert any("aqtinstall(aqt)" in record.message for record in caplog.records)
assert any("Downloading Qt installer" in record.message for record in caplog.records)

# Clear logs for next test
caplog.clear()

# Test install-qt-commercial command
install_args = cli.parser.parse_args(
["install-qt-commercial", "--override", "search", "6.8.0", "--email", TEST_EMAIL, "--pw", TEST_PASSWORD]
)
cli.run(install_args)

assert expected_ret in err or expected_ret in out
# Verify key outputs in logs
assert any("Qt installation completed successfully" in record.message for record in caplog.records)
assert any("Done" in record.message for record in caplog.records)


@pytest.mark.parametrize(
Expand Down

0 comments on commit e8c5ccb

Please sign in to comment.