diff --git a/tests/selenium/testing.ini b/example_testing.ini similarity index 91% rename from tests/selenium/testing.ini rename to example_testing.ini index 91cdf0f..d7770ef 100644 --- a/tests/selenium/testing.ini +++ b/example_testing.ini @@ -1,8 +1,8 @@ [testconfig] selenium.driver = firefox -base_url = http://localhost:5000 -default_login_url = http://localhost:5000/login +app_port = 5000 +default_login_url = http://localhost:%(app_port)d/login test_providers = # facebook @@ -98,8 +98,3 @@ velruse.twitter.authorize = # Yahoo (also requires OpenID configuration) velruse.yahoo.consumer_key = velruse.yahoo.consumer_secret = - -[server:main] -use = egg:Paste#http -host = 0.0.0.0 -port = 5000 diff --git a/setup.cfg b/setup.cfg index 2d86594..53b96b1 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,7 +1,6 @@ [aliases] docs = develop easy_install velruse[docs] dev = develop easy_install velruse[testing] -test = nosetests [nosetests] match=^test diff --git a/setup.py b/setup.py index 8e9657b..12f754a 100644 --- a/setup.py +++ b/setup.py @@ -19,6 +19,7 @@ testing_extras = [ 'nose', 'selenium', + 'webtest', ] docs_extras = [ diff --git a/tests/selenium/setup.py b/tests/selenium/setup.py deleted file mode 100644 index 882b8ac..0000000 --- a/tests/selenium/setup.py +++ /dev/null @@ -1,20 +0,0 @@ -from setuptools import setup - -requires = [ - 'pyramid', - 'velruse', -] - -setup(name='testapp', - version='0.0', - packages=['testapp'], - install_requires=[ - 'pyramid', - 'velruse', - 'selenium', - ], - entry_points="""\ - [paste.app_factory] - main = testapp:main - """, - ) diff --git a/tests/selenium/tests.py b/tests/selenium/tests.py index 6df466c..7d85846 100644 --- a/tests/selenium/tests.py +++ b/tests/selenium/tests.py @@ -4,28 +4,46 @@ from nose.plugins.skip import SkipTest +from pyramid.paster import get_app + from selenium import webdriver from selenium.webdriver.support.ui import WebDriverWait +from webtest.http import StopableWSGIServer + from velruse._compat import ConfigParser config = {} browser = None # populated in setUpModule +server = None # populated in setUpModule def splitlines(s): - return filter(None, [c.strip() for x in s.splitlines() - for c in x.split(', ')]) + return filter(None, [c.strip() + for x in s.splitlines() + for c in x.split(', ')]) def setUpModule(): - global browser, config + global browser, server + + inipath = os.path.abspath( + os.environ.get('TEST_INI', 'testing.ini')) + if not os.path.isfile(inipath): + raise RuntimeError( + 'Cannot find INI file to setup selenium tests. ' + 'Please specify the path via the TEST_INI environment variable ' + 'or by adding a testing.ini file to the current directory.') + + parser = ConfigParser() + parser.read(inipath) - inipath = os.environ.get('TEST_INI', 'testing.ini') - if os.path.isfile(inipath): - parser = ConfigParser() - parser.read(inipath) + config.update(parser.items('testconfig')) + config['test_providers'] = splitlines(config['test_providers']) - config = dict(parser.items('testconfig')) - config['test_providers'] = splitlines(config['test_providers']) + app = get_app(inipath) + port = int(config['app_port']) + server = StopableWSGIServer(app, port=port) + server.run() + server.wait() driver = config.get('selenium.driver', 'firefox') browser = { @@ -37,6 +55,8 @@ def setUpModule(): def tearDownModule(): if browser is not None: browser.quit() + if server is not None: + server.shutdown() class ProviderTests(object): @@ -45,6 +65,9 @@ def require_provider(cls, name): if name not in config.get('test_providers', []): raise SkipTest('tests not enabled for "%s"' % name) + def setUp(self): + browser.delete_all_cookies() + def find_login_url(config, key): return config.get(key, config['default_login_url']) @@ -64,9 +87,6 @@ def setUpClass(cls): cls.app = config['facebook.app'] cls.login_url = find_login_url(config, 'facebook.login_url') - def setUp(self): - browser.delete_all_cookies() - def test_it(self): browser.get(self.login_url) self.assertEqual(browser.title, 'Auth Page') @@ -100,9 +120,6 @@ def setUpClass(cls): cls.app = config['github.app'] cls.login_url = find_login_url(config, 'github.login_url') - def setUp(self): - browser.delete_all_cookies() - def test_it(self): from velruse._compat import u browser.get(self.login_url) @@ -135,9 +152,6 @@ def setUpClass(cls): cls.app = config['twitter.app'] cls.login_url = find_login_url(config, 'twitter.login_url') - def setUp(self): - browser.delete_all_cookies() - def test_it(self): browser.get(self.login_url) self.assertEqual(browser.title, 'Auth Page') @@ -171,9 +185,6 @@ def setUpClass(cls): cls.app = config['bitbucket.app'] cls.login_url = find_login_url(config, 'bitbucket.login_url') - def setUp(self): - browser.delete_all_cookies() - def test_it(self): browser.get(self.login_url) self.assertEqual(browser.title, 'Auth Page') @@ -208,9 +219,6 @@ def setUpClass(cls): cls.password = config['google.password'] cls.login_url = find_login_url(config, 'google.login_url') - def setUp(self): - browser.delete_all_cookies() - def test_it(self): browser.get(self.login_url) self.assertEqual(browser.title, 'Auth Page') @@ -242,9 +250,6 @@ def setUpClass(cls): cls.password = config['yahoo.password'] cls.login_url = find_login_url(config, 'yahoo.login_url') - def setUp(self): - browser.delete_all_cookies() - def test_it(self): browser.get(self.login_url) self.assertEqual(browser.title, 'Auth Page') @@ -282,9 +287,6 @@ def setUpClass(cls): cls.password = config['live.password'] cls.login_url = find_login_url(config, 'live.login_url') - def setUp(self): - browser.delete_all_cookies() - def test_it(self): browser.get(self.login_url) self.assertEqual(browser.title, 'Auth Page') diff --git a/velruse/app/__init__.py b/velruse/app/__init__.py index 9d4eee3..2ca1f3a 100644 --- a/velruse/app/__init__.py +++ b/velruse/app/__init__.py @@ -113,6 +113,7 @@ def register_velruse_store(config, storage): """ config.registry.velruse_store = storage + settings_adapter = { 'bitbucket': 'add_bitbucket_login_from_settings', 'douban': 'add_douban_login_from_settings',