mirror of https://gitlab.com/bashrc2/epicyon
Fix network unit tests
parent
6f1bdfb1b1
commit
9e46a45eb1
9
inbox.py
9
inbox.py
|
@ -225,17 +225,26 @@ def validInboxFilenames(baseDir: str, nickname: str, domain: str,
|
||||||
return True
|
return True
|
||||||
expectedStr = expectedDomain + ':' + str(expectedPort)
|
expectedStr = expectedDomain + ':' + str(expectedPort)
|
||||||
expectedFound = False
|
expectedFound = False
|
||||||
|
ctr = 0
|
||||||
for subdir, dirs, files in os.walk(inboxDir):
|
for subdir, dirs, files in os.walk(inboxDir):
|
||||||
for f in files:
|
for f in files:
|
||||||
filename = os.path.join(subdir, f)
|
filename = os.path.join(subdir, f)
|
||||||
|
ctr += 1
|
||||||
if not os.path.isfile(filename):
|
if not os.path.isfile(filename):
|
||||||
print('filename: ' + filename)
|
print('filename: ' + filename)
|
||||||
return False
|
return False
|
||||||
if expectedStr in filename:
|
if expectedStr in filename:
|
||||||
expectedFound = True
|
expectedFound = True
|
||||||
break
|
break
|
||||||
|
if ctr == 0:
|
||||||
|
return True
|
||||||
if not expectedFound:
|
if not expectedFound:
|
||||||
print('Expected file was not found: ' + expectedStr)
|
print('Expected file was not found: ' + expectedStr)
|
||||||
|
for subdir, dirs, files in os.walk(inboxDir):
|
||||||
|
for f in files:
|
||||||
|
filename = os.path.join(subdir, f)
|
||||||
|
print(filename)
|
||||||
|
break
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
128
tests.py
128
tests.py
|
@ -2391,6 +2391,18 @@ def _testCreatePerson():
|
||||||
shutil.rmtree(baseDir)
|
shutil.rmtree(baseDir)
|
||||||
|
|
||||||
|
|
||||||
|
def showTestBoxes(name: str, inboxPath: str, outboxPath: str) -> None:
|
||||||
|
inboxPosts = \
|
||||||
|
len([name for name in os.listdir(inboxPath)
|
||||||
|
if os.path.isfile(os.path.join(inboxPath, name))])
|
||||||
|
outboxPosts = \
|
||||||
|
len([name for name in os.listdir(outboxPath)
|
||||||
|
if os.path.isfile(os.path.join(outboxPath, name))])
|
||||||
|
print('EVENT: ' + name +
|
||||||
|
' inbox has ' + str(inboxPosts) + ' posts and ' +
|
||||||
|
str(outboxPosts) + ' outbox posts')
|
||||||
|
|
||||||
|
|
||||||
def _testAuthentication():
|
def _testAuthentication():
|
||||||
print('testAuthentication')
|
print('testAuthentication')
|
||||||
currDir = os.getcwd()
|
currDir = os.getcwd()
|
||||||
|
@ -2432,7 +2444,7 @@ def _testAuthentication():
|
||||||
|
|
||||||
|
|
||||||
def testClientToServer():
|
def testClientToServer():
|
||||||
print('Testing sending a post via c2s')
|
print('EVENT: Testing sending a post via c2s')
|
||||||
|
|
||||||
global testServerAliceRunning
|
global testServerAliceRunning
|
||||||
global testServerBobRunning
|
global testServerBobRunning
|
||||||
|
@ -2509,7 +2521,7 @@ def testClientToServer():
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
print('\n\n*******************************************************')
|
print('\n\n*******************************************************')
|
||||||
print('Alice sends to Bob via c2s')
|
print('EVENT: Alice sends to Bob via c2s')
|
||||||
|
|
||||||
sessionAlice = createSession(proxyType)
|
sessionAlice = createSession(proxyType)
|
||||||
followersOnly = False
|
followersOnly = False
|
||||||
|
@ -2522,12 +2534,25 @@ def testClientToServer():
|
||||||
personCache = {}
|
personCache = {}
|
||||||
password = 'alicepass'
|
password = 'alicepass'
|
||||||
conversationId = None
|
conversationId = None
|
||||||
|
|
||||||
|
aliceInboxPath = aliceDir + '/accounts/alice@' + aliceDomain + '/inbox'
|
||||||
|
aliceOutboxPath = aliceDir + '/accounts/alice@' + aliceDomain + '/outbox'
|
||||||
|
bobInboxPath = bobDir + '/accounts/bob@' + bobDomain + '/inbox'
|
||||||
|
bobOutboxPath = bobDir + '/accounts/bob@' + bobDomain + '/outbox'
|
||||||
|
|
||||||
outboxPath = aliceDir + '/accounts/alice@' + aliceDomain + '/outbox'
|
outboxPath = aliceDir + '/accounts/alice@' + aliceDomain + '/outbox'
|
||||||
inboxPath = bobDir + '/accounts/bob@' + bobDomain + '/inbox'
|
inboxPath = bobDir + '/accounts/bob@' + bobDomain + '/inbox'
|
||||||
assert len([name for name in os.listdir(outboxPath)
|
showTestBoxes('alice', aliceInboxPath, aliceOutboxPath)
|
||||||
if os.path.isfile(os.path.join(outboxPath, name))]) == 0
|
showTestBoxes('bob', bobInboxPath, bobOutboxPath)
|
||||||
assert len([name for name in os.listdir(inboxPath)
|
assert len([name for name in os.listdir(aliceInboxPath)
|
||||||
if os.path.isfile(os.path.join(inboxPath, name))]) == 0
|
if os.path.isfile(os.path.join(aliceInboxPath, name))]) == 0
|
||||||
|
assert len([name for name in os.listdir(aliceOutboxPath)
|
||||||
|
if os.path.isfile(os.path.join(aliceOutboxPath, name))]) == 0
|
||||||
|
assert len([name for name in os.listdir(bobInboxPath)
|
||||||
|
if os.path.isfile(os.path.join(bobInboxPath, name))]) == 0
|
||||||
|
assert len([name for name in os.listdir(bobOutboxPath)
|
||||||
|
if os.path.isfile(os.path.join(bobOutboxPath, name))]) == 0
|
||||||
|
print('EVENT: all inboxes and outboxes are empty')
|
||||||
sendResult = \
|
sendResult = \
|
||||||
sendPostViaServer(__version__,
|
sendPostViaServer(__version__,
|
||||||
aliceDir, sessionAlice, 'alice', password,
|
aliceDir, sessionAlice, 'alice', password,
|
||||||
|
@ -2550,23 +2575,32 @@ def testClientToServer():
|
||||||
break
|
break
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
assert len([name for name in os.listdir(outboxPath)
|
showTestBoxes('alice', aliceInboxPath, aliceOutboxPath)
|
||||||
if os.path.isfile(os.path.join(outboxPath, name))]) == 1
|
showTestBoxes('bob', bobInboxPath, bobOutboxPath)
|
||||||
print(">>> c2s post arrived in Alice's outbox")
|
assert len([name for name in os.listdir(aliceInboxPath)
|
||||||
|
if os.path.isfile(os.path.join(aliceInboxPath, name))]) == 0
|
||||||
|
assert len([name for name in os.listdir(aliceOutboxPath)
|
||||||
|
if os.path.isfile(os.path.join(aliceOutboxPath, name))]) == 1
|
||||||
|
print(">>> c2s post arrived in Alice's outbox\n\n\n")
|
||||||
|
|
||||||
for i in range(30):
|
for i in range(30):
|
||||||
if os.path.isdir(inboxPath):
|
if os.path.isdir(inboxPath):
|
||||||
if len([name for name in os.listdir(inboxPath)
|
if len([name for name in os.listdir(bobInboxPath)
|
||||||
if os.path.isfile(os.path.join(inboxPath, name))]) == 1:
|
if os.path.isfile(os.path.join(bobInboxPath, name))]) == 1:
|
||||||
break
|
break
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
assert len([name for name in os.listdir(inboxPath)
|
showTestBoxes('alice', aliceInboxPath, aliceOutboxPath)
|
||||||
if os.path.isfile(os.path.join(inboxPath, name))]) == 1
|
showTestBoxes('bob', bobInboxPath, bobOutboxPath)
|
||||||
print(">>> s2s post arrived in Bob's inbox")
|
assert len([name for name in os.listdir(bobInboxPath)
|
||||||
print("c2s send success")
|
if os.path.isfile(os.path.join(bobInboxPath, name))]) == 1
|
||||||
|
assert len([name for name in os.listdir(bobOutboxPath)
|
||||||
|
if os.path.isfile(os.path.join(bobOutboxPath, name))]) == 0
|
||||||
|
|
||||||
print('\n\nGetting message id for the post')
|
print(">>> s2s post arrived in Bob's inbox")
|
||||||
|
print("c2s send success\n\n\n")
|
||||||
|
|
||||||
|
print('\n\nEVENT: Getting message id for the post')
|
||||||
statusNumber = 0
|
statusNumber = 0
|
||||||
outboxPostFilename = None
|
outboxPostFilename = None
|
||||||
outboxPostId = None
|
outboxPostId = None
|
||||||
|
@ -2626,7 +2660,7 @@ def testClientToServer():
|
||||||
assert validInboxFilenames(bobDir, 'bob', bobDomain,
|
assert validInboxFilenames(bobDir, 'bob', bobDomain,
|
||||||
aliceDomain, alicePort)
|
aliceDomain, alicePort)
|
||||||
|
|
||||||
print('\n\nBob follows Alice')
|
print('\n\nEVENT: Bob follows Alice')
|
||||||
sendFollowRequestViaServer(aliceDir, sessionAlice,
|
sendFollowRequestViaServer(aliceDir, sessionAlice,
|
||||||
'bob', 'bobpass',
|
'bob', 'bobpass',
|
||||||
bobDomain, bobPort,
|
bobDomain, bobPort,
|
||||||
|
@ -2666,19 +2700,23 @@ def testClientToServer():
|
||||||
assert 'alice@' + aliceDomain + ':' + str(alicePort) in \
|
assert 'alice@' + aliceDomain + ':' + str(alicePort) in \
|
||||||
open(bobDir + '/accounts/bob@' + bobDomain + '/following.txt').read()
|
open(bobDir + '/accounts/bob@' + bobDomain + '/following.txt').read()
|
||||||
|
|
||||||
print('\n\nBob likes the post')
|
|
||||||
sessionBob = createSession(proxyType)
|
sessionBob = createSession(proxyType)
|
||||||
password = 'bobpass'
|
password = 'bobpass'
|
||||||
outboxPath = bobDir + '/accounts/bob@' + bobDomain + '/outbox'
|
outboxPath = bobDir + '/accounts/bob@' + bobDomain + '/outbox'
|
||||||
inboxPath = aliceDir + '/accounts/alice@' + aliceDomain + '/inbox'
|
inboxPath = aliceDir + '/accounts/alice@' + aliceDomain + '/inbox'
|
||||||
print(str(len([name for name in os.listdir(outboxPath)
|
print(str(len([name for name in os.listdir(bobOutboxPath)
|
||||||
if os.path.isfile(os.path.join(outboxPath, name))])))
|
if os.path.isfile(os.path.join(bobOutboxPath, name))])))
|
||||||
assert len([name for name in os.listdir(outboxPath)
|
showTestBoxes('alice', aliceInboxPath, aliceOutboxPath)
|
||||||
if os.path.isfile(os.path.join(outboxPath, name))]) == 1
|
showTestBoxes('bob', bobInboxPath, bobOutboxPath)
|
||||||
print(str(len([name for name in os.listdir(inboxPath)
|
assert len([name for name in os.listdir(bobOutboxPath)
|
||||||
if os.path.isfile(os.path.join(inboxPath, name))])))
|
if os.path.isfile(os.path.join(bobOutboxPath, name))]) == 1
|
||||||
assert len([name for name in os.listdir(inboxPath)
|
print(str(len([name for name in os.listdir(aliceInboxPath)
|
||||||
if os.path.isfile(os.path.join(inboxPath, name))]) == 1
|
if os.path.isfile(os.path.join(aliceInboxPath, name))])))
|
||||||
|
showTestBoxes('alice', aliceInboxPath, aliceOutboxPath)
|
||||||
|
showTestBoxes('bob', bobInboxPath, bobOutboxPath)
|
||||||
|
assert len([name for name in os.listdir(aliceInboxPath)
|
||||||
|
if os.path.isfile(os.path.join(aliceInboxPath, name))]) == 0
|
||||||
|
print('\n\nEVENT: Bob likes the post')
|
||||||
sendLikeViaServer(bobDir, sessionBob,
|
sendLikeViaServer(bobDir, sessionBob,
|
||||||
'bob', 'bobpass',
|
'bob', 'bobpass',
|
||||||
bobDomain, bobPort,
|
bobDomain, bobPort,
|
||||||
|
@ -2694,21 +2732,27 @@ def testClientToServer():
|
||||||
if test == 1:
|
if test == 1:
|
||||||
break
|
break
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
assert len([name for name in os.listdir(outboxPath)
|
showTestBoxes('alice', aliceInboxPath, aliceOutboxPath)
|
||||||
if os.path.isfile(os.path.join(outboxPath, name))]) == 2
|
showTestBoxes('bob', bobInboxPath, bobOutboxPath)
|
||||||
assert len([name for name in os.listdir(inboxPath)
|
assert len([name for name in os.listdir(bobOutboxPath)
|
||||||
if os.path.isfile(os.path.join(inboxPath, name))]) == 1
|
if os.path.isfile(os.path.join(bobOutboxPath, name))]) == 2
|
||||||
print('Post liked')
|
assert len([name for name in os.listdir(aliceInboxPath)
|
||||||
|
if os.path.isfile(os.path.join(aliceInboxPath, name))]) == 0
|
||||||
|
print('EVENT: Post liked')
|
||||||
|
|
||||||
print('\n\nBob repeats the post')
|
|
||||||
print(str(len([name for name in os.listdir(outboxPath)
|
print(str(len([name for name in os.listdir(outboxPath)
|
||||||
if os.path.isfile(os.path.join(outboxPath, name))])))
|
if os.path.isfile(os.path.join(outboxPath, name))])))
|
||||||
|
showTestBoxes('alice', aliceInboxPath, aliceOutboxPath)
|
||||||
|
showTestBoxes('bob', bobInboxPath, bobOutboxPath)
|
||||||
assert len([name for name in os.listdir(outboxPath)
|
assert len([name for name in os.listdir(outboxPath)
|
||||||
if os.path.isfile(os.path.join(outboxPath, name))]) == 2
|
if os.path.isfile(os.path.join(outboxPath, name))]) == 2
|
||||||
print(str(len([name for name in os.listdir(inboxPath)
|
print(str(len([name for name in os.listdir(inboxPath)
|
||||||
if os.path.isfile(os.path.join(inboxPath, name))])))
|
if os.path.isfile(os.path.join(inboxPath, name))])))
|
||||||
assert len([name for name in os.listdir(inboxPath)
|
assert len([name for name in os.listdir(aliceInboxPath)
|
||||||
if os.path.isfile(os.path.join(inboxPath, name))]) == 1
|
if os.path.isfile(os.path.join(aliceInboxPath, name))]) == 0
|
||||||
|
showTestBoxes('alice', aliceInboxPath, aliceOutboxPath)
|
||||||
|
showTestBoxes('bob', bobInboxPath, bobOutboxPath)
|
||||||
|
print('\n\nEVENT: Bob repeats the post')
|
||||||
sendAnnounceViaServer(bobDir, sessionBob, 'bob', password,
|
sendAnnounceViaServer(bobDir, sessionBob, 'bob', password,
|
||||||
bobDomain, bobPort,
|
bobDomain, bobPort,
|
||||||
httpPrefix, outboxPostId,
|
httpPrefix, outboxPostId,
|
||||||
|
@ -2724,18 +2768,20 @@ def testClientToServer():
|
||||||
break
|
break
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
assert len([name for name in os.listdir(outboxPath)
|
showTestBoxes('alice', aliceInboxPath, aliceOutboxPath)
|
||||||
if os.path.isfile(os.path.join(outboxPath, name))]) == 3
|
showTestBoxes('bob', bobInboxPath, bobOutboxPath)
|
||||||
assert len([name for name in os.listdir(inboxPath)
|
assert len([name for name in os.listdir(bobOutboxPath)
|
||||||
if os.path.isfile(os.path.join(inboxPath, name))]) == 2
|
if os.path.isfile(os.path.join(bobOutboxPath, name))]) == 3
|
||||||
print('Post repeated')
|
assert len([name for name in os.listdir(aliceInboxPath)
|
||||||
|
if os.path.isfile(os.path.join(aliceInboxPath, name))]) == 1
|
||||||
|
print('EVENT: Post repeated')
|
||||||
|
|
||||||
inboxPath = bobDir + '/accounts/bob@' + bobDomain + '/inbox'
|
inboxPath = bobDir + '/accounts/bob@' + bobDomain + '/inbox'
|
||||||
outboxPath = aliceDir + '/accounts/alice@' + aliceDomain + '/outbox'
|
outboxPath = aliceDir + '/accounts/alice@' + aliceDomain + '/outbox'
|
||||||
postsBefore = \
|
postsBefore = \
|
||||||
len([name for name in os.listdir(inboxPath)
|
len([name for name in os.listdir(inboxPath)
|
||||||
if os.path.isfile(os.path.join(inboxPath, name))])
|
if os.path.isfile(os.path.join(inboxPath, name))])
|
||||||
print('\n\nAlice deletes her post: ' + outboxPostId + ' ' +
|
print('\n\nEVENT: Alice deletes her post: ' + outboxPostId + ' ' +
|
||||||
str(postsBefore))
|
str(postsBefore))
|
||||||
password = 'alicepass'
|
password = 'alicepass'
|
||||||
sendDeleteViaServer(aliceDir, sessionAlice, 'alice', password,
|
sendDeleteViaServer(aliceDir, sessionAlice, 'alice', password,
|
||||||
|
@ -2759,7 +2805,7 @@ def testClientToServer():
|
||||||
assert validInboxFilenames(bobDir, 'bob', bobDomain,
|
assert validInboxFilenames(bobDir, 'bob', bobDomain,
|
||||||
aliceDomain, alicePort)
|
aliceDomain, alicePort)
|
||||||
|
|
||||||
print('\n\nAlice unfollows Bob')
|
print('\n\nEVENT: Alice unfollows Bob')
|
||||||
password = 'alicepass'
|
password = 'alicepass'
|
||||||
sendUnfollowRequestViaServer(baseDir, sessionAlice,
|
sendUnfollowRequestViaServer(baseDir, sessionAlice,
|
||||||
'alice', password,
|
'alice', password,
|
||||||
|
|
Loading…
Reference in New Issue