From f27a1dd9a3a778d981813542d936fa56f22c3d2d Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Thu, 5 Jan 2023 22:33:05 +0000 Subject: [PATCH] Unit test for hashtag link replacement --- tests.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tests.py b/tests.py index c99597fee..478700958 100644 --- a/tests.py +++ b/tests.py @@ -135,6 +135,7 @@ from inbox import valid_inbox from inbox import valid_inbox_filenames from inbox import cache_svg_images from categories import guess_hashtag_category +from content import replace_remote_hashtags from content import add_name_emojis_to_tags from content import combine_textarea_lines from content import detect_dogwhistles @@ -7719,6 +7720,31 @@ def _test_replace_variable(): assert result == expected +def _test_replace_remote_tags() -> None: + print('replace_remote_tags') + nickname = 'mynick' + domain = 'furious.duck' + content = 'This is a test' + result = replace_remote_hashtags(content, nickname, domain) + assert result == content + + link = "https://something/else/mytag" + content = 'This is href="' + link + '" test' + result = replace_remote_hashtags(content, nickname, domain) + assert result == content + + link = "https://something/tags/mytag" + content = 'This is href="' + link + '" test' + result = replace_remote_hashtags(content, nickname, domain) + expected = \ + 'This is href="/users/' + nickname + '?remotetag=' + \ + link.replace('/', '--') + '" test' + if result != expected: + print(expected) + print(result) + assert result == expected + + def run_all_tests(): base_dir = os.getcwd() print('Running tests...') @@ -7736,6 +7762,7 @@ def run_all_tests(): _test_checkbox_names() _test_thread_functions() _test_functions() + _test_replace_remote_tags() _test_replace_variable() _test_missing_theme_colors(base_dir) _test_reply_language(base_dir)