Refactor Functional Test Cases

To simplify the setup code, a base class
"Swift3FanctionalTestCase" expeced to keep common
procedures there is added to __init__.py.

Change-Id: I3d0bd909751167de864ad0acc4cb9e7d93b4f2fc
This commit is contained in:
Kota Tsuyuzaki
2015-03-12 20:20:30 -07:00
parent dd1905d4f9
commit 07f2681876
5 changed files with 58 additions and 27 deletions

View File

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

View File

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

View File

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

View File

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

View File

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