From c0ec6dbec28a361717de6fb93b089d53a99b1801 Mon Sep 17 00:00:00 2001 From: Samuel Dion-Girardeau Date: Thu, 11 Aug 2016 21:39:59 -0400 Subject: [PATCH 1/6] Remove useless top-level __init__ file If the top-level snappass directory is a package, `import` will fail, depending on the environment, python version, etc. --- __init__.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 __init__.py diff --git a/__init__.py b/__init__.py deleted file mode 100644 index e69de29..0000000 From a46fc40aa321dda36a70a43b6a035aeb3bdb0eb9 Mon Sep 17 00:00:00 2001 From: Samuel Dion-Girardeau Date: Thu, 11 Aug 2016 21:50:37 -0400 Subject: [PATCH 2/6] Improve string encoding for password retrieval - Prevent the password from displaying as b'...' in the app; - Use Flask's `get_data(as_test=True)` to read the data, in the tests; - Add test to ensure `get_password` is not returning bytes. --- snappass/main.py | 2 ++ tests.py | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/snappass/main.py b/snappass/main.py index 3c84820..ee9b77e 100644 --- a/snappass/main.py +++ b/snappass/main.py @@ -31,6 +31,8 @@ def set_password(password, ttl): def get_password(key): password = redis_client.get(key) + if password is not None: + password = password.decode('utf-8') redis_client.delete(key) return password diff --git a/tests.py b/tests.py index 8c0b5a8..988961d 100644 --- a/tests.py +++ b/tests.py @@ -23,6 +23,11 @@ class SnapPassTestCase(TestCase): # Assert that we can't look this up a second time. self.assertEqual(None, snappass.get_password(key)) + def test_password_is_decoded(self): + password = "correct horse battery staple" + key = snappass.set_password(password, 30) + self.assertFalse(isinstance(snappass.get_password(key), bytes)) + def test_clean_input(self): # Test Bad Data with snappass.app.test_request_context( @@ -54,7 +59,7 @@ class SnapPassRoutesTestCase(TestCase): password = "I like novelty kitten statues!" key = snappass.set_password(password, 30) rv = self.app.get('/{}'.format(key)) - self.assertIn(password, rv.data) + self.assertIn(password, rv.get_data(as_text=True)) if __name__ == '__main__': From 28e19b51a77ddb2dc7085503692958151879340a Mon Sep 17 00:00:00 2001 From: Samuel Dion-Girardeau Date: Thu, 11 Aug 2016 22:12:56 -0400 Subject: [PATCH 3/6] Add support for python 3.3 in tox And update associated documentation --- .travis.yml | 3 ++- CONTRIBUTING.rst | 8 +------- README.rst | 2 +- setup.py | 2 ++ tox.ini | 2 +- 5 files changed, 7 insertions(+), 10 deletions(-) diff --git a/.travis.yml b/.travis.yml index 38d4e30..7ab464a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,6 @@ language: python -python: 2.7 +python: + - "3.5" sudo: false install: - pip install tox diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index 0d05ba5..c8299cd 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -24,12 +24,6 @@ If you are reporting a bug, please include: as much detail as you can. Questions to start a discussion about the issue are welcome. -Python 3.3 Support -~~~~~~~~~~~~~~~~~~ - -We'd love for ``tox -e py33`` to work and would welcome anybody who can help -make that a reality. - Fix Bugs ~~~~~~~~ @@ -119,7 +113,7 @@ Before you submit a pull request, check that it meets these guidelines: 2. If the pull request adds functionality, the docs should be updated. Put your new functionality into a function with a docstring, and add the feature to the list in README.rst. -3. The pull request should work for Python 2.7 and ideally 3.3. Check +3. The pull request should work for Python 2.7 and 3.3+. Check `Travis`_ and make sure that the tests pass for all supported Python versions. diff --git a/README.rst b/README.rst index f3d2050..66ec6aa 100644 --- a/README.rst +++ b/README.rst @@ -33,7 +33,7 @@ Requirements ------------ * Redis. -* Python 2.6, 2.7 or 3.3. +* Python 2.6, 2.7 or 3.3+. Installation ------------ diff --git a/setup.py b/setup.py index f6c0408..562b643 100644 --- a/setup.py +++ b/setup.py @@ -30,6 +30,8 @@ setup( 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3.3', + 'Programming Language :: Python :: 3.4', + 'Programming Language :: Python :: 3.5', 'Topic :: Software Development :: Libraries :: Python Modules', ], zip_safe=False, diff --git a/tox.ini b/tox.ini index 5d83da1..0a9c5cd 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py27 +envlist = py27, py33, py34, py35 [testenv] deps = From faef96c30c6e9d3c66e368b1bc3e9d66b76958bf Mon Sep 17 00:00:00 2001 From: Samuel Dion-Girardeau Date: Thu, 11 Aug 2016 22:13:27 -0400 Subject: [PATCH 4/6] Use python 3.5 in the Docker image Since tests are running for 3.5, there is no point in not using the latest & greatest version. --- Dockerfile | 2 +- README.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 257f59d..ad5336c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.3 +FROM python:3.5 ENV APP_DIR=/usr/src/snappass diff --git a/README.rst b/README.rst index 66ec6aa..e8dc2cf 100644 --- a/README.rst +++ b/README.rst @@ -74,4 +74,4 @@ Alternatively, you can use `Docker`_ and `Docker Compose`_ to install and run Sn $ docker build -t snappass . $ docker-compose up -d -This will pull all dependencies, i.e. Redis and appropriate Python version (3.3), then start up snappass and Redis server. SnapPass server is accessible at: http://localhost:5000 +This will pull all dependencies, i.e. Redis and appropriate Python version (3.5), then start up snappass and Redis server. SnapPass server is accessible at: http://localhost:5000 From 20635bdec8ac93a5cfead902bc642e1c95b360e3 Mon Sep 17 00:00:00 2001 From: Samuel Dion-Girardeau Date: Thu, 11 Aug 2016 22:39:29 -0400 Subject: [PATCH 5/6] Explicitly define all supported python environment With only 3.5, travis-ci works, because 2.7, 3.3 and 3.4 interpreters are present by default, but it might break randomly at some point. Definining all the versions explicitly, and using the tox-travis plugin is more robust. Also, 2.6 was removed from the "officially supported" python versions, as the tests are not run (and don't pass). --- .travis.yml | 5 ++++- README.rst | 2 +- setup.py | 1 - 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7ab464a..d0ad25a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,12 @@ language: python python: + - "2.7" + - "3.3" + - "3.4" - "3.5" sudo: false install: - - pip install tox + - pip install tox-travis script: - tox services: diff --git a/README.rst b/README.rst index e8dc2cf..bb9eca7 100644 --- a/README.rst +++ b/README.rst @@ -33,7 +33,7 @@ Requirements ------------ * Redis. -* Python 2.6, 2.7 or 3.3+. +* Python 2.7 or 3.3+. Installation ------------ diff --git a/setup.py b/setup.py index 562b643..d0a1811 100644 --- a/setup.py +++ b/setup.py @@ -26,7 +26,6 @@ setup( 'Operating System :: OS Independent', 'Programming Language :: Python', 'Programming Language :: Python :: 2', - 'Programming Language :: Python :: 2.6', 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3.3', From 00f6964a90ae29a6de6bff8e3295d7e93ebb055c Mon Sep 17 00:00:00 2001 From: Samuel Dion-Girardeau Date: Fri, 12 Aug 2016 18:38:33 -0400 Subject: [PATCH 6/6] Fix python2.6 support for tests - "{}".format('foo') does not work on python2.6, as the index needs to be explicitly specified. - assertIn(x, y) was only introduced in 2.7, reverting to assertTrue(x in y) Updated test environments definitions and docs accordingly. --- .travis.yml | 1 + CONTRIBUTING.rst | 2 +- README.rst | 2 +- setup.py | 1 + tests.py | 4 ++-- tox.ini | 2 +- 6 files changed, 7 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index d0ad25a..e118237 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,6 @@ language: python python: + - "2.6" - "2.7" - "3.3" - "3.4" diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index c8299cd..20bf915 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -113,7 +113,7 @@ Before you submit a pull request, check that it meets these guidelines: 2. If the pull request adds functionality, the docs should be updated. Put your new functionality into a function with a docstring, and add the feature to the list in README.rst. -3. The pull request should work for Python 2.7 and 3.3+. Check +3. The pull request should work for Python 2.6, 2.7 and 3.3+. Check `Travis`_ and make sure that the tests pass for all supported Python versions. diff --git a/README.rst b/README.rst index bb9eca7..e8dc2cf 100644 --- a/README.rst +++ b/README.rst @@ -33,7 +33,7 @@ Requirements ------------ * Redis. -* Python 2.7 or 3.3+. +* Python 2.6, 2.7 or 3.3+. Installation ------------ diff --git a/setup.py b/setup.py index d0a1811..562b643 100644 --- a/setup.py +++ b/setup.py @@ -26,6 +26,7 @@ setup( 'Operating System :: OS Independent', 'Programming Language :: Python', 'Programming Language :: Python :: 2', + 'Programming Language :: Python :: 2.6', 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3.3', diff --git a/tests.py b/tests.py index 988961d..a90b292 100644 --- a/tests.py +++ b/tests.py @@ -58,8 +58,8 @@ class SnapPassRoutesTestCase(TestCase): def test_show_password(self): password = "I like novelty kitten statues!" key = snappass.set_password(password, 30) - rv = self.app.get('/{}'.format(key)) - self.assertIn(password, rv.get_data(as_text=True)) + rv = self.app.get('/{0}'.format(key)) + self.assertTrue(password in rv.get_data(as_text=True)) if __name__ == '__main__': diff --git a/tox.ini b/tox.ini index 0a9c5cd..d06412b 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py27, py33, py34, py35 +envlist = py26, py27, py33, py34, py35 [testenv] deps =