From 687c4378da61111de25530d3d3bdf2fe7700eb0f Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sun, 30 Jun 2019 17:29:53 +0100 Subject: [PATCH] Test for cache --- cache.py | 12 +++++++++++- daemon.py | 2 ++ epicyon.py | 4 ++-- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/cache.py b/cache.py index 8604b235c..01f875f45 100644 --- a/cache.py +++ b/cache.py @@ -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' + diff --git a/daemon.py b/daemon.py index a452e4fc4..e311828a0 100644 --- a/daemon.py +++ b/daemon.py @@ -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) diff --git a/epicyon.py b/epicyon.py index 72de8a78c..47449a160 100644 --- a/epicyon.py +++ b/epicyon.py @@ -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