From f3011396269f02bff26a36aa089cfc96255da7e9 Mon Sep 17 00:00:00 2001
From: Bob Mottram <bob@freedombone.net>
Date: Thu, 11 Jul 2019 13:59:00 +0100
Subject: [PATCH] Receiving likes

---
 epicyon.py |  5 -----
 inbox.py   |  4 ++--
 tests.py   | 64 ++++++++++++++++++++++++++----------------------------
 3 files changed, 33 insertions(+), 40 deletions(-)

diff --git a/epicyon.py b/epicyon.py
index 987ef53b..fb3b9f83 100644
--- a/epicyon.py
+++ b/epicyon.py
@@ -388,7 +388,6 @@ if args.changepassword:
 if not args.domain and not domain:
     print('Specify a domain with --domain [name]')
     sys.exit()
-    
 
 if federationList:
     print('Federating with: '+str(federationList))
@@ -400,10 +399,6 @@ if not os.path.isdir(baseDir+'/accounts/'+nickname+'@'+domain):
     setConfigParam(baseDir,'adminPassword',adminPassword)
     createPerson(baseDir,nickname,domain,port,httpPrefix,True,adminPassword)
 
-#if not os.path.isdir(baseDir+'/accounts/capabilities@'+domain):
-#    print('Creating capabilities account which can sign requests')
-#    createCapabilitiesInbox(baseDir,'capabilities',domain,port,httpPrefix)
-
 if args.testdata:
     nickname='testuser567'
     print('Generating some test data for user: '+nickname)
diff --git a/inbox.py b/inbox.py
index d1cb8a96..0c55791d 100644
--- a/inbox.py
+++ b/inbox.py
@@ -432,8 +432,8 @@ def receiveLike(session,handle: str,baseDir: str, \
             print(messageJson['object'])
         return True
     if debug:
-        print('DEBUG: liked post found in '+boxName)
-    updateLikesCollection(postFilename,messageJson['object'],messageJson['actor'])
+        print('DEBUG: liked post found in inbox')
+    updateLikesCollection(postFilename,messageJson['object'],messageJson['actor'],debug)
     return True
 
 def inboxAfterCapabilities(session,keyId: str,handle: str,messageJson: {}, \
diff --git a/tests.py b/tests.py
index cad06654..87abce40 100644
--- a/tests.py
+++ b/tests.py
@@ -278,43 +278,41 @@ def testPostMessageBetweenServers():
     # queue item removed
     assert len([name for name in os.listdir(queuePath) if os.path.isfile(os.path.join(queuePath, name))])==0
 
-    #print('\n\n*******************************************************')
-    #print("Bob likes Alice's post")
+    print('\n\n*******************************************************')
+    print("Bob likes Alice's post")
 
-    #followerOfPerson(bobDir,'bob',bobDomain,'alice',aliceDomain+':'+str(alicePort),federationList,True)
-    #followPerson(aliceDir,'alice',aliceDomain,'bob',bobDomain+':'+str(bobPort),federationList,True)
-    #followList=getFollowersOfPerson(bobDir,'bob',bobDomain,'followers.txt')
-    #assert len(followList)==1
+    followerOfPerson(bobDir,'bob',bobDomain,'alice',aliceDomain+':'+str(alicePort),federationList,True)
+    followPerson(aliceDir,'alice',aliceDomain,'bob',bobDomain+':'+str(bobPort),federationList,True)
 
-    #sessionBob = createSession(bobDomain,bobPort,useTor)
-    #bobSendThreads = []
-    #bobPostLog = []
-    #bobPersonCache={}
-    #bobCachedWebfingers={}
-    #statusNumber=None
-    #outboxPostFilename=None
-    #outboxPath=aliceDir+'/accounts/alice@'+aliceDomain+'/outbox'
-    #for name in os.listdir(outboxPath):
-    #    if '#statuses#' in name:
-    #        statusNumber=int(name.split('#statuses#')[1].replace('.json',''))
-    #        outboxPostFilename=outboxPath+'/'+name
-    #assert statusNumber
-    #assert outboxPostFilename
-    #assert likePost(sessionBob,bobDir,federationList, \
-    #                'bob',bobDomain,bobPort,httpPrefix, \
-    #                'alice',aliceDomain,alicePort,[], \
-    #                statusNumber,False,bobSendThreads,bobPostLog, \
-    #                bobPersonCache,bobCachedWebfingers,True)
+    sessionBob = createSession(bobDomain,bobPort,useTor)
+    bobSendThreads = []
+    bobPostLog = []
+    bobPersonCache={}
+    bobCachedWebfingers={}
+    statusNumber=None
+    outboxPostFilename=None
+    outboxPath=aliceDir+'/accounts/alice@'+aliceDomain+'/outbox'
+    for name in os.listdir(outboxPath):
+        if '#statuses#' in name:
+            statusNumber=int(name.split('#statuses#')[1].replace('.json',''))
+            outboxPostFilename=outboxPath+'/'+name
+    assert statusNumber
+    assert outboxPostFilename
+    assert likePost(sessionBob,bobDir,federationList, \
+                    'bob',bobDomain,bobPort,httpPrefix, \
+                    'alice',aliceDomain,alicePort,[], \
+                    statusNumber,False,bobSendThreads,bobPostLog, \
+                    bobPersonCache,bobCachedWebfingers,True)
 
-    #for i in range(20):
-    #    if 'likes' in open(outboxPostFilename).read():
-    #        break
-    #    time.sleep(1)
+    for i in range(20):
+        if 'likes' in open(outboxPostFilename).read():
+            break
+        time.sleep(1)
 
-    #with open(outboxPostFilename, 'r') as fp:
-    #    alicePostJson=commentjson.load(fp)
-    #    pprint(alicePostJson)
-    #assert 'likes' in open(outboxPostFilename).read()
+    with open(outboxPostFilename, 'r') as fp:
+        alicePostJson=commentjson.load(fp)
+        pprint(alicePostJson)
+    assert 'likes' in open(outboxPostFilename).read()
     
     # stop the servers
     thrAlice.kill()