Test for getting the languages list

main
Bob Mottram 2021-08-11 10:15:46 +01:00
parent 1a54698ec8
commit f2b4de3044
2 changed files with 16 additions and 7 deletions

View File

@ -47,15 +47,21 @@ def setActorLanguages(baseDir: str, actorJson: {}, languagesStr: str) -> None:
elif ' ' in languagesStr:
separator = ' '
langList = languagesStr.lower().split(separator)
langList2 = []
langList2 = ''
for lang in langList:
lang = lang.strip()
if baseDir:
languageFilename = baseDir + '/translations/' + lang + '.json'
if os.path.isfile(languageFilename):
langList2.append(lang)
if langList2:
langList2 += ', ' + lang.strip()
else:
langList2 += lang.strip()
else:
langList2.append(lang)
if langList2:
langList2 += ', ' + lang.strip()
else:
langList2 += lang.strip()
# remove any existing value
propertyFound = None

View File

@ -42,6 +42,7 @@ from follow import clearFollowers
from follow import sendFollowRequestViaServer
from follow import sendUnfollowRequestViaServer
from siteactive import siteIsActive
from utils import getActorLanguagesList
from utils import getCategoryTypes
from utils import getSupportedLanguages
from utils import setConfigParam
@ -5084,10 +5085,12 @@ def _testSetActorLanguages():
assert len(actorJson['attachment']) == 1
assert actorJson['attachment'][0]['name'] == 'Languages'
assert actorJson['attachment'][0]['type'] == 'PropertyValue'
assert len(actorJson['attachment'][0]['value']) == 3
assert 'en' in actorJson['attachment'][0]['value']
assert 'fr' in actorJson['attachment'][0]['value']
assert 'es' in actorJson['attachment'][0]['value']
assert isinstance(actorJson['attachment'][0]['value'], str)
assert ',' in actorJson['attachment'][0]['value']
langList = getActorLanguagesList(actorJson)
assert 'en' in langList
assert 'fr' in langList
assert 'es' in langList
languagesStr = getActorLanguages(actorJson)
assert languagesStr == 'en / es / fr'