moksha/middleware/connector.py | 10 ++-- moksha/tests/quickstarts/base.py | 69 ++++++++++++++-------------- moksha/tests/quickstarts/test_connector.py | 44 +++++++++++------ moksha/tests/quickstarts/test_consumer.py | 44 +++++++++++------ moksha/tests/quickstarts/test_controller.py | 43 +++++++++++------ moksha/tests/quickstarts/test_livewidget.py | 43 ++++++++++------- moksha/tests/quickstarts/test_stream.py | 44 +++++++++++------ 7 files changed, 183 insertions(+), 114 deletions(-)
New commits: commit e0a9b5dff04aa2360b4c69da8466153f1faa8432 Author: Luke Macken lmacken@redhat.com Date: Thu Sep 24 09:37:33 2009 -0400
Test suite optimizations to cut the running time almost in half
diff --git a/moksha/tests/quickstarts/base.py b/moksha/tests/quickstarts/base.py index f7403a3..0589127 100644 --- a/moksha/tests/quickstarts/base.py +++ b/moksha/tests/quickstarts/base.py @@ -20,47 +20,50 @@ class Options(object): inspect_files = False svn_repository = None
+old_cwd = None
-class QuickstartTester(object): +def setup_quickstart(template, templates, template_vars, args): + command = CreateDistroCommand('MokshaQuickStartUnitTest') + command.verbose = False + command.simulate = False + command.options = Options() + command.interactive=False + command.args=[ + 'mokshatest', '--package=mokshatest', + '--template=moksha.master', + ] + for t in templates: + command.args.append('--template=%s' % t) + + for arg in args: + command.args.append('%s=%s' % (arg, args[arg]))
- def setUp(self): - command = CreateDistroCommand('MokshaQuickStartUnitTest') - command.verbose = False - command.simulate = False - command.options = Options() - command.interactive=False - command.args=[ - 'mokshatest', '--package=mokshatest', - '--template=moksha.master', - ] - for template in self.templates: - command.args.append('--template=%s' % template) + proj_dir = os.path.join(testDataPath, 'mokshatest') + command.create_template( + template('mokshatest'), + proj_dir, + template_vars) + command.command()
- for arg in self.args: - command.args.append('%s=%s' % (arg, self.args[arg])) + global old_cwd + old_cwd = os.getcwd() + os.chdir(proj_dir) + subprocess.Popen('paver egg_info', shell=True, stdout=subprocess.PIPE, + stderr=subprocess.PIPE).communicate()
- proj_dir = os.path.join(testDataPath, 'mokshatest') - command.create_template( - self.template('mokshatest'), - proj_dir, - self.template_vars) - command.command() + pkg_resources.working_set.add_entry(proj_dir) + reload(pkg_resources)
- self.oldcwd = os.getcwd() - os.chdir(proj_dir) - subprocess.Popen('paver egg_info', shell=True, stdout=subprocess.PIPE, - stderr=subprocess.PIPE).communicate() + app = loadapp('config:/srv/moksha/development.ini', + relative_to=proj_dir) + return TestApp(app)
- pkg_resources.working_set.add_entry(proj_dir) - reload(pkg_resources) +def teardown_quickstart(): + shutil.rmtree(testDataPath, ignore_errors=True) + os.chdir(old_cwd)
- self.app = loadapp('config:/srv/moksha/development.ini', - relative_to=proj_dir) - self.app = TestApp(self.app)
- def tearDown(self): - shutil.rmtree(testDataPath, ignore_errors=True) - os.chdir(self.oldcwd) +class QuickstartTester(object):
def get_entry(self, entry_point): for entry in pkg_resources.working_set.iter_entry_points(entry_point): diff --git a/moksha/tests/quickstarts/test_connector.py b/moksha/tests/quickstarts/test_connector.py index 2c40280..9ea7eba 100644 --- a/moksha/tests/quickstarts/test_connector.py +++ b/moksha/tests/quickstarts/test_connector.py @@ -4,24 +4,35 @@ import pkg_resources
from datetime import timedelta from moksha.pastetemplate import MokshaConnectorTemplate -from base import QuickstartTester +from base import QuickstartTester, setup_quickstart, teardown_quickstart + +app = None + +def setup(): + template = MokshaConnectorTemplate + templates = ['moksha.connector'] + template_vars = { + 'package': 'mokshatest', + 'project': 'mokshatest', + 'egg': 'mokshatest', + 'egg_plugins': ['Moksha'], + } + args = { + 'connector': True, + 'connector_name': 'MokshatestConnector', + } + global app + app = setup_quickstart(template=template, templates=templates, args=args, + template_vars=template_vars) + +def teardown(): + teardown_quickstart() +
class TestConnectorQuickstart(QuickstartTester):
- def __init__(self,**options): - self.app = None - self.template_vars = { - 'package': 'mokshatest', - 'project': 'mokshatest', - 'egg': 'mokshatest', - 'egg_plugins': ['Moksha'], - } - self.args = { - 'connector': True, - 'connector_name': 'MokshatestConnector', - } - self.template = MokshaConnectorTemplate - self.templates = ['moksha.connector'] + def setUp(self): + self.app = app
def get_connector(self): return self.get_entry('moksha.connector') diff --git a/moksha/tests/quickstarts/test_consumer.py b/moksha/tests/quickstarts/test_consumer.py index 53bb95e..9bd6a88 100644 --- a/moksha/tests/quickstarts/test_consumer.py +++ b/moksha/tests/quickstarts/test_consumer.py @@ -6,25 +6,37 @@ from datetime import timedelta from moksha.api.hub import Consumer from moksha.pastetemplate import MokshaConsumerTemplate
-from base import QuickstartTester +from base import QuickstartTester, setup_quickstart, teardown_quickstart + +app = None + +def setup(): + template = MokshaConsumerTemplate + templates = ['moksha.consumer'] + template_vars = { + 'package': 'mokshatest', + 'project': 'mokshatest', + 'egg': 'mokshatest', + 'egg_plugins': ['Moksha'], + 'topic': 'moksha.topics.test', + } + args = { + 'consumer': True, + 'consumer_name': 'MokshatestConsumer', + } + global app + app = setup_quickstart(template=template, templates=templates, args=args, + template_vars=template_vars) + + +def teardown(): + teardown_quickstart() +
class TestConsumerQuickstart(QuickstartTester):
- def __init__(self,**options): - self.app = None - self.template_vars = { - 'package': 'mokshatest', - 'project': 'mokshatest', - 'egg': 'mokshatest', - 'egg_plugins': ['Moksha'], - 'topic': 'moksha.topics.test', - } - self.args = { - 'consumer': True, - 'consumer_name': 'MokshatestConsumer', - } - self.template = MokshaConsumerTemplate - self.templates = ['moksha.consumer'] + def setUp(self): + self.app = app
def get_consumer(self): return self.get_entry('moksha.consumer') diff --git a/moksha/tests/quickstarts/test_controller.py b/moksha/tests/quickstarts/test_controller.py index c186902..122d756 100644 --- a/moksha/tests/quickstarts/test_controller.py +++ b/moksha/tests/quickstarts/test_controller.py @@ -3,26 +3,39 @@ import pkg_resources
from datetime import timedelta from moksha.pastetemplate import MokshaControllerTemplate -from base import QuickstartTester
from moksha.lib.base import Controller
+from base import QuickstartTester, setup_quickstart, teardown_quickstart + +app = None + +def setup(): + template_vars = { + 'package': 'mokshatest', + 'project': 'mokshatest', + 'egg': 'mokshatest', + 'egg_plugins': ['Moksha'], + } + args = { + 'controller': True, + 'controller_name': 'MokshatestController', + } + template = MokshaControllerTemplate + templates = ['moksha.controller'] + global app + app = setup_quickstart(template=template, templates=templates, args=args, + template_vars=template_vars) + + +def teardown(): + teardown_quickstart() + + class TestControllerQuickstart(QuickstartTester):
- def __init__(self,**options): - self.app = None - self.template_vars = { - 'package': 'mokshatest', - 'project': 'mokshatest', - 'egg': 'mokshatest', - 'egg_plugins': ['Moksha'], - } - self.args = { - 'controller': True, - 'controller_name': 'MokshatestController', - } - self.template = MokshaControllerTemplate - self.templates = ['moksha.controller'] + def setUp(self): + self.app = app
def get_controller(self): return self.get_entry('moksha.application') diff --git a/moksha/tests/quickstarts/test_livewidget.py b/moksha/tests/quickstarts/test_livewidget.py index aee91c1..1cdcf98 100644 --- a/moksha/tests/quickstarts/test_livewidget.py +++ b/moksha/tests/quickstarts/test_livewidget.py @@ -3,25 +3,36 @@ import pkg_resources
from moksha.pastetemplate import MokshaLiveWidgetTemplate
-from base import QuickstartTester +from base import QuickstartTester, setup_quickstart, teardown_quickstart + +app = None + +def setup(): + template = MokshaLiveWidgetTemplate + templates = ['moksha.livewidget'] + template_vars = { + 'package': 'mokshatest', + 'project': 'mokshatest', + 'egg': 'mokshatest', + 'egg_plugins': ['Moksha'], + 'topic': 'moksha.topics.test', + } + args = { + 'livewidget': True, + 'widget_name': 'MokshatestWidget', + } + + global app + app = setup_quickstart(template=template, templates=templates, args=args, + template_vars=template_vars) + +def teardown(): + teardown_quickstart()
class TestLiveWidgetQuickstart(QuickstartTester):
- def __init__(self,**options): - self.app = None - self.template_vars = { - 'package': 'mokshatest', - 'project': 'mokshatest', - 'egg': 'mokshatest', - 'egg_plugins': ['Moksha'], - 'topic': 'moksha.topics.test', - } - self.args = { - 'livewidget': True, - 'widget_name': 'MokshatestWidget', - } - self.template = MokshaLiveWidgetTemplate - self.templates = ['moksha.livewidget'] + def setUp(self): + self.app = app
def get_widget(self): return self.get_entry('moksha.widget') diff --git a/moksha/tests/quickstarts/test_stream.py b/moksha/tests/quickstarts/test_stream.py index bfaecc2..d08b4ec 100644 --- a/moksha/tests/quickstarts/test_stream.py +++ b/moksha/tests/quickstarts/test_stream.py @@ -6,25 +6,37 @@ from datetime import timedelta from moksha.api.streams import PollingDataStream from moksha.pastetemplate import MokshaStreamTemplate
-from base import QuickstartTester +from base import QuickstartTester, setup_quickstart, teardown_quickstart + +app = None + +def setup(): + template = MokshaStreamTemplate + templates = ['moksha.stream'] + template_vars = { + 'package': 'mokshatest', + 'project': 'mokshatest', + 'egg': 'mokshatest', + 'egg_plugins': ['Moksha'], + 'topic': 'moksha.topics.test', + } + args = { + 'stream': True, + 'stream_name': 'MokshatestStream', + } + global app + app = setup_quickstart(template=template, templates=templates, args=args, + template_vars=template_vars) + +def teardown(): + teardown_quickstart() + +
class TestStreamQuickstart(QuickstartTester):
- def __init__(self,**options): - self.app = None - self.template_vars = { - 'package': 'mokshatest', - 'project': 'mokshatest', - 'egg': 'mokshatest', - 'egg_plugins': ['Moksha'], - 'topic': 'moksha.topics.test', - } - self.args = { - 'stream': True, - 'stream_name': 'MokshatestStream', - } - self.template = MokshaStreamTemplate - self.templates = ['moksha.stream'] + def setUp(self): + self.app = app
def get_stream(self): return self.get_entry('moksha.stream')
commit 4db2cc1754cc88e04a0a66766d1db8a69612a989 Author: Luke Macken lmacken@redhat.com Date: Thu Sep 24 08:47:38 2009 -0400
Ensure our Connector middleware can handle invalid requests
diff --git a/moksha/middleware/connector.py b/moksha/middleware/connector.py index 8c5638b..9632b98 100644 --- a/moksha/middleware/connector.py +++ b/moksha/middleware/connector.py @@ -85,9 +85,13 @@ class MokshaConnectorMiddleware(object): if params[k] and len(params[k]) == 1: params[k] = params[k][0]
- response = self._run_connector(environ, request, - s[0], s[1], *s[2:], - **params) + try: + response = self._run_connector(environ, request, + s[0], s[1], *s[2:], + **params) + except IndexError, e: + log.info('Invalid connector path: %s' % str(e)) + return Response(status='404 Not Found')(environ, start_response) else: response = request.get_response(self.application)
diff --git a/moksha/tests/quickstarts/test_connector.py b/moksha/tests/quickstarts/test_connector.py index f611b0d..2c40280 100644 --- a/moksha/tests/quickstarts/test_connector.py +++ b/moksha/tests/quickstarts/test_connector.py @@ -34,6 +34,9 @@ class TestConnectorQuickstart(QuickstartTester): resp = self.app.get('/moksha_connector/mokshatest/call/foo') assert "MokshatestConnector.call('foo')" in resp, resp.body
+ def test_failed_connector_call(self): + self.app.get('/moksha_connector/foo', status=404) + def test_connector_query(self): """ Ensure we can perform a basic connector query """ resp = self.app.get('/moksha_connector/mokshatest/query/query_stuff/')
moksha-commits@lists.fedorahosted.org