forked from indymedia/epicyon
Tests for follow functions
parent
0a956f3ea6
commit
60b59d4f86
|
@ -283,12 +283,12 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
|
||||
def runDaemon(domain: str,port=80,https=True,fedList=[],useTor=False) -> None:
|
||||
if len(domain)==0:
|
||||
domain='127.0.0.1'
|
||||
domain='localhost'
|
||||
if '.' not in domain:
|
||||
print('Invalid domain: ' + domain)
|
||||
return
|
||||
|
||||
serverAddress = (domain, port)
|
||||
serverAddress = ('', port)
|
||||
httpd = ThreadingHTTPServer(serverAddress, PubServer)
|
||||
httpd.domain=domain
|
||||
httpd.port=port
|
||||
|
|
61
epicyon.py
61
epicyon.py
|
@ -35,17 +35,60 @@ from follow import unfollowPerson
|
|||
from follow import unfollowerOfPerson
|
||||
from tests import testPostMessageBetweenServers
|
||||
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)
|
||||
personCache={}
|
||||
cachedWebfingers={}
|
||||
|
|
46
tests.py
46
tests.py
|
@ -206,11 +206,57 @@ def testPostMessageBetweenServers():
|
|||
thrBob.join()
|
||||
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():
|
||||
print('Running tests...')
|
||||
testHttpsig()
|
||||
testCache()
|
||||
testThreads()
|
||||
testFollows()
|
||||
print('Tests succeeded\n')
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue