Test for follow capabilities creation

master
Bob Mottram 2019-07-07 17:06:38 +01:00
parent 994ce34a76
commit 3addf30a9b
3 changed files with 13 additions and 7 deletions

View File

@ -138,11 +138,14 @@ def acceptFollow(baseDir: str,domain : str,messageJson: {}, \
return
# are capabilities attached? If so then store them
if messageJson['object'].get('capabilities'):
if isinstance(messageJson['object']['capabilities'], dict):
if messageJson.get('capabilities'):
if isinstance(messageJson['capabilities'], dict):
acceptedDomainFull=acceptedDomain
if acceptedPort:
acceptedDomainFull=acceptedDomain+':'+str(acceptedPort)
capabilitiesGrantedSave(baseDir, \
followedNickname,followedDomain, \
messageJson['object']['capabilities'])
nickname,acceptedDomainFull, \
messageJson['capabilities'])
if followPerson(baseDir, \
nickname,acceptedDomain, \

View File

@ -91,7 +91,8 @@ def capabilitiesGrantedSave(baseDir :str,nickname :str,domain :str,ocap: {}) ->
"""
if not ocap.get('actor'):
return False
ocapFilename=getOcapFilename(baseDir,nickname,fullDomain,ocap['actor'],'granted')
capabilitiesMakeDirs(baseDir)
ocapFilename=getOcapFilename(baseDir,nickname,domain,ocap['actor'],'granted')
with open(ocapFilename, 'w') as fp:
commentjson.dump(ocap, fp, indent=4, sort_keys=False)
return True

View File

@ -314,6 +314,7 @@ def testFollowBetweenServers():
if os.path.isfile(bobDir+'/accounts/bob@'+bobDomain+'/followers.txt'):
if os.path.isfile(aliceDir+'/accounts/alice@'+aliceDomain+'/following.txt'):
if os.path.isfile(bobDir+'/ocap/accept/'+bobDomain+':'+str(bobPort)+':bob:'+httpPrefix+':##'+aliceDomain+':'+str(alicePort)+'#users#alice.json'):
if os.path.isfile(aliceDir+'/ocap/granted/'+aliceDomain+':'+str(alicePort)+':alice:'+httpPrefix+':##'+bobDomain+':'+str(bobPort)+'#users#bob.json'):
break
time.sleep(1)
@ -327,11 +328,12 @@ def testFollowBetweenServers():
assert thrBob.isAlive()==False
assert os.path.isfile(bobDir+'/ocap/accept/'+bobDomain+':'+str(bobPort)+':bob:'+httpPrefix+':##'+aliceDomain+':'+str(alicePort)+'#users#alice.json')
assert os.path.isfile(aliceDir+'/ocap/granted/'+aliceDomain+':'+str(alicePort)+':alice:'+httpPrefix+':##'+bobDomain+':'+str(bobPort)+'#users#bob.json')
assert 'alice@'+aliceDomain in open(bobDir+'/accounts/bob@'+bobDomain+'/followers.txt').read()
assert 'bob@'+bobDomain in open(aliceDir+'/accounts/alice@'+aliceDomain+'/following.txt').read()
os.chdir(baseDir)
#shutil.rmtree(baseDir+'/.tests')
shutil.rmtree(baseDir+'/.tests')
def testFollowersOfPerson():
print('testFollowersOfPerson')