From 39765dfd2f19d8565e83066672faf508e031cecc Mon Sep 17 00:00:00 2001 From: Dolph Mathews Date: Wed, 13 Jul 2011 11:59:27 -0500 Subject: Extracted sample test from framework and moved system test framework into __init__ --- keystone/test/system/__init__.py | 66 ++++++++++++++++++++++++++++ keystone/test/system/test.py | 70 ------------------------------ keystone/test/system/test_content_types.py | 5 +++ 3 files changed, 71 insertions(+), 70 deletions(-) delete mode 100644 keystone/test/system/test.py create mode 100644 keystone/test/system/test_content_types.py diff --git a/keystone/test/system/__init__.py b/keystone/test/system/__init__.py index e69de29b..07a47844 100644 --- a/keystone/test/system/__init__.py +++ b/keystone/test/system/__init__.py @@ -0,0 +1,66 @@ +import unittest +import httplib + +class RestfulTestCase(unittest.TestCase): + """Performs generic HTTP request testing""" + + def setUp(self): + """Sets default connection settings""" + self.host = '127.0.0.1' + self.port = 80 + + def request(self, method='GET', path='/', headers={}, body=None, + expect_exception=False): + """Perform request and fetch httplib.HTTPResponse from the server""" + + # Initialize a connection + connection = httplib.HTTPConnection(self.host, self.port, timeout=3) + + # Perform the request + connection.request(method, path, body, headers) + + # Retrieve the response so can go ahead and close the connection + response = connection.getresponse() + + # Close the connection + connection.close() + + # Automatically assert HTTP status code + if not expect_exception: + self.assertSuccessfulResponse(response.status) + else: + self.assertExceptionalResponse(response.status) + + # This contains the response headers, body, etc + return response + + def assertSuccessfulResponse(self, status_code): + """Asserts that a status code lies in the 2xx range""" + self.assertTrue(status_code >= 200 and status_code <= 299) + + def assertExceptionalResponse(self, status_code): + """Asserts that a status code lies outside the 2xx range""" + self.assertTrue(status_code < 200 or status_code > 299) + +class ServiceTestCase(RestfulTestCase): + """Perform generic HTTP request testing against Service API""" + + def setUp(self): + """Sets custom connection settings""" + super(ServiceTestCase, self).setUp() + + # Override parent's connection settings + self.port = 5000 # The port the service API is expected to run on + +class AdminTestCase(RestfulTestCase): + """Perform generic HTTP request testing against Service API""" + + def setUp(self): + """Sets custom connection settings""" + super(AdminTestCase, self).setUp() + + # Override parent's connection settings + self.port = 5001 # The port the admin API is expected to run on + +if __name__ == '__main__': + unittest.main() diff --git a/keystone/test/system/test.py b/keystone/test/system/test.py deleted file mode 100644 index 39534837..00000000 --- a/keystone/test/system/test.py +++ /dev/null @@ -1,70 +0,0 @@ -import unittest -import httplib - -class RestfulTestCase(unittest.TestCase): - """Performs generic HTTP request testing""" - - def setUp(self): - """Sets default connection settings""" - self.host = '127.0.0.1' - self.port = 80 - - def request(self, method='GET', path='/', headers={}, body=None, - expect_exception=False): - """Perform request and fetch httplib.HTTPResponse from the server""" - - # Initialize a connection - connection = httplib.HTTPConnection(self.host, self.port, timeout=3) - - # Perform the request - connection.request(method, path, body, headers) - - # Retrieve the response so can go ahead and close the connection - response = connection.getresponse() - - # Close the connection - connection.close() - - # Automatically assert HTTP status code - if not expect_exception: - self.assertSuccessfulResponse(response.status) - else: - self.assertExceptionalResponse(response.status) - - # This contains the response headers, body, etc - return response - - def assertSuccessfulResponse(self, status_code): - """Asserts that a status code lies in the 2xx range""" - self.assertTrue(status_code >= 200 and status_code <= 299) - - def assertExceptionalResponse(self, status_code): - """Asserts that a status code lies outside the 2xx range""" - self.assertTrue(status_code < 200 or status_code > 299) - -class ServiceTestCase(RestfulTestCase): - """Perform generic HTTP request testing against Service API""" - - def setUp(self): - """Sets custom connection settings""" - super(ServiceTestCase, self).setUp() - - # Override parent's connection settings - self.port = 5000 # The port the service API is expected to run on - -class AdminTestCase(RestfulTestCase): - """Perform generic HTTP request testing against Service API""" - - def setUp(self): - """Sets custom connection settings""" - super(AdminTestCase, self).setUp() - - # Override parent's connection settings - self.port = 5001 # The port the admin API is expected to run on - -class TestContentTypes(AdminTestCase): - def test_simple(self): - self.request(path='/v2.0/') - -if __name__ == '__main__': - unittest.main() diff --git a/keystone/test/system/test_content_types.py b/keystone/test/system/test_content_types.py new file mode 100644 index 00000000..41d16513 --- /dev/null +++ b/keystone/test/system/test_content_types.py @@ -0,0 +1,5 @@ +from . import AdminTestCase + +class TestContentTypes(AdminTestCase): + def test_simple(self): + self.request(path='/v2.0/') -- cgit