forked from indymedia/epicyon
Unit test for emoji
parent
bacc06f416
commit
cd30e547b8
45
tests.py
45
tests.py
|
@ -40,6 +40,7 @@ from follow import sendUnfollowRequestViaServer
|
||||||
from utils import followPerson
|
from utils import followPerson
|
||||||
from utils import getNicknameFromActor
|
from utils import getNicknameFromActor
|
||||||
from utils import getDomainFromActor
|
from utils import getDomainFromActor
|
||||||
|
from utils import copytree
|
||||||
from follow import followerOfPerson
|
from follow import followerOfPerson
|
||||||
from follow import unfollowPerson
|
from follow import unfollowPerson
|
||||||
from follow import unfollowerOfPerson
|
from follow import unfollowerOfPerson
|
||||||
|
@ -65,6 +66,8 @@ from delete import sendDeleteViaServer
|
||||||
from inbox import validInbox
|
from inbox import validInbox
|
||||||
from inbox import validInboxFilenames
|
from inbox import validInboxFilenames
|
||||||
from content import addWebLinks
|
from content import addWebLinks
|
||||||
|
from content import replaceEmojiFromTags
|
||||||
|
from content import addHtmlTags
|
||||||
|
|
||||||
testServerAliceRunning = False
|
testServerAliceRunning = False
|
||||||
testServerBobRunning = False
|
testServerBobRunning = False
|
||||||
|
@ -1375,8 +1378,50 @@ def testWebLinks():
|
||||||
linkedText=addWebLinks(exampleText)
|
linkedText=addWebLinks(exampleText)
|
||||||
assert '<a href="https://somesite.net" rel="nofollow noopener" target="_blank"><span class="invisible">https://</span><span class="ellipsis">somesite.net</span></a' in linkedText
|
assert '<a href="https://somesite.net" rel="nofollow noopener" target="_blank"><span class="invisible">https://</span><span class="ellipsis">somesite.net</span></a' in linkedText
|
||||||
|
|
||||||
|
def testAddEmoji():
|
||||||
|
print('testAddEmoji')
|
||||||
|
content='Emoji :lemon: :strawberry: :banana:'
|
||||||
|
httpPrefix='http'
|
||||||
|
nickname='testuser'
|
||||||
|
domain='testdomain.net'
|
||||||
|
port=3682
|
||||||
|
recipients=[]
|
||||||
|
hashtags={}
|
||||||
|
baseDir=os.getcwd()
|
||||||
|
baseDirOriginal=os.getcwd()
|
||||||
|
path=baseDir+'/.tests'
|
||||||
|
if not os.path.isdir(path):
|
||||||
|
os.mkdir(path)
|
||||||
|
path=baseDir+'/.tests/emoji'
|
||||||
|
if os.path.isdir(path):
|
||||||
|
shutil.rmtree(path)
|
||||||
|
os.mkdir(path)
|
||||||
|
baseDir=path
|
||||||
|
path=baseDir+'/emoji'
|
||||||
|
if os.path.isdir(path):
|
||||||
|
shutil.rmtree(path)
|
||||||
|
os.mkdir(path)
|
||||||
|
copytree(baseDirOriginal+'/emoji',baseDir+'/emoji')
|
||||||
|
os.chdir(baseDir)
|
||||||
|
privateKeyPem,publicKeyPem,person,wfEndpoint= \
|
||||||
|
createPerson(baseDir,nickname,domain,port,httpPrefix,True,'password')
|
||||||
|
contentModified= \
|
||||||
|
addHtmlTags(baseDir,httpPrefix, \
|
||||||
|
nickname,domain,content, \
|
||||||
|
recipients,hashtags)
|
||||||
|
tags=[]
|
||||||
|
for tagName,tag in hashtags.items():
|
||||||
|
tags.append(tag)
|
||||||
|
content=contentModified
|
||||||
|
contentModified=replaceEmojiFromTags(content,tags,'content')
|
||||||
|
assert 'img src' in contentModified
|
||||||
|
|
||||||
|
os.chdir(baseDirOriginal)
|
||||||
|
shutil.rmtree(baseDirOriginal+'/.tests')
|
||||||
|
|
||||||
def runAllTests():
|
def runAllTests():
|
||||||
print('Running tests...')
|
print('Running tests...')
|
||||||
|
testAddEmoji()
|
||||||
testWebLinks()
|
testWebLinks()
|
||||||
testActorParsing()
|
testActorParsing()
|
||||||
testHttpsig()
|
testHttpsig()
|
||||||
|
|
12
utils.py
12
utils.py
|
@ -7,6 +7,7 @@ __email__ = "bob@freedombone.net"
|
||||||
__status__ = "Production"
|
__status__ = "Production"
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import shutil
|
||||||
import datetime
|
import datetime
|
||||||
import commentjson
|
import commentjson
|
||||||
|
|
||||||
|
@ -324,3 +325,14 @@ def isPublicPost(postJsonObject: {}) -> bool:
|
||||||
if recipient.endswith('#Public'):
|
if recipient.endswith('#Public'):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def copytree(src: str, dst: str, symlinks=False, ignore=None):
|
||||||
|
"""Copy a directory
|
||||||
|
"""
|
||||||
|
for item in os.listdir(src):
|
||||||
|
s = os.path.join(src, item)
|
||||||
|
d = os.path.join(dst, item)
|
||||||
|
if os.path.isdir(s):
|
||||||
|
shutil.copytree(s, d, symlinks, ignore)
|
||||||
|
else:
|
||||||
|
shutil.copy2(s, d)
|
||||||
|
|
Loading…
Reference in New Issue