mirror of https://gitlab.com/bashrc2/epicyon
Test for unfollowing
parent
dcd0b8eff7
commit
6b3de06ec7
15
follow.py
15
follow.py
|
@ -62,9 +62,12 @@ def followerOfPerson(baseDir: str,nickname: str, domain: str, \
|
||||||
|
|
||||||
def unfollowPerson(baseDir: str,nickname: str, domain: str, \
|
def unfollowPerson(baseDir: str,nickname: str, domain: str, \
|
||||||
followNickname: str, followDomain: str, \
|
followNickname: str, followDomain: str, \
|
||||||
followFile='following.txt') -> bool:
|
followFile='following.txt', \
|
||||||
|
debug=False) -> bool:
|
||||||
"""Removes a person to the follow list
|
"""Removes a person to the follow list
|
||||||
"""
|
"""
|
||||||
|
if ':' in domain:
|
||||||
|
domain=domain.split(':')[0]
|
||||||
handle=nickname.lower()+'@'+domain.lower()
|
handle=nickname.lower()+'@'+domain.lower()
|
||||||
handleToUnfollow=followNickname.lower()+'@'+followDomain.lower()
|
handleToUnfollow=followNickname.lower()+'@'+followDomain.lower()
|
||||||
if not os.path.isdir(baseDir+'/accounts'):
|
if not os.path.isdir(baseDir+'/accounts'):
|
||||||
|
@ -73,8 +76,12 @@ def unfollowPerson(baseDir: str,nickname: str, domain: str, \
|
||||||
os.mkdir(baseDir+'/accounts/'+handle)
|
os.mkdir(baseDir+'/accounts/'+handle)
|
||||||
filename=baseDir+'/accounts/'+handle+'/'+followFile
|
filename=baseDir+'/accounts/'+handle+'/'+followFile
|
||||||
if not os.path.isfile(filename):
|
if not os.path.isfile(filename):
|
||||||
|
if debug:
|
||||||
|
print('DEBUG: follow file '+filename+' was not found')
|
||||||
return False
|
return False
|
||||||
if handleToUnfollow not in open(filename).read():
|
if handleToUnfollow not in open(filename).read():
|
||||||
|
if debug:
|
||||||
|
print('DEBUG: handle to unfollow '+handleToUnfollow+' is not in '+filename)
|
||||||
return
|
return
|
||||||
with open(filename, "r") as f:
|
with open(filename, "r") as f:
|
||||||
lines = f.readlines()
|
lines = f.readlines()
|
||||||
|
@ -84,11 +91,13 @@ def unfollowPerson(baseDir: str,nickname: str, domain: str, \
|
||||||
f.write(line)
|
f.write(line)
|
||||||
|
|
||||||
def unfollowerOfPerson(baseDir: str,nickname: str,domain: str, \
|
def unfollowerOfPerson(baseDir: str,nickname: str,domain: str, \
|
||||||
followerNickname: str,followerDomain: str) -> bool:
|
followerNickname: str,followerDomain: str, \
|
||||||
|
debug=False) -> bool:
|
||||||
"""Remove a follower of a person
|
"""Remove a follower of a person
|
||||||
"""
|
"""
|
||||||
return unfollowPerson(baseDir,nickname,domain, \
|
return unfollowPerson(baseDir,nickname,domain, \
|
||||||
followerNickname,followerDomain,'followers.txt')
|
followerNickname,followerDomain, \
|
||||||
|
'followers.txt',debug)
|
||||||
|
|
||||||
def clearFollows(baseDir: str,nickname: str,domain: str, \
|
def clearFollows(baseDir: str,nickname: str,domain: str, \
|
||||||
followFile='following.txt') -> None:
|
followFile='following.txt') -> None:
|
||||||
|
|
16
inbox.py
16
inbox.py
|
@ -27,6 +27,7 @@ from session import createSession
|
||||||
from session import getJson
|
from session import getJson
|
||||||
from follow import receiveFollowRequest
|
from follow import receiveFollowRequest
|
||||||
from follow import getFollowersOfActor
|
from follow import getFollowersOfActor
|
||||||
|
from follow import unfollowerOfPerson
|
||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
from cache import getPersonFromCache
|
from cache import getPersonFromCache
|
||||||
from cache import storePersonInCache
|
from cache import storePersonInCache
|
||||||
|
@ -74,7 +75,7 @@ def inboxMessageHasParams(messageJson: {}) -> bool:
|
||||||
if not messageJson.get(param):
|
if not messageJson.get(param):
|
||||||
return False
|
return False
|
||||||
if not messageJson.get('to'):
|
if not messageJson.get('to'):
|
||||||
allowedWithoutToParam=['Follow','Request','Capability']
|
allowedWithoutToParam=['Follow','Request','Capability','Undo']
|
||||||
if messageJson['type'] not in allowedWithoutToParam:
|
if messageJson['type'] not in allowedWithoutToParam:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
@ -410,8 +411,17 @@ def receiveUndoFollow(session,baseDir: str,httpPrefix: str, \
|
||||||
if portFollowing!=80 and portFollowing!=443:
|
if portFollowing!=80 and portFollowing!=443:
|
||||||
domainFollowingFull=domainFollowing+':'+str(portFollowing)
|
domainFollowingFull=domainFollowing+':'+str(portFollowing)
|
||||||
|
|
||||||
return unfollowerOfPerson(baseDir,nicknameFollower,domainFollowerFull, \
|
if unfollowerOfPerson(baseDir, \
|
||||||
nicknameFollowing,domainFollowingFull)
|
nicknameFollowing,domainFollowingFull, \
|
||||||
|
nicknameFollower,domainFollowerFull, \
|
||||||
|
debug):
|
||||||
|
if debug:
|
||||||
|
print('DEBUG: Follower '+nicknameFollower+'@'+domainFollowerFull+' was removed')
|
||||||
|
return True
|
||||||
|
|
||||||
|
if debug:
|
||||||
|
print('DEBUG: Follower '+nicknameFollower+'@'+domainFollowerFull+' was not removed')
|
||||||
|
return False
|
||||||
|
|
||||||
def receiveUndo(session,baseDir: str,httpPrefix: str, \
|
def receiveUndo(session,baseDir: str,httpPrefix: str, \
|
||||||
port: int,sendThreads: [],postLog: [], \
|
port: int,sendThreads: [],postLog: [], \
|
||||||
|
|
21
tests.py
21
tests.py
|
@ -33,6 +33,7 @@ from posts import sendPostViaServer
|
||||||
from follow import clearFollows
|
from follow import clearFollows
|
||||||
from follow import clearFollowers
|
from follow import clearFollowers
|
||||||
from follow import sendFollowRequestViaServer
|
from follow import sendFollowRequestViaServer
|
||||||
|
from follow import sendUnfollowRequestViaServer
|
||||||
from utils import followPerson
|
from utils import followPerson
|
||||||
from follow import followerOfPerson
|
from follow import followerOfPerson
|
||||||
from follow import unfollowPerson
|
from follow import unfollowPerson
|
||||||
|
@ -1114,6 +1115,26 @@ def testClientToServer():
|
||||||
assert len([name for name in os.listdir(inboxPath) if os.path.isfile(os.path.join(inboxPath, name))])==1
|
assert len([name for name in os.listdir(inboxPath) if os.path.isfile(os.path.join(inboxPath, name))])==1
|
||||||
print('Post repeated')
|
print('Post repeated')
|
||||||
|
|
||||||
|
|
||||||
|
print('\n\nAlice unfollows Bob')
|
||||||
|
password='alicepass'
|
||||||
|
sendUnfollowRequestViaServer(sessionAlice,'alice',password, \
|
||||||
|
aliceDomain,alicePort, \
|
||||||
|
'bob',bobDomain,bobPort, \
|
||||||
|
httpPrefix, \
|
||||||
|
cachedWebfingers,personCache, \
|
||||||
|
True)
|
||||||
|
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():
|
||||||
|
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()
|
||||||
|
|
||||||
# stop the servers
|
# stop the servers
|
||||||
thrAlice.kill()
|
thrAlice.kill()
|
||||||
thrAlice.join()
|
thrAlice.join()
|
||||||
|
|
Loading…
Reference in New Issue