mirror of https://gitlab.com/bashrc2/epicyon
Unit test for adding new follow to calendar
parent
8d642fe267
commit
949f54f5f3
|
@ -42,14 +42,19 @@ def receiveCalendarEvents(baseDir: str, nickname: str, domain: str,
|
||||||
indicating whether to receive calendar events from that account
|
indicating whether to receive calendar events from that account
|
||||||
"""
|
"""
|
||||||
# check that a following file exists
|
# check that a following file exists
|
||||||
|
if ':' in domain:
|
||||||
|
domain = domain.split(':')[0]
|
||||||
followingFilename = baseDir + '/accounts/' + \
|
followingFilename = baseDir + '/accounts/' + \
|
||||||
nickname + '@' + domain + '/following.txt'
|
nickname + '@' + domain + '/following.txt'
|
||||||
if not os.path.isfile(followingFilename):
|
if not os.path.isfile(followingFilename):
|
||||||
|
print("WARN: following.txt doesn't exist for " +
|
||||||
|
nickname + '@' + domain)
|
||||||
return
|
return
|
||||||
handle = followingNickname + '@' + followingDomain
|
handle = followingNickname + '@' + followingDomain
|
||||||
|
|
||||||
# check that you are following this handle
|
# check that you are following this handle
|
||||||
if handle + '\n' not in open(followingFilename).read():
|
if handle + '\n' not in open(followingFilename).read():
|
||||||
|
print('WARN: ' + handle + ' is not in ' + followingFilename)
|
||||||
return
|
return
|
||||||
|
|
||||||
calendarFilename = baseDir + '/accounts/' + \
|
calendarFilename = baseDir + '/accounts/' + \
|
||||||
|
@ -59,17 +64,22 @@ def receiveCalendarEvents(baseDir: str, nickname: str, domain: str,
|
||||||
# a set of handles
|
# a set of handles
|
||||||
followingHandles = ''
|
followingHandles = ''
|
||||||
if os.path.isfile(calendarFilename):
|
if os.path.isfile(calendarFilename):
|
||||||
|
print('Calendar file exists')
|
||||||
with open(calendarFilename, 'r') as calendarFile:
|
with open(calendarFilename, 'r') as calendarFile:
|
||||||
followingHandles = calendarFile.read()
|
followingHandles = calendarFile.read()
|
||||||
else:
|
else:
|
||||||
# create a new calendar file from the following file
|
# create a new calendar file from the following file
|
||||||
|
print('Creating calendar file ' + calendarFilename)
|
||||||
|
followingHandles = ''
|
||||||
with open(followingFilename, 'r') as followingFile:
|
with open(followingFilename, 'r') as followingFile:
|
||||||
followingHandles = followingFile.read()
|
followingHandles = followingFile.read()
|
||||||
|
if add:
|
||||||
with open(calendarFilename, 'w+') as fp:
|
with open(calendarFilename, 'w+') as fp:
|
||||||
fp.write(followingHandles)
|
fp.write(followingHandles + handle + '\n')
|
||||||
|
|
||||||
# already in the calendar file?
|
# already in the calendar file?
|
||||||
if handle + '\n' in followingHandles:
|
if handle + '\n' in followingHandles:
|
||||||
|
print(handle + ' exists in followingCalendar.txt')
|
||||||
if add:
|
if add:
|
||||||
# already added
|
# already added
|
||||||
return
|
return
|
||||||
|
@ -78,6 +88,7 @@ def receiveCalendarEvents(baseDir: str, nickname: str, domain: str,
|
||||||
with open(calendarFilename, 'w+') as fp:
|
with open(calendarFilename, 'w+') as fp:
|
||||||
fp.write(followingHandles)
|
fp.write(followingHandles)
|
||||||
else:
|
else:
|
||||||
|
print(handle + ' not in followingCalendar.txt')
|
||||||
# not already in the calendar file
|
# not already in the calendar file
|
||||||
if add:
|
if add:
|
||||||
# append to the list of handles
|
# append to the list of handles
|
||||||
|
|
16
tests.py
16
tests.py
|
@ -777,12 +777,21 @@ def testFollowBetweenServers():
|
||||||
bobDomain + '/followers.txt'):
|
bobDomain + '/followers.txt'):
|
||||||
if os.path.isfile(aliceDir + '/accounts/alice@' +
|
if os.path.isfile(aliceDir + '/accounts/alice@' +
|
||||||
aliceDomain + '/following.txt'):
|
aliceDomain + '/following.txt'):
|
||||||
break
|
if os.path.isfile(aliceDir + '/accounts/alice@' +
|
||||||
|
aliceDomain + '/followingCalendar.txt'):
|
||||||
|
break
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
assert validInbox(bobDir, 'bob', bobDomain)
|
assert validInbox(bobDir, 'bob', bobDomain)
|
||||||
assert validInboxFilenames(bobDir, 'bob', bobDomain,
|
assert validInboxFilenames(bobDir, 'bob', bobDomain,
|
||||||
aliceDomain, alicePort)
|
aliceDomain, alicePort)
|
||||||
|
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 +
|
||||||
|
'/followingCalendar.txt').read()
|
||||||
|
|
||||||
print('\n\n*********************************************************')
|
print('\n\n*********************************************************')
|
||||||
print('Alice sends a message to Bob')
|
print('Alice sends a message to Bob')
|
||||||
|
@ -828,11 +837,6 @@ def testFollowBetweenServers():
|
||||||
thrBob.join()
|
thrBob.join()
|
||||||
assert thrBob.isAlive() is False
|
assert thrBob.isAlive() is False
|
||||||
|
|
||||||
assert 'alice@' + aliceDomain in open(bobDir + '/accounts/bob@' +
|
|
||||||
bobDomain + '/followers.txt').read()
|
|
||||||
assert 'bob@' + bobDomain in open(aliceDir + '/accounts/alice@' +
|
|
||||||
aliceDomain + '/following.txt').read()
|
|
||||||
|
|
||||||
# queue item removed
|
# queue item removed
|
||||||
time.sleep(4)
|
time.sleep(4)
|
||||||
assert len([name for name in os.listdir(queuePath)
|
assert len([name for name in os.listdir(queuePath)
|
||||||
|
|
13
utils.py
13
utils.py
|
@ -369,24 +369,27 @@ def followPerson(baseDir: str, nickname: str, domain: str,
|
||||||
content = f.read()
|
content = f.read()
|
||||||
f.seek(0, 0)
|
f.seek(0, 0)
|
||||||
f.write(handleToFollow + '\n' + content)
|
f.write(handleToFollow + '\n' + content)
|
||||||
if debug:
|
print('DEBUG: follow added')
|
||||||
print('DEBUG: follow added')
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print('WARN: Failed to write entry to follow file ' +
|
print('WARN: Failed to write entry to follow file ' +
|
||||||
filename + ' ' + str(e))
|
filename + ' ' + str(e))
|
||||||
else:
|
else:
|
||||||
# first follow
|
# first follow
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: creating new following file to follow ' +
|
print('DEBUG: ' + handle +
|
||||||
handleToFollow)
|
' creating new following file to follow ' + handleToFollow +
|
||||||
|
', filename is ' + filename)
|
||||||
with open(filename, 'w+') as f:
|
with open(filename, 'w+') as f:
|
||||||
f.write(handleToFollow + '\n')
|
f.write(handleToFollow + '\n')
|
||||||
|
|
||||||
# Default to adding new follows to the calendar.
|
# Default to adding new follows to the calendar.
|
||||||
# Possibly this could be made optional
|
# Possibly this could be made optional
|
||||||
if followFile == 'following.txt':
|
if followFile.endswith('following.txt'):
|
||||||
# if following a person add them to the list of
|
# if following a person add them to the list of
|
||||||
# calendar follows
|
# calendar follows
|
||||||
|
print('DEBUG: adding ' +
|
||||||
|
followNickname + '@' + followDomain + ' to calendar of ' +
|
||||||
|
nickname + '@' + domain)
|
||||||
addPersonToCalendar(baseDir, nickname, domain,
|
addPersonToCalendar(baseDir, nickname, domain,
|
||||||
followNickname, followDomain)
|
followNickname, followDomain)
|
||||||
return True
|
return True
|
||||||
|
|
Loading…
Reference in New Issue