Skip to content
Snippets Groups Projects
Commit 6e89e9b5 authored by Moul's avatar Moul
Browse files

[mod] #426: Drop Ğ1 monetary license display in a browser

It doesn’t makes sense to keep displaying outdated license
From the console display of files, there is six languages versus two from websites
Less code means less maintenance
parent 246919df
No related branches found
No related tags found
1 merge request!207#426: Ğ1 monetary license: Drop browser display, languages discovery, class
......@@ -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)
......
......@@ -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:
......
......@@ -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",
[
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment