mirror of https://gitlab.com/bashrc2/epicyon
Test for web link replacement in the speaker interface
parent
9851a0f1af
commit
f0659f2dd2
|
@ -38,7 +38,7 @@ def speakerReplaceLinks(sayText: str, translate: {},
|
||||||
"""Replaces any links in the given text with "link to [domain]".
|
"""Replaces any links in the given text with "link to [domain]".
|
||||||
Instead of reading out potentially very long and meaningless links
|
Instead of reading out potentially very long and meaningless links
|
||||||
"""
|
"""
|
||||||
removeChars = ('.', ',', ';', ':', '?', '!')
|
removeChars = ('.\n', '. ', ',', ';', '?', '!')
|
||||||
text = sayText
|
text = sayText
|
||||||
for ch in removeChars:
|
for ch in removeChars:
|
||||||
text = text.replace(ch, ' ')
|
text = text.replace(ch, ' ')
|
||||||
|
@ -58,11 +58,13 @@ def speakerReplaceLinks(sayText: str, translate: {},
|
||||||
continue
|
continue
|
||||||
if '/' in domain:
|
if '/' in domain:
|
||||||
domain = domain.split('/')[0]
|
domain = domain.split('/')[0]
|
||||||
|
if domain.startswith('www.'):
|
||||||
|
domain = domain.replace('www.', '')
|
||||||
replacements[domainFull] = '. ' + linkedStr + ' ' + domain + '.'
|
replacements[domainFull] = '. ' + linkedStr + ' ' + domain + '.'
|
||||||
detectedLinks.append(domainFull)
|
detectedLinks.append(domainFull)
|
||||||
for replaceStr, newStr in replacements.items():
|
for replaceStr, newStr in replacements.items():
|
||||||
sayText = sayText.replace(replaceStr, newStr)
|
sayText = sayText.replace(replaceStr, newStr)
|
||||||
return sayText
|
return sayText.replace('..', '.')
|
||||||
|
|
||||||
|
|
||||||
def getSpeakerFromServer(baseDir: str, session,
|
def getSpeakerFromServer(baseDir: str, session,
|
||||||
|
|
22
tests.py
22
tests.py
|
@ -100,6 +100,7 @@ from mastoapiv1 import getMastoApiV1IdFromNickname
|
||||||
from mastoapiv1 import getNicknameFromMastoApiV1Id
|
from mastoapiv1 import getNicknameFromMastoApiV1Id
|
||||||
from webapp_post import prepareHtmlPostNickname
|
from webapp_post import prepareHtmlPostNickname
|
||||||
from webapp_utils import markdownToHtml
|
from webapp_utils import markdownToHtml
|
||||||
|
from speaker import speakerReplaceLinks
|
||||||
|
|
||||||
testServerAliceRunning = False
|
testServerAliceRunning = False
|
||||||
testServerBobRunning = False
|
testServerBobRunning = False
|
||||||
|
@ -3368,9 +3369,30 @@ def testExtractTextFieldsInPOST():
|
||||||
assert fields['message'] == 'This is a ; test'
|
assert fields['message'] == 'This is a ; test'
|
||||||
|
|
||||||
|
|
||||||
|
def testSpeakerReplaceLinks():
|
||||||
|
print('testSpeakerReplaceLinks')
|
||||||
|
text = 'The Tor Project: For Snowflake volunteers: If you use ' + \
|
||||||
|
'Firefox, Brave, or Chrome, our Snowflake extension turns ' + \
|
||||||
|
'your browser into a proxy that connects Tor users in ' + \
|
||||||
|
'censored regions to the Tor network. Note: you should ' + \
|
||||||
|
'not run more than one snowflake in the same ' + \
|
||||||
|
'network.https://support.torproject.org/censorship/' + \
|
||||||
|
'how-to-help-running-snowflake/'
|
||||||
|
detectedLinks = []
|
||||||
|
result = speakerReplaceLinks(text, {'Linked': 'Web link'}, detectedLinks)
|
||||||
|
print(result)
|
||||||
|
print(str(detectedLinks))
|
||||||
|
assert len(detectedLinks) == 1
|
||||||
|
assert detectedLinks[0] == \
|
||||||
|
'https://support.torproject.org/censorship/' + \
|
||||||
|
'how-to-help-running-snowflake/'
|
||||||
|
assert 'Web link support.torproject.org' in result
|
||||||
|
|
||||||
|
|
||||||
def runAllTests():
|
def runAllTests():
|
||||||
print('Running tests...')
|
print('Running tests...')
|
||||||
testFunctions()
|
testFunctions()
|
||||||
|
testSpeakerReplaceLinks()
|
||||||
testExtractTextFieldsInPOST()
|
testExtractTextFieldsInPOST()
|
||||||
testMarkdownToHtml()
|
testMarkdownToHtml()
|
||||||
testValidHashTag()
|
testValidHashTag()
|
||||||
|
|
Loading…
Reference in New Issue