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 return
# are capabilities attached? If so then store them # are capabilities attached? If so then store them
if messageJson['object'].get('capabilities'): if messageJson.get('capabilities'):
if isinstance(messageJson['object']['capabilities'], dict): if isinstance(messageJson['capabilities'], dict):
acceptedDomainFull=acceptedDomain
if acceptedPort:
acceptedDomainFull=acceptedDomain+':'+str(acceptedPort)
capabilitiesGrantedSave(baseDir, \ capabilitiesGrantedSave(baseDir, \
followedNickname,followedDomain, \ nickname,acceptedDomainFull, \
messageJson['object']['capabilities']) messageJson['capabilities'])
if followPerson(baseDir, \ if followPerson(baseDir, \
nickname,acceptedDomain, \ nickname,acceptedDomain, \

View File

@ -91,7 +91,8 @@ def capabilitiesGrantedSave(baseDir :str,nickname :str,domain :str,ocap: {}) ->
""" """
if not ocap.get('actor'): if not ocap.get('actor'):
return False 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: with open(ocapFilename, 'w') as fp:
commentjson.dump(ocap, fp, indent=4, sort_keys=False) commentjson.dump(ocap, fp, indent=4, sort_keys=False)
return True return True

View File

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