From bc52ebb27807e157a2c1d38abe45dc4d35a9300a Mon Sep 17 00:00:00 2001 From: Nicholas Charriere Date: Mon, 18 Jul 2016 11:26:33 -0700 Subject: [PATCH 1/4] Add virtualenv env/ to gitignore Add python standardized .gitignore --- .gitignore | 50 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 2950c9d..b2e0c88 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,51 @@ -.tox -.coverage .project *.rdb junit*xml + +env/ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +env/ +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +*.egg-info/ +.installed.cfg +*.egg + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache + +# virtualenv +venv/ +ENV/ From db1ef7673e4452c52a67639ed74d72ea9ce7653e Mon Sep 17 00:00:00 2001 From: Nicholas Charriere Date: Mon, 18 Jul 2016 11:52:37 -0700 Subject: [PATCH 2/4] Make flake8 test pass --- snappass/main.py | 13 ++++++++----- tests.py | 5 ++--- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/snappass/main.py b/snappass/main.py index 88f53c9..9dd8f61 100644 --- a/snappass/main.py +++ b/snappass/main.py @@ -12,7 +12,6 @@ app.secret_key = os.environ.get('SECRET_KEY', 'Secret Key') app.config.update( dict(STATIC_URL=os.environ.get('STATIC_URL', 'static'))) -id_ = lambda: uuid.uuid4().hex redis_host = os.environ.get('REDIS_HOST', 'localhost') redis_client = redis.StrictRedis(host=redis_host, port=6379, db=0) @@ -23,8 +22,12 @@ time_conversion = { } +def _id(): + return uuid.uuid4().hex + + def set_password(password, ttl): - key = id_() + key = _id() redis_client.set(key, password) redis_client.expire(key, ttl) return key @@ -41,14 +44,14 @@ def clean_input(): Make sure we're not getting bad data from the front end, format data to be machine readable """ - if not 'password' in request.form: + if 'password' not in request.form: abort(400) - if not 'ttl' in request.form: + if 'ttl' not in request.form: abort(400) time_period = request.form['ttl'].lower() - if not time_period in time_conversion: + if time_period not in time_conversion: abort(400) return time_conversion[time_period], request.form['password'] diff --git a/tests.py b/tests.py index b6fc65d..7cdc373 100644 --- a/tests.py +++ b/tests.py @@ -3,7 +3,7 @@ from unittest import TestCase from werkzeug.exceptions import ClientDisconnected -#noinspection PyPep8Naming +# noinspection PyPep8Naming import snappass.main as snappass __author__ = 'davedash' @@ -45,7 +45,7 @@ class SnapPassTestCase(TestCase): class SnapPassRoutesTestCase(TestCase): - #noinspection PyPep8Naming + # noinspection PyPep8Naming def setUp(self): snappass.app.config['TESTING'] = True self.app = snappass.app.test_client() @@ -59,4 +59,3 @@ class SnapPassRoutesTestCase(TestCase): if __name__ == '__main__': unittest.main() - From d88cf2600e1bf6a61601092e3e17d1a29fb6a6e1 Mon Sep 17 00:00:00 2001 From: Nicholas Charriere Date: Mon, 18 Jul 2016 13:35:57 -0700 Subject: [PATCH 3/4] Refactor _id() function to be inline --- snappass/main.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/snappass/main.py b/snappass/main.py index 9dd8f61..3c84820 100644 --- a/snappass/main.py +++ b/snappass/main.py @@ -22,12 +22,8 @@ time_conversion = { } -def _id(): - return uuid.uuid4().hex - - def set_password(password, ttl): - key = _id() + key = uuid.uuid4().hex redis_client.set(key, password) redis_client.expire(key, ttl) return key From a9fc72724047fcdfe876ffcef7e74352c3d9230a Mon Sep 17 00:00:00 2001 From: Nicholas Charriere Date: Mon, 18 Jul 2016 13:36:06 -0700 Subject: [PATCH 4/4] Fix tests --- tests.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests.py b/tests.py index 7cdc373..8c0b5a8 100644 --- a/tests.py +++ b/tests.py @@ -1,7 +1,7 @@ import unittest from unittest import TestCase -from werkzeug.exceptions import ClientDisconnected +from werkzeug.exceptions import BadRequest # noinspection PyPep8Naming import snappass.main as snappass @@ -27,17 +27,17 @@ class SnapPassTestCase(TestCase): # Test Bad Data with snappass.app.test_request_context( "/", data={'password': 'foo', 'ttl': 'bar'}, method='POST'): - self.assertRaises(ClientDisconnected, snappass.clean_input) + self.assertRaises(BadRequest, snappass.clean_input) # No Password with snappass.app.test_request_context( "/", method='POST'): - self.assertRaises(ClientDisconnected, snappass.clean_input) + self.assertRaises(BadRequest, snappass.clean_input) # No TTL with snappass.app.test_request_context( "/", data={'password': 'foo'}, method='POST'): - self.assertRaises(ClientDisconnected, snappass.clean_input) + self.assertRaises(BadRequest, snappass.clean_input) with snappass.app.test_request_context( "/", data={'password': 'foo', 'ttl': 'hour'}, method='POST'):