From 6e1f37eabd664a936bed2db99b77d8a04eb73e2e Mon Sep 17 00:00:00 2001 From: Dylan Date: Wed, 28 Sep 2022 23:50:12 +0100 Subject: [PATCH] Misc. changes and coverage excludes --- .gitignore | 2 ++ cache.py | 8 ++++---- configHandler.py | 2 +- run_tests.sh | 1 + twitfix.py | 9 +-------- 5 files changed, 9 insertions(+), 13 deletions(-) create mode 100644 run_tests.sh diff --git a/.gitignore b/.gitignore index e11fb61..74e9504 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,5 @@ admin.env _meta .serverless db/ +.coverage +htmlcov/ \ No newline at end of file diff --git a/cache.py b/cache.py index e66d407..705b8df 100644 --- a/cache.py +++ b/cache.py @@ -8,7 +8,7 @@ import boto3 link_cache_system = config['config']['link_cache'] DYNAMO_CACHE_TBL=None -if link_cache_system=="dynamodb": +if link_cache_system=="dynamodb": # pragma: no cover DYNAMO_CACHE_TBL=config['config']['table'] if link_cache_system == "json": @@ -35,7 +35,7 @@ elif link_cache_system == "db": client = pymongo.MongoClient(config['config']['database'], connect=False) table = config['config']['table'] db = client[table] -elif link_cache_system == "dynamodb": +elif link_cache_system == "dynamodb": # pragma: no cover client = boto3.resource('dynamodb') def serializeUnknown(obj): @@ -57,7 +57,7 @@ def addVnfToLinkCache(video_link, vnf): return None elif link_cache_system == "ram": # FOR TESTS ONLY link_cache[video_link] = vnf - elif link_cache_system == "dynamodb": + elif link_cache_system == "dynamodb": # pragma: no cover vnf["ttl"] = int(vnf["ttl"].strftime('%s')) table = client.Table(DYNAMO_CACHE_TBL) table.put_item( @@ -98,7 +98,7 @@ def getVnfFromLinkCache(video_link): else: print(" ➤ [ X ] Link not in json cache") return None - elif link_cache_system == "dynamodb": + elif link_cache_system == "dynamodb": # pragma: no cover table = client.Table(DYNAMO_CACHE_TBL) response = table.get_item( Key={ diff --git a/configHandler.py b/configHandler.py index 752def5..8fb619d 100644 --- a/configHandler.py +++ b/configHandler.py @@ -3,7 +3,7 @@ import os if ('RUNNING_TESTS' in os.environ): config= {"config":{"link_cache":"ram","database":"","table":"","color":"","appname": "vxTwitter","repo": "https://github.com/dylanpdx/BetterTwitFix","url": "https://vxtwitter.com","combination_method": "local"}} -elif ('RUNNING_SERVERLESS' in os.environ and os.environ['RUNNING_SERVERLESS'] == '1'): +elif ('RUNNING_SERVERLESS' in os.environ and os.environ['RUNNING_SERVERLESS'] == '1'): # pragma: no cover config = { "config":{ "link_cache":os.environ["VXTWITTER_LINK_CACHE"], diff --git a/run_tests.sh b/run_tests.sh new file mode 100644 index 0000000..0300201 --- /dev/null +++ b/run_tests.sh @@ -0,0 +1 @@ +pytest --cov-config=.coveragerc --cov=. --cov-report html \ No newline at end of file diff --git a/twitfix.py b/twitfix.py index b05f969..feb89e0 100644 --- a/twitfix.py +++ b/twitfix.py @@ -158,7 +158,7 @@ def dir(sub_path): return redirect(url, 301) @app.route('/favicon.ico') -def favicon(): +def favicon(): # pragma: no cover return send_from_directory(os.path.join(app.root_path, 'static'), 'favicon.ico',mimetype='image/vnd.microsoft.icon') @app.route("/rendercombined.jpg") @@ -273,13 +273,6 @@ def tweetInfo(url, tweet="", desc="", thumb="", uploader="", screen_name="", pfp } return vnf -def get_tweet_data_from_api(video_link): - print(" ➤ [ + ] Attempting to download tweet info from Twitter API") - twid = int(re.sub(r'\?.*$','',video_link.rsplit("/", 1)[-1])) # gets the tweet ID as a int from the passed url - tweet = twitter_api.statuses.show(_id=twid, tweet_mode="extended") - #print(tweet) # For when I need to poke around and see what a tweet looks like - return tweet - def link_to_vnf_from_tweet_data(tweet,video_link): imgs = ["","","","", ""] print(" ➤ [ + ] Tweet Type: " + tweetType(tweet))