Fix network unit test

main
Bob Mottram 2020-03-02 21:28:22 +00:00
parent 91c7d7b226
commit ca5c0d5f20
3 changed files with 25 additions and 19 deletions

View File

@ -512,7 +512,8 @@ def receiveFollowRequest(session,baseDir: str,httpPrefix: str, \
# single user instance
nickname='dev'
if debug:
print('DEBUG: follow request does not contain a nickname. Assuming single user instance.')
print('DEBUG: follow request does not contain a '+ \
'nickname. Assuming single user instance.')
if not messageJson.get('to'):
messageJson['to']=messageJson['object']
handle=nickname.lower()+'@'+domain.lower()
@ -555,7 +556,7 @@ def receiveFollowRequest(session,baseDir: str,httpPrefix: str, \
return True
# what is the followers policy?
approveHandle=nickname+'@'+domainFull
approveHandle=nickname+'@'+domainFull
if followApprovalRequired(baseDir,nicknameToFollow, \
domainToFollow,debug,approveHandle):
print('Follow approval is required')

View File

@ -1168,19 +1168,23 @@ def testClientToServer():
'bob',bobDomain,bobPort, \
httpPrefix, \
cachedWebfingers,personCache, \
True,__version__)
for t in range(25):
if os.path.isfile(bobDir+'/accounts/bob@'+bobDomain+'/followers.txt'):
if 'alice@'+aliceDomain+':'+str(alicePort) in open(bobDir+'/accounts/bob@'+bobDomain+'/followers.txt').read():
if os.path.isfile(aliceDir+'/accounts/alice@'+aliceDomain+'/following.txt'):
if 'bob@'+bobDomain+':'+str(bobPort) in open(aliceDir+'/accounts/alice@'+aliceDomain+'/following.txt').read():
True,__version__)
aliceFollowingFilename=aliceDir+'/accounts/alice@'+aliceDomain+'/following.txt'
bobFollowersFilename=bobDir+'/accounts/bob@'+bobDomain+'/followers.txt'
for t in range(10):
if os.path.isfile(bobFollowersFilename):
if 'alice@'+aliceDomain+':'+str(alicePort) in open(bobFollowersFilename).read():
if os.path.isfile(aliceFollowingFilename):
if 'bob@'+bobDomain+':'+str(bobPort) in open(aliceFollowingFilename).read():
break
time.sleep(1)
assert os.path.isfile(bobDir+'/accounts/bob@'+bobDomain+'/followers.txt')
assert os.path.isfile(aliceDir+'/accounts/alice@'+aliceDomain+'/following.txt')
assert 'alice@'+aliceDomain+':'+str(alicePort) in open(bobDir+'/accounts/bob@'+bobDomain+'/followers.txt').read()
assert 'bob@'+bobDomain+':'+str(bobPort) in open(aliceDir+'/accounts/alice@'+aliceDomain+'/following.txt').read()
assert os.path.isfile(bobFollowersFilename)
assert os.path.isfile(aliceFollowingFilename)
print('alice@'+aliceDomain+':'+str(alicePort)+' in '+bobFollowersFilename)
assert 'alice@'+aliceDomain+':'+str(alicePort) in open(bobFollowersFilename).read()
print('bob@'+bobDomain+':'+str(bobPort)+' in '+aliceFollowingFilename)
assert 'bob@'+bobDomain+':'+str(bobPort) in open(aliceFollowingFilename).read()
assert validInbox(bobDir,'bob',bobDomain)
assert validInboxFilenames(bobDir,'bob',bobDomain,aliceDomain,alicePort)
@ -1285,15 +1289,15 @@ def testClientToServer():
cachedWebfingers,personCache, \
True,__version__)
for t in range(10):
if 'alice@'+aliceDomain+':'+str(alicePort) not in open(bobDir+'/accounts/bob@'+bobDomain+'/followers.txt').read():
if 'bob@'+bobDomain+':'+str(bobPort) not in open(aliceDir+'/accounts/alice@'+aliceDomain+'/following.txt').read():
if 'alice@'+aliceDomain+':'+str(alicePort) not in open(bobFollowersFilename).read():
if 'bob@'+bobDomain+':'+str(bobPort) not in open(aliceFollowingFilename).read():
break
time.sleep(1)
assert os.path.isfile(bobDir+'/accounts/bob@'+bobDomain+'/followers.txt')
assert os.path.isfile(aliceDir+'/accounts/alice@'+aliceDomain+'/following.txt')
assert 'alice@'+aliceDomain+':'+str(alicePort) not in open(bobDir+'/accounts/bob@'+bobDomain+'/followers.txt').read()
assert 'bob@'+bobDomain+':'+str(bobPort) not in open(aliceDir+'/accounts/alice@'+aliceDomain+'/following.txt').read()
assert os.path.isfile(bobFollowersFilename)
assert os.path.isfile(aliceFollowingFilename)
assert 'alice@'+aliceDomain+':'+str(alicePort) not in open(bobFollowersFilename).read()
assert 'bob@'+bobDomain+':'+str(bobPort) not in open(aliceFollowingFilename).read()
assert validInbox(bobDir,'bob',bobDomain)
assert validInboxFilenames(bobDir,'bob',bobDomain,aliceDomain,alicePort)
assert validInbox(aliceDir,'alice',aliceDomain)

View File

@ -259,6 +259,7 @@ def followPerson(baseDir: str,nickname: str, domain: str, \
os.mkdir(baseDir+'/accounts')
if not os.path.isdir(baseDir+'/accounts/'+handle):
os.mkdir(baseDir+'/accounts/'+handle)
handleToFollow=followNickname+'@'+followDomain
filename=baseDir+'/accounts/'+handle+'/'+followFile
if os.path.isfile(filename):
if handleToFollow in open(filename).read():
@ -277,7 +278,7 @@ def followPerson(baseDir: str,nickname: str, domain: str, \
except Exception as e:
print('WARN: Failed to write entry to follow file '+filename+' '+str(e))
if debug:
print('DEBUG: creating new following file')
print('DEBUG: creating new following file to follow '+handleToFollow)
with open(filename, "w") as followfile:
followfile.write(handleToFollow+'\n')
return True