tox.ini and unittest fix

Change-Id: Ic6b2435159c63adc81b8881a7a0c1e65a14f7c1c
This commit is contained in:
Peter Lisák 2015-11-12 16:13:36 +01:00
parent eeae4ac9fb
commit 69cadf8499
7 changed files with 111 additions and 20 deletions

4
requirements.txt Normal file
View File

@ -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.

View File

@ -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,

View File

@ -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):

12
test-requirements.txt Normal file
View File

@ -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

View File

@ -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)

View File

@ -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):

63
tox.ini Normal file
View File

@ -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