diff --git a/silkaj/cli.py b/silkaj/cli.py index e7455f0c539f2232c432ae9bac96d7189b0c7693..405c063f7462d6910fffb7dd5f1feaa798698558 100644 --- a/silkaj/cli.py +++ b/silkaj/cli.py @@ -87,13 +87,6 @@ from silkaj.wot import id_pubkey_correspondence, received_sent_certifications help="By-pass licence, confirmation. \ Do not send the document, but display it instead", ) -@option( - "--g1-license-web", - "-w", - is_flag=True, - help="Display Äž1 monetary license in a web browser if not running on a headless system. \ -Defaults to terminal display.", -) @pass_context def cli( ctx, @@ -107,7 +100,6 @@ def cli( auth_wif, display, dry_run, - g1_license_web, ): if display and dry_run: sys.exit("ERROR: display and dry-run options can not be used together") @@ -124,7 +116,6 @@ def cli( ctx.obj["AUTH_WIF"] = auth_wif ctx.obj["DISPLAY_DOCUMENT"] = display ctx.obj["DRY_RUN"] = dry_run - ctx.obj["G1_LICENSE_WEB"] = g1_license_web cli.add_command(argos_info) diff --git a/silkaj/license.py b/silkaj/license.py index baee1f8ada79f4e78468225d78727b3759ad2c3e..00c318d4814b8fcefa79225806bf5213e092bad3 100644 --- a/silkaj/license.py +++ b/silkaj/license.py @@ -13,7 +13,6 @@ # You should have received a copy of the GNU Affero General Public License # along with Silkaj. If not, see <https://www.gnu.org/licenses/>. -import webbrowser from pathlib import Path from typing import List @@ -22,11 +21,6 @@ import g1_monetary_license as gml languages = ["es", "en", "eo", "it", "fr", "pt"] -licenses_urls = { - "en": "https://duniter.org/en/wiki/g1-license/", - "fr": "https://duniter.fr/wiki/g1/licence-txt/", -} - def license_approval(currency: str) -> None: if currency != "g1": @@ -43,29 +37,14 @@ def license_command() -> None: display_license() -@click.pass_context -def display_license(ctx) -> None: +def display_license() -> None: """ - Display in web browser if flag set and not headless system - Otherwise, display in the terminal + Display license in the terminal """ - if ctx.obj["G1_LICENSE_WEB"] and has_web_browser(): - languages_choices = list(licenses_urls.keys()) - language = language_prompt(languages_choices) - webbrowser.open(licenses_urls[language]) - else: - language = language_prompt(languages) - path = license_path(language) - with open(path) as license: - click.echo_via_pager(license.read()) - - -def has_web_browser() -> bool: - try: - webbrowser.get() - return True - except webbrowser.Error: - return False + language = language_prompt(languages) + path = license_path(language) + with open(path) as license: + click.echo_via_pager(license.read()) def language_prompt(languages_choices: List) -> str: diff --git a/tests/test_license.py b/tests/test_license.py index 91924ea758867940c39bac131e088ab97e7e0b7e..b1b72d838a3660160310ccc60853344c4b631417 100644 --- a/tests/test_license.py +++ b/tests/test_license.py @@ -13,8 +13,6 @@ # You should have received a copy of the GNU Affero General Public License # along with Silkaj. If not, see <https://www.gnu.org/licenses/>. -import webbrowser -from pathlib import Path from unittest.mock import patch import pytest @@ -50,42 +48,6 @@ def test_license_approval_g1(mock_display_license, mock_confirm, display, approv mock_confirm.assert_called() -@pytest.mark.parametrize( - "language, web, license_sample", - [ - ("en", False, "**Currency licensing"), - ("fr", False, "**Licence de la monnaie"), - ("en", True, "**Currency licensing"), - ("fr", True, "**Licence de la monnaie"), - ], -) -@patch("webbrowser.open") -def test_display_license(webbrowser_open, language, web, license_sample): - args = [] - if web: - args += ["--g1-license-web"] - args += ["license"] - - result = CliRunner().invoke(cli.cli, args=args, input=language) - assert "In which language" in result.output - if web and license.has_web_browser(): - webbrowser_open.assert_called_once_with(license.licenses_urls[language]) - else: - assert license_sample in result.output - assert result.exit_code == SUCCESS_EXIT_STATUS - - -def test_has_web_browser(): - """ - https://stackoverflow.com/a/50990039 - """ - with patch("webbrowser.get", side_effect=webbrowser.Error): - assert license.has_web_browser() == False - - with patch("webbrowser.get", side_effect=None): - assert license.has_web_browser() == True - - @pytest.mark.parametrize( "language, license_sample", [