From 69cadf84996667b5f73bacd01c44918c2b8adfdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20Lis=C3=A1k?= <peter.lisak@firma.seznam.cz> Date: Thu, 12 Nov 2015 16:13:36 +0100 Subject: [PATCH] tox.ini and unittest fix Change-Id: Ic6b2435159c63adc81b8881a7a0c1e65a14f7c1c --- requirements.txt | 4 ++ setup.py | 2 +- swauth/authtypes.py | 2 +- test-requirements.txt | 12 ++++++ test_swauth/unit/test_authtypes.py | 5 ++- test_swauth/unit/test_middleware.py | 43 ++++++++++++-------- tox.ini | 63 +++++++++++++++++++++++++++++ 7 files changed, 111 insertions(+), 20 deletions(-) create mode 100644 requirements.txt create mode 100644 test-requirements.txt create mode 100644 tox.ini diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..2683dd4 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,4 @@ +# The order of packages is significant, because pip processes them in the order +# of appearance. Changing the order has an impact on the overall integration +# process, which may cause wedges in the gate later. + diff --git a/setup.py b/setup.py index ceef1ca..5ca4924 100644 --- a/setup.py +++ b/setup.py @@ -63,7 +63,7 @@ setup( license='Apache License (2.0)', author='OpenStack, LLC.', author_email='swauth@brim.net', - url='https://github.com/gholt/swauth', + url='https://github.com/openstack/swauth', packages=find_packages(exclude=['test_swauth', 'bin']), test_suite='nose.collector', cmdclass=cmdclass, diff --git a/swauth/authtypes.py b/swauth/authtypes.py index 5d83f76..3f990d7 100644 --- a/swauth/authtypes.py +++ b/swauth/authtypes.py @@ -99,7 +99,7 @@ class Sha1(object): :param key: User's secret key :returns: A string representing user credentials """ - salt = os.urandom(32).encode('base64').rstrip(); + salt = os.urandom(32).encode('base64').rstrip() return self.encode_w_salt(salt, key) def match(self, key, creds): diff --git a/test-requirements.txt b/test-requirements.txt new file mode 100644 index 0000000..7bb5021 --- /dev/null +++ b/test-requirements.txt @@ -0,0 +1,12 @@ +# The order of packages is significant, because pip processes them in the order +# of appearance. Changing the order has an impact on the overall integration +# process, which may cause wedges in the gate later. +hacking<0.11,>=0.10.0 + +flake8 +mock +nose +#coverage>=3.6 +#discover +#python-subunit>=0.0.18 +sphinx>=1.1.2,!=1.2.0,!=1.3b1,<1.3 diff --git a/test_swauth/unit/test_authtypes.py b/test_swauth/unit/test_authtypes.py index eda1de4..fb0ca9c 100644 --- a/test_swauth/unit/test_authtypes.py +++ b/test_swauth/unit/test_authtypes.py @@ -14,6 +14,7 @@ # Pablo Llopis 2011 import unittest +import mock from contextlib import contextmanager from swauth import authtypes @@ -44,7 +45,9 @@ class TestSha1(unittest.TestCase): self.auth_encoder = authtypes.Sha1() self.auth_encoder.salt = 'salt' - def test_sha1_encode(self): + @mock.patch('swauth.authtypes.os') + def test_sha1_encode(self, os): + os.urandom.return_value.encode.return_value.rstrip.return_value = 'salt' enc_key = self.auth_encoder.encode('keystring') self.assertEquals('sha1:salt$d50dc700c296e23ce5b41f7431a0e01f69010f06', enc_key) diff --git a/test_swauth/unit/test_middleware.py b/test_swauth/unit/test_middleware.py index 00e6b1b..8a9c8c4 100644 --- a/test_swauth/unit/test_middleware.py +++ b/test_swauth/unit/test_middleware.py @@ -1625,6 +1625,10 @@ class TestAuth(unittest.TestCase): self.assertEquals(conn.calls, 1) def test_put_account_success_preexist_and_completed(self): + conn = FakeConn(iter([ + # PUT of storage account itself + ('201 Created', {}, '')])) + self.test_auth.get_conn = lambda: conn self.test_auth.app = FakeApp(iter([ # Initial HEAD of account container to check for pre-existence # We're going to show it as existing this time, and with an @@ -1710,7 +1714,27 @@ class TestAuth(unittest.TestCase): ).get_response(self.test_auth) self.assertEquals(resp.status_int, 400) + def test_put_account_fail_on_storage_account_put(self): + conn = FakeConn(iter([ + # PUT of storage account itself + ('503 Service Unavailable', {}, '')])) + self.test_auth.get_conn = lambda: conn + self.test_auth.app = FakeApp(iter([ + ])) + resp = Request.blank('/auth/v2/act', + environ={'REQUEST_METHOD': 'PUT', 'swift.cache': FakeMemcache()}, + headers={'X-Auth-Admin-User': '.super_admin', + 'X-Auth-Admin-Key': 'supertest'} + ).get_response(self.test_auth) + self.assertEquals(resp.status_int, 500) + self.assertEquals(conn.calls, 1) + self.assertEquals(self.test_auth.app.calls, 0) + def test_put_account_fail_on_initial_account_head(self): + conn = FakeConn(iter([ + # PUT of storage account itself + ('201 Created', {}, '')])) + self.test_auth.get_conn = lambda: conn self.test_auth.app = FakeApp(iter([ # Initial HEAD of account container to check for pre-existence ('503 Service Unavailable', {}, '')])) @@ -1723,36 +1747,21 @@ class TestAuth(unittest.TestCase): self.assertEquals(self.test_auth.app.calls, 1) def test_put_account_fail_on_account_marker_put(self): - self.test_auth.app = FakeApp(iter([ - # Initial HEAD of account container to check for pre-existence - ('404 Not Found', {}, ''), - # PUT of account container - ('503 Service Unavailable', {}, '')])) - resp = Request.blank('/auth/v2/act', - environ={'REQUEST_METHOD': 'PUT', 'swift.cache': FakeMemcache()}, - headers={'X-Auth-Admin-User': '.super_admin', - 'X-Auth-Admin-Key': 'supertest'} - ).get_response(self.test_auth) - self.assertEquals(resp.status_int, 500) - self.assertEquals(self.test_auth.app.calls, 2) - - def test_put_account_fail_on_storage_account_put(self): conn = FakeConn(iter([ # PUT of storage account itself - ('503 Service Unavailable', {}, '')])) + ('201 Created', {}, '')])) self.test_auth.get_conn = lambda: conn self.test_auth.app = FakeApp(iter([ # Initial HEAD of account container to check for pre-existence ('404 Not Found', {}, ''), # PUT of account container - ('204 No Content', {}, '')])) + ('503 Service Unavailable', {}, '')])) resp = Request.blank('/auth/v2/act', environ={'REQUEST_METHOD': 'PUT', 'swift.cache': FakeMemcache()}, headers={'X-Auth-Admin-User': '.super_admin', 'X-Auth-Admin-Key': 'supertest'} ).get_response(self.test_auth) self.assertEquals(resp.status_int, 500) - self.assertEquals(conn.calls, 1) self.assertEquals(self.test_auth.app.calls, 2) def test_put_account_fail_on_account_id_mapping(self): diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..1b5315e --- /dev/null +++ b/tox.ini @@ -0,0 +1,63 @@ +[tox] +minversion = 1.6 +envlist = py27,pep8 +skipsdist = True + +[testenv] +basepython = python2.7 +usedevelop = True +install_command = pip install -U {opts} {packages} +setenv = + VIRTUAL_ENV={envdir} +deps = + -r{toxinidir}/requirements.txt + -r{toxinidir}/test-requirements.txt + https://launchpad.net/swift/kilo/2.3.0/+download/swift-2.3.0.tar.gz +commands = python setup.py test + +[testenv:pep8] +commands = flake8 swauth test_swauth + +[testenv:venv] +commands = {posargs} + +#[testenv:cover] +#commands = python setup.py test --coverage + +[testenv:docs] +commands = python setup.py build_sphinx + +[flake8] +# E123, E125 skipped as they are invalid PEP-8. +# will be removed later +# H234 assertEquals is deprecated, use assertEqual +# H405 multi line docstring summary not separated with an empty line +# E127 continuation line over-indented for visual indent +# E128 continuation line under-indented for visual indent +# H235 assert_ is deprecated, use assertTrue +# E131 continuation line unaligned for hanging indent +# E124 closing bracket does not match visual indentation +# E121 continuation line under-indented for hanging indent +# H306 imports not in alphabetical order +# H404 multi line docstring should start without a leading new line +# H301 one import per line +# F841 local variable 'detail' is assigned to but never used +# H231 Python 3.x incompatible 'except x,y:' construct +# H233 Python 3.x incompatible use of print operator +# E226 missing whitespace around arithmetic operator +# W291 trailing whitespace +# H202 assertRaises Exception too broad +# H101 Use TODO(NAME) +# F401 '' imported but unused +# H703 Multiple positional placeholders +# E501 line too long (93 > 79 characters) +# E703 statement ends with a semicolon +# F841 local variable 'detail' is assigned to but never used +# H102 Apache 2.0 license header not found +# E302 expected 2 blank lines, found 1 + +show-source = True +ignore = E123,E125,H234,H405,E127,E128,H235,E131,E124,E121,H306,H404,H301, + F841,H231,H233,E226,W291,H202,H101,F401,H703,E501,E703,F841,H102,E302 +builtins = _ +exclude=.venv,.git,.tox,dist,doc,*egg,build