Merge pull request #11 from pinterest/tweaks

Cleanup gitignore and make linter pass
This commit is contained in:
Nicholas Charriere 2016-07-18 20:53:38 +00:00 committed by GitHub
commit 64755bae8a
3 changed files with 58 additions and 14 deletions

50
.gitignore vendored
View file

@ -1,5 +1,51 @@
.tox
.coverage
.project .project
*.rdb *.rdb
junit*xml 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/

View file

@ -12,7 +12,6 @@ app.secret_key = os.environ.get('SECRET_KEY', 'Secret Key')
app.config.update( app.config.update(
dict(STATIC_URL=os.environ.get('STATIC_URL', 'static'))) dict(STATIC_URL=os.environ.get('STATIC_URL', 'static')))
id_ = lambda: uuid.uuid4().hex
redis_host = os.environ.get('REDIS_HOST', 'localhost') redis_host = os.environ.get('REDIS_HOST', 'localhost')
redis_client = redis.StrictRedis(host=redis_host, port=6379, db=0) redis_client = redis.StrictRedis(host=redis_host, port=6379, db=0)
@ -24,7 +23,7 @@ time_conversion = {
def set_password(password, ttl): def set_password(password, ttl):
key = id_() key = uuid.uuid4().hex
redis_client.set(key, password) redis_client.set(key, password)
redis_client.expire(key, ttl) redis_client.expire(key, ttl)
return key return key
@ -41,14 +40,14 @@ def clean_input():
Make sure we're not getting bad data from the front end, Make sure we're not getting bad data from the front end,
format data to be machine readable format data to be machine readable
""" """
if not 'password' in request.form: if 'password' not in request.form:
abort(400) abort(400)
if not 'ttl' in request.form: if 'ttl' not in request.form:
abort(400) abort(400)
time_period = request.form['ttl'].lower() time_period = request.form['ttl'].lower()
if not time_period in time_conversion: if time_period not in time_conversion:
abort(400) abort(400)
return time_conversion[time_period], request.form['password'] return time_conversion[time_period], request.form['password']

View file

@ -1,9 +1,9 @@
import unittest import unittest
from unittest import TestCase from unittest import TestCase
from werkzeug.exceptions import ClientDisconnected from werkzeug.exceptions import BadRequest
#noinspection PyPep8Naming # noinspection PyPep8Naming
import snappass.main as snappass import snappass.main as snappass
__author__ = 'davedash' __author__ = 'davedash'
@ -27,17 +27,17 @@ class SnapPassTestCase(TestCase):
# Test Bad Data # Test Bad Data
with snappass.app.test_request_context( with snappass.app.test_request_context(
"/", data={'password': 'foo', 'ttl': 'bar'}, method='POST'): "/", data={'password': 'foo', 'ttl': 'bar'}, method='POST'):
self.assertRaises(ClientDisconnected, snappass.clean_input) self.assertRaises(BadRequest, snappass.clean_input)
# No Password # No Password
with snappass.app.test_request_context( with snappass.app.test_request_context(
"/", method='POST'): "/", method='POST'):
self.assertRaises(ClientDisconnected, snappass.clean_input) self.assertRaises(BadRequest, snappass.clean_input)
# No TTL # No TTL
with snappass.app.test_request_context( with snappass.app.test_request_context(
"/", data={'password': 'foo'}, method='POST'): "/", data={'password': 'foo'}, method='POST'):
self.assertRaises(ClientDisconnected, snappass.clean_input) self.assertRaises(BadRequest, snappass.clean_input)
with snappass.app.test_request_context( with snappass.app.test_request_context(
"/", data={'password': 'foo', 'ttl': 'hour'}, method='POST'): "/", data={'password': 'foo', 'ttl': 'hour'}, method='POST'):
@ -45,7 +45,7 @@ class SnapPassTestCase(TestCase):
class SnapPassRoutesTestCase(TestCase): class SnapPassRoutesTestCase(TestCase):
#noinspection PyPep8Naming # noinspection PyPep8Naming
def setUp(self): def setUp(self):
snappass.app.config['TESTING'] = True snappass.app.config['TESTING'] = True
self.app = snappass.app.test_client() self.app = snappass.app.test_client()
@ -59,4 +59,3 @@ class SnapPassRoutesTestCase(TestCase):
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()