From 47be3a762abb4968892dfe81dd46b8b1833b8d9e Mon Sep 17 00:00:00 2001 From: Ivan Habunek Date: Sun, 11 Dec 2022 23:03:08 +0100 Subject: [PATCH] Fix language specification Old API docs claimed to require ISO 639-2 format, testing determines that that ISO 639-1 is required instead. --- tests/test_console.py | 4 ++-- tests/test_integration.py | 12 ++++++++++++ toot/console.py | 6 +++--- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/tests/test_console.py b/tests/test_console.py index d912033..a985b45 100644 --- a/tests/test_console.py +++ b/tests/test_console.py @@ -61,7 +61,7 @@ def test_post_with_options(mock_post, mock_uuid, capsys): '--sensitive', '--spoiler-text', 'Spoiler!', '--reply-to', '123a', - '--language', 'hrv', + '--language', 'hr', ] mock_post.return_value = MockResponse({ @@ -77,7 +77,7 @@ def test_post_with_options(mock_post, mock_uuid, capsys): 'sensitive': True, 'spoiler_text': "Spoiler!", 'in_reply_to_id': '123a', - 'language': 'hrv', + 'language': 'hr', }, headers={"Idempotency-Key": "up-the-irons"}) out, err = capsys.readouterr() diff --git a/tests/test_integration.py b/tests/test_integration.py index f44b081..d2636df 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -192,6 +192,18 @@ def test_post_scheduled_in(app, user, run): assert delta.total_seconds() < 5 +def test_post_language(app, user, run): + out = run("post", "test", "--language", "hr") + status_id = _posted_status_id(out) + status = api.fetch_status(app, user, status_id) + assert status["language"] == "hr" + + out = run("post", "test", "--language", "zh") + status_id = _posted_status_id(out) + status = api.fetch_status(app, user, status_id) + assert status["language"] == "zh" + + def test_media_attachments(app, user, run): assets_dir = path.realpath(path.join(path.dirname(__file__), "assets")) diff --git a/toot/console.py b/toot/console.py index b9ff8c6..71ced98 100644 --- a/toot/console.py +++ b/toot/console.py @@ -17,10 +17,10 @@ VISIBILITY_CHOICES = ['public', 'unlisted', 'private', 'direct'] def language(value): """Validates the language parameter""" - if len(value) != 3: + if len(value) != 2: raise ArgumentTypeError( - "Invalid language specified: '{}'. Expected a 3 letter " - "abbreviation according to ISO 639-2 standard.".format(value) + "Invalid language. Expected a 2 letter abbreviation according to " + "the ISO 639-1 standard." ) return value