Tests for follow functions

master
Bob Mottram 2019-07-03 10:24:55 +01:00
parent 0a956f3ea6
commit 60b59d4f86
3 changed files with 100 additions and 11 deletions

View File

@ -283,12 +283,12 @@ class PubServer(BaseHTTPRequestHandler):
def runDaemon(domain: str,port=80,https=True,fedList=[],useTor=False) -> None: def runDaemon(domain: str,port=80,https=True,fedList=[],useTor=False) -> None:
if len(domain)==0: if len(domain)==0:
domain='127.0.0.1' domain='localhost'
if '.' not in domain: if '.' not in domain:
print('Invalid domain: ' + domain) print('Invalid domain: ' + domain)
return return
serverAddress = (domain, port) serverAddress = ('', port)
httpd = ThreadingHTTPServer(serverAddress, PubServer) httpd = ThreadingHTTPServer(serverAddress, PubServer)
httpd.domain=domain httpd.domain=domain
httpd.port=port httpd.port=port

View File

@ -35,17 +35,60 @@ from follow import unfollowPerson
from follow import unfollowerOfPerson from follow import unfollowerOfPerson
from tests import testPostMessageBetweenServers from tests import testPostMessageBetweenServers
from tests import runAllTests from tests import runAllTests
import argparse
runAllTests() def str2bool(v):
if isinstance(v, bool):
return v
if v.lower() in ('yes', 'true', 't', 'y', '1'):
return True
elif v.lower() in ('no', 'false', 'f', 'n', '0'):
return False
else:
raise argparse.ArgumentTypeError('Boolean value expected.')
parser = argparse.ArgumentParser(description='ActivityPub Server')
parser.add_argument('-d','--domain', dest='domain', type=str,default='localhost',
help='Domain name of the server')
parser.add_argument('-p','--port', dest='port', type=int,default=80,
help='Port number to run on')
parser.add_argument('--path', dest='baseDir', type=str,default=os.getcwd(),
help='Directory in which to store posts')
parser.add_argument('-f','--federate', nargs='+',dest='federationList',
help='Specify federation list separated by spaces')
parser.add_argument("--https", type=str2bool, nargs='?',
const=True, default=False,
help="Use https")
parser.add_argument("--tor", type=str2bool, nargs='?',
const=True, default=False,
help="Route via Tor")
parser.add_argument("--tests", type=str2bool, nargs='?',
const=True, default=False,
help="Run unit tests")
args = parser.parse_args()
if args.tests:
runAllTests()
sys.exit()
print(args.domain)
print(str(args.federationList))
username='admin'
domain=args.domain
port=args.port
https=args.https
useTor=args.tor
baseDir=args.baseDir
if baseDir.endswith('/'):
print("--path option should not end with '/'")
sys.exit()
federationList=[]
if args.federationList:
federationList=args.federationList.copy()
print(baseDir)
sys.exit()
federationList=['mastodon.social','wild.com','trees.com','127.0.0.1']
username='testuser'
#domain=socket.gethostname()
domain='0.0.0.0'
port=6227
https=False
useTor=False
baseDir=os.getcwd()
session = createSession(domain,port,useTor) session = createSession(domain,port,useTor)
personCache={} personCache={}
cachedWebfingers={} cachedWebfingers={}

View File

@ -206,11 +206,57 @@ def testPostMessageBetweenServers():
thrBob.join() thrBob.join()
assert thrBob.isAlive()==False assert thrBob.isAlive()==False
def testFollows():
currDir=os.getcwd()
username='test529'
domain='testdomain.com'
port=80
https=True
federationList=['wild.com','mesh.com']
baseDir=currDir+'/.tests_testfollows'
if os.path.isdir(baseDir):
shutil.rmtree(baseDir)
os.mkdir(baseDir)
os.chdir(baseDir)
createPerson(baseDir,username,domain,port,https,True)
clearFollows(baseDir,username,domain)
followPerson(baseDir,username,domain,'badger','wild.com',federationList)
followPerson(baseDir,username,domain,'squirrel','secret.com',federationList)
followPerson(baseDir,username,domain,'rodent','drainpipe.com',federationList)
followPerson(baseDir,username,domain,'batman','mesh.com',federationList)
followPerson(baseDir,username,domain,'giraffe','trees.com',federationList)
f = open(baseDir+'/accounts/'+username+'@'+domain+'/following.txt', "r")
for followingDomain in f:
testDomain=followingDomain.split('@')[1].replace('\n','')
if testDomain not in federationList:
print(testDomain)
assert(False)
clearFollowers(baseDir,username,domain)
followerOfPerson(baseDir,username,domain,'badger','wild.com',federationList)
followerOfPerson(baseDir,username,domain,'squirrel','secret.com',federationList)
followerOfPerson(baseDir,username,domain,'rodent','drainpipe.com',federationList)
followerOfPerson(baseDir,username,domain,'batman','mesh.com',federationList)
followerOfPerson(baseDir,username,domain,'giraffe','trees.com',federationList)
f = open(baseDir+'/accounts/'+username+'@'+domain+'/followers.txt', "r")
for followerDomain in f:
testDomain=followerDomain.split('@')[1].replace('\n','')
if testDomain not in federationList:
print(testDomain)
assert(False)
os.chdir(currDir)
shutil.rmtree(baseDir)
def runAllTests(): def runAllTests():
print('Running tests...') print('Running tests...')
testHttpsig() testHttpsig()
testCache() testCache()
testThreads() testThreads()
testFollows()
print('Tests succeeded\n') print('Tests succeeded\n')