Skip to content

Commit

Permalink
start reworking tests to run in-process wsgi server
Browse files Browse the repository at this point in the history
  • Loading branch information
mmerickel committed Jun 10, 2013
1 parent 286597a commit ce4b685
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 58 deletions.
9 changes: 2 additions & 7 deletions tests/selenium/testing.ini → example_testing.ini
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
1 change: 0 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[aliases]
docs = develop easy_install velruse[docs]
dev = develop easy_install velruse[testing]
test = nosetests

[nosetests]
match=^test
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
testing_extras = [
'nose',
'selenium',
'webtest',
]

docs_extras = [
Expand Down
20 changes: 0 additions & 20 deletions tests/selenium/setup.py

This file was deleted.

62 changes: 32 additions & 30 deletions tests/selenium/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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):

Expand All @@ -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'])

Expand All @@ -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')
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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')
Expand Down
1 change: 1 addition & 0 deletions velruse/app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit ce4b685

Please sign in to comment.