diff --git a/swift3/test/functional/__init__.py b/swift3/test/functional/__init__.py index e69de29b..61e0413e 100644 --- a/swift3/test/functional/__init__.py +++ b/swift3/test/functional/__init__.py @@ -0,0 +1,34 @@ +# Copyright (c) 2011-2014 OpenStack Foundation. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import unittest +import traceback +from swift3.test.functional.s3_test_client import Connection + + +class Swift3FunctionalTestCase(unittest.TestCase): + def __init__(self, method_name): + super(Swift3FunctionalTestCase, self).__init__(method_name) + self.method_name = method_name + + def setUp(self): + try: + self.conn = Connection() + self.conn.reset() + except Exception: + message = '%s got an error during initialize process.\n\n%s' % \ + (self.method_name, traceback.format_exc()) + # TODO: Find a way to make this go to FAIL instead of Error + self.fail(message) diff --git a/swift3/test/functional/s3_test_client.py b/swift3/test/functional/s3_test_client.py index b3e99597..3c03c673 100644 --- a/swift3/test/functional/s3_test_client.py +++ b/swift3/test/functional/s3_test_client.py @@ -25,10 +25,10 @@ class Connection(object): """ Connection class used for S3 functional testing. """ - def __init__(self, aws_access_key=os.environ.get('ADMIN_ACCESS_KEY'), - aws_secret_key=os.environ.get('ADMIN_SECRET_KEY'), - user_id='%s:%s' % (os.environ.get('ADMIN_TENANT'), - os.environ.get('ADMIN_USER'))): + def __init__(self, aws_access_key=os.environ.get('TESTER_ACCESS_KEY'), + aws_secret_key=os.environ.get('TESTER_SECRET_KEY'), + user_id='%s:%s' % (os.environ.get('TESTER_TENANT'), + os.environ.get('TESTER_USER'))): """ Initialize method. @@ -37,9 +37,9 @@ class Connection(object): :param user_id: a string consists of TENANT and USER name used for asserting Owner ID (not required S3Connection) - In default, Connection class will be initialized as admin user + In default, Connection class will be initialized as tester user behaves as: - user_test_admin = admin .admin + user_test_tester = testing .admin """ self.aws_access_key = aws_access_key @@ -104,15 +104,15 @@ class Connection(object): return response.status, dict(response.getheaders()), response.read() -def get_tester_connection(): +def get_admin_connection(): """ Return tester connection behaves as: - user_test_tester = testing .admin + user_test_admin = admin .admin """ - aws_access_key = os.environ.get('TESTER_ACCESS_KEY') - aws_secret_key = os.environ.get('TESTER_SECRET_KEY') - user_id = os.environ.get('TESTER_TENANT') + ':' + \ - os.environ.get('TESTER_USER') + aws_access_key = os.environ.get('ADMIN_ACCESS_KEY') + aws_secret_key = os.environ.get('ADMIN_SECRET_KEY') + user_id = os.environ.get('ADMIN_TENANT') + ':' + \ + os.environ.get('ADMIN_USER') return Connection(aws_access_key, aws_secret_key, user_id) diff --git a/swift3/test/functional/test_bucket.py b/swift3/test/functional/test_bucket.py index 82ed5cab..0d24159b 100644 --- a/swift3/test/functional/test_bucket.py +++ b/swift3/test/functional/test_bucket.py @@ -15,18 +15,17 @@ import unittest -from swift3.test.functional.s3_test_client import get_tester_connection,\ - Connection +from swift3.test.functional.s3_test_client import Connection from swift3.test.functional.utils import get_error_code,\ assert_common_response_headers from swift3.etree import fromstring from swift3.cfg import CONF +from swift3.test.functional import Swift3FunctionalTestCase -class TestSwift3Bucket(unittest.TestCase): +class TestSwift3Bucket(Swift3FunctionalTestCase): def setUp(self): - self.conn = get_tester_connection() - self.conn.reset() + super(TestSwift3Bucket, self).setUp() def test_bucket(self): bucket = 'bucket' diff --git a/swift3/test/functional/test_object.py b/swift3/test/functional/test_object.py index 2309eea2..b95b11f5 100644 --- a/swift3/test/functional/test_object.py +++ b/swift3/test/functional/test_object.py @@ -15,16 +15,15 @@ import unittest -from swift3.test.functional.s3_test_client import get_tester_connection,\ - Connection +from swift3.test.functional.s3_test_client import Connection from swift3.test.functional.utils import get_error_code,\ assert_common_response_headers +from swift3.test.functional import Swift3FunctionalTestCase -class TestSwift3Object(unittest.TestCase): +class TestSwift3Object(Swift3FunctionalTestCase): def setUp(self): - self.conn = get_tester_connection() - self.conn.reset() + super(TestSwift3Object, self).setUp() self.bucket = 'bucket' self.conn.make_request('PUT', self.bucket) diff --git a/swift3/test/functional/test_service.py b/swift3/test/functional/test_service.py index 9ce1e2ab..64179d29 100644 --- a/swift3/test/functional/test_service.py +++ b/swift3/test/functional/test_service.py @@ -15,17 +15,16 @@ import unittest -from swift3.test.functional.s3_test_client import get_tester_connection,\ - Connection +from swift3.test.functional.s3_test_client import Connection from swift3.test.functional.utils import get_error_code,\ assert_common_response_headers from swift3.etree import fromstring +from swift3.test.functional import Swift3FunctionalTestCase -class TestSwift3Service(unittest.TestCase): +class TestSwift3Service(Swift3FunctionalTestCase): def setUp(self): - self.conn = get_tester_connection() - self.conn.reset() + super(TestSwift3Service, self).setUp() def test_service(self): # GET Service(without bucket)