Test for cache

master
Bob Mottram 2019-06-30 17:29:53 +01:00
parent e485010e4e
commit 687c4378da
3 changed files with 15 additions and 3 deletions

View File

@ -33,7 +33,7 @@ def getPersonFromCache(personUrl: str):
if personCache.get(personUrl):
# how old is the cached data?
currTime=datetime.datetime.utcnow()
cacheTime=datetime.strptime(personCache[personUrl]['timestamp'].replace('T',' '))
cacheTime=datetime.datetime.strptime(personCache[personUrl]['timestamp'],"%Y-%m-%dT%H:%M:%SZ")
daysSinceCached=(currTime - cacheTime).days
# return cached value if it has not expired
if daysSinceCached <= 2:
@ -46,3 +46,13 @@ def getWebfingerFromCache(handle: str):
if cachedWebfingers.get(handle):
return cachedWebfingers[handle]
return None
def testCache():
print('testCache')
personUrl="cat@cardboard.box"
personJson={ "id": 123456, "test": "This is a test" }
storePersonInCache(personUrl,personJson)
result=getPersonFromCache(personUrl)
assert result['id']==123456
assert result['test']=='This is a test'

View File

@ -13,6 +13,7 @@ import cgi
from pprint import pprint
from session import createSession
from httpsig import testHttpsig
from cache import testCache
from webfinger import webfingerMeta
from webfinger import webfingerLookup
from person import personLookup
@ -218,6 +219,7 @@ def runDaemon(domain: str,port=80,fedList=[],useTor=False) -> None:
print('Running tests...')
testHttpsig()
testCache()
print('Tests succeeded\n')
serverAddress = ('', port)

View File

@ -32,10 +32,10 @@ from follow import followerOfPerson
from follow import unfollowPerson
from follow import unfollowerOfPerson
federationList=['mastodon.social','wild.com','trees.com']
federationList=['mastodon.social','wild.com','trees.com','127.0.0.1']
username='testuser'
#domain=socket.gethostname()
domain='mydomain.com'
domain='127.0.0.1'
port=6227
https=True
useTor=False