Check that imports are correct

merge-requests/30/head
Bob Mottram 2020-12-22 13:57:24 +00:00
parent 59357c0c4f
commit 0cf0841402
4 changed files with 39 additions and 28 deletions

View File

@ -87,7 +87,7 @@ from inbox import populateReplies
from inbox import getPersonPubKey from inbox import getPersonPubKey
from follow import getFollowingFeed from follow import getFollowingFeed
from follow import sendFollowRequest from follow import sendFollowRequest
from follow import unfollowPerson from follow import unfollowAccount
from follow import createInitialLastSeen from follow import createInitialLastSeen
from auth import authorize from auth import authorize
from auth import createPassword from auth import createPassword
@ -2115,9 +2115,9 @@ class PubServer(BaseHTTPRequestHandler):
} }
pathUsersSection = path.split('/users/')[1] pathUsersSection = path.split('/users/')[1]
self.postToNickname = pathUsersSection.split('/')[0] self.postToNickname = pathUsersSection.split('/')[0]
unfollowPerson(self.server.baseDir, self.postToNickname, unfollowAccount(self.server.baseDir, self.postToNickname,
self.server.domain, self.server.domain,
followingNickname, followingDomainFull) followingNickname, followingDomainFull)
self._postToOutboxThread(unfollowJson) self._postToOutboxThread(unfollowJson)
if callingDomain.endswith('.onion') and onionDomain: if callingDomain.endswith('.onion') and onionDomain:

View File

@ -212,10 +212,10 @@ def isFollowerOfPerson(baseDir: str, nickname: str, domain: str,
return alreadyFollowing return alreadyFollowing
def unfollowPerson(baseDir: str, nickname: str, domain: str, def unfollowAccount(baseDir: str, nickname: str, domain: str,
followNickname: str, followDomain: str, followNickname: str, followDomain: str,
followFile='following.txt', followFile='following.txt',
debug=False) -> bool: debug=False) -> bool:
"""Removes a person to the follow list """Removes a person to the follow list
""" """
if ':' in domain: if ':' in domain:
@ -261,14 +261,14 @@ def unfollowPerson(baseDir: str, nickname: str, domain: str,
return True return True
def unfollowerOfPerson(baseDir: str, nickname: str, domain: str, def unfollowerOfAccount(baseDir: str, nickname: str, domain: str,
followerNickname: str, followerDomain: str, followerNickname: str, followerDomain: str,
debug=False) -> bool: debug=False) -> bool:
"""Remove a follower of a person """Remove a follower of a person
""" """
return unfollowPerson(baseDir, nickname, domain, return unfollowAccount(baseDir, nickname, domain,
followerNickname, followerDomain, followerNickname, followerDomain,
'followers.txt', debug) 'followers.txt', debug)
def clearFollows(baseDir: str, nickname: str, domain: str, def clearFollows(baseDir: str, nickname: str, domain: str,
@ -1208,8 +1208,8 @@ def outboxUndoFollow(baseDir: str, messageJson: {}, debug: bool) -> None:
getDomainFromActor(messageJson['object']['object']) getDomainFromActor(messageJson['object']['object'])
domainFollowingFull = getFullDomain(domainFollowing, portFollowing) domainFollowingFull = getFullDomain(domainFollowing, portFollowing)
if unfollowPerson(baseDir, nicknameFollower, domainFollowerFull, if unfollowAccount(baseDir, nicknameFollower, domainFollowerFull,
nicknameFollowing, domainFollowingFull): nicknameFollowing, domainFollowingFull):
if debug: if debug:
print('DEBUG: ' + nicknameFollower + ' unfollowed ' + print('DEBUG: ' + nicknameFollower + ' unfollowed ' +
nicknameFollowing + '@' + domainFollowingFull) nicknameFollowing + '@' + domainFollowingFull)

View File

@ -39,7 +39,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 follow import unfollowerOfAccount
from pprint import pprint from pprint import pprint
from cache import getPersonFromCache from cache import getPersonFromCache
from cache import storePersonInCache from cache import storePersonInCache
@ -49,8 +49,8 @@ from bookmarks import undoBookmarksCollectionEntry
from blocking import isBlocked from blocking import isBlocked
from blocking import isBlockedDomain from blocking import isBlockedDomain
from filters import isFiltered from filters import isFiltered
from announce import updateAnnounceCollection from utils import updateAnnounceCollection
from announce import undoAnnounceCollectionEntry from utils import undoAnnounceCollectionEntry
from httpsig import messageContentDigest from httpsig import messageContentDigest
from posts import validContentWarning from posts import validContentWarning
from posts import downloadAnnounce from posts import downloadAnnounce
@ -637,10 +637,10 @@ def receiveUndoFollow(session, baseDir: str, httpPrefix: str,
getDomainFromActor(messageJson['object']['object']) getDomainFromActor(messageJson['object']['object'])
domainFollowingFull = getFullDomain(domainFollowing, portFollowing) domainFollowingFull = getFullDomain(domainFollowing, portFollowing)
if unfollowerOfPerson(baseDir, if unfollowerOfAccount(baseDir,
nicknameFollowing, domainFollowingFull, nicknameFollowing, domainFollowingFull,
nicknameFollower, domainFollowerFull, nicknameFollower, domainFollowerFull,
debug): debug):
print(nicknameFollowing + '@' + domainFollowingFull + ': ' print(nicknameFollowing + '@' + domainFollowingFull + ': '
'Follower ' + nicknameFollower + '@' + domainFollowerFull + 'Follower ' + nicknameFollower + '@' + domainFollowerFull +
' was removed') ' was removed')

View File

@ -49,8 +49,8 @@ from utils import getStatusNumber
from utils import getFollowersOfPerson from utils import getFollowersOfPerson
from utils import removeHtml from utils import removeHtml
from follow import followerOfPerson from follow import followerOfPerson
from follow import unfollowPerson from follow import unfollowAccount
from follow import unfollowerOfPerson from follow import unfollowerOfAccount
from follow import sendFollowRequest from follow import sendFollowRequest
from person import createPerson from person import createPerson
from person import setDisplayNickname from person import setDisplayNickname
@ -73,7 +73,7 @@ from delete import sendDeleteViaServer
from inbox import jsonPostAllowsComments from inbox import jsonPostAllowsComments
from inbox import validInbox from inbox import validInbox
from inbox import validInboxFilenames from inbox import validInboxFilenames
from inbox import guessHashtagCategory from categories import guessHashtagCategory
from content import htmlReplaceEmailQuote from content import htmlReplaceEmailQuote
from content import htmlReplaceQuoteMarks from content import htmlReplaceQuoteMarks
from content import dangerousMarkup from content import dangerousMarkup
@ -978,7 +978,7 @@ def testNoOfFollowersOnDomain():
noOfFollowersOnDomain(baseDir, nickname + '@' + domain, otherdomain) noOfFollowersOnDomain(baseDir, nickname + '@' + domain, otherdomain)
assert followersOnOtherDomain == 3 assert followersOnOtherDomain == 3
unfollowerOfPerson(baseDir, nickname, domain, 'sausagedog', otherdomain) unfollowerOfAccount(baseDir, nickname, domain, 'sausagedog', otherdomain)
followersOnOtherDomain = \ followersOnOtherDomain = \
noOfFollowersOnDomain(baseDir, nickname + '@' + domain, otherdomain) noOfFollowersOnDomain(baseDir, nickname + '@' + domain, otherdomain)
assert followersOnOtherDomain == 2 assert followersOnOtherDomain == 2
@ -1074,7 +1074,7 @@ def testFollows():
assert(False) assert(False)
assert(domainFound) assert(domainFound)
unfollowPerson(baseDir, nickname, domain, 'batman', 'mesh.com') unfollowAccount(baseDir, nickname, domain, 'batman', 'mesh.com')
domainFound = False domainFound = False
for followingDomain in f: for followingDomain in f:
@ -2614,6 +2614,9 @@ def testFunctions():
'E2EEremoveDevice', 'E2EEremoveDevice',
'setOrganizationScheme' 'setOrganizationScheme'
] ]
excludeImports = [
'link'
]
# check that functions are called somewhere # check that functions are called somewhere
for name, properties in functionProperties.items(): for name, properties in functionProperties.items():
if name in exclusions: if name in exclusions:
@ -2623,6 +2626,14 @@ def testFunctions():
' in module ' + properties['module'] + ' in module ' + properties['module'] +
' is not called anywhere') ' is not called anywhere')
assert properties['calledInModule'] assert properties['calledInModule']
if name not in excludeImports:
for modName in properties['calledInModule']:
if modName == properties['module']:
continue
importStr = 'from ' + properties['module'] + ' import ' + name
if importStr not in open(modName + '.py').read():
print(importStr + ' not found in ' + modName + '.py')
assert False
print('Function: ' + name + '') print('Function: ' + name + '')
# print(str(function)) # print(str(function))
# print(str(functionProperties)) # print(str(functionProperties))