From 3addf30a9bc0893e5801982672f791d09bb321ee Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sun, 7 Jul 2019 17:06:38 +0100 Subject: [PATCH] Test for follow capabilities creation --- acceptreject.py | 11 +++++++---- capabilities.py | 3 ++- tests.py | 6 ++++-- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/acceptreject.py b/acceptreject.py index fd8daed5..6d9a65c8 100644 --- a/acceptreject.py +++ b/acceptreject.py @@ -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, \ diff --git a/capabilities.py b/capabilities.py index 0c13d221..9e3e6e31 100644 --- a/capabilities.py +++ b/capabilities.py @@ -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 diff --git a/tests.py b/tests.py index 77bade8f..2f62b6bc 100644 --- a/tests.py +++ b/tests.py @@ -314,7 +314,8 @@ 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'): - break + if os.path.isfile(aliceDir+'/ocap/granted/'+aliceDomain+':'+str(alicePort)+':alice:'+httpPrefix+':##'+bobDomain+':'+str(bobPort)+'#users#bob.json'): + break time.sleep(1) # stop the servers @@ -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')