def setup_module(): global app, app_murdoc config.set_profile('test') app = controllers.make_app() app = BespinTestApp(app) app_murdoc = controllers.make_app() app_murdoc = BespinTestApp(app_murdoc) _install_test_plugin_path() config.activate_profile()
def _reset(): Base.metadata.drop_all(bind=config.c.dbengine) Base.metadata.create_all(bind=config.c.dbengine) fsroot = config.c.fsroot if fsroot.exists() and fsroot.basename() == "testfiles": fsroot.rmtree() fsroot.makedirs() global session session = config.c.session_factory() num_users = session.query(User).count() assert_equals(num_users, 0) session.commit() global mattb, zuck, tom, ev, joe mattb = User.create_user("mattb", "mattb", "mattb") zuck = User.create_user("zuck", "zuck", "zuck") tom = User.create_user("tom", "tom", "tom") ev = User.create_user("ev", "ev", "ev") joe = User.create_user("joe", "joe", "joe") group = joe.add_group("group") group.add_member(mattb) group.add_member(zuck) group.add_member(tom) group.add_member(ev) global app app = controllers.make_app() app = BespinTestApp(app) app.post("/register/login/joe", dict(password="******"))
def start(): """Starts the BespinServer on localhost port 8080 for development. You can change the port and allow remote connections by setting server.port or server.address on the command line. paver server.address=your.ip.address server.port=8000 start will allow remote connections (assuming you don't have a firewall blocking the connection) and start the server on port 8000. """ # automatically install Dojo if it's not there already if not (options.dojo.destination / "dojo").exists(): dojo() from bespin import config, controllers from paste.httpserver import serve options.order('server') config.set_profile('dev') if options.server.try_build: config.c.static_dir = (options.build_dir / "frontend").abspath() if options.server.dburl: config.c.dburl = options.server.dburl if options.server.async: config.c.async_jobs = True config.c.queue_path = path.getcwd() / "queue.db" config.activate_profile() port = int(options.port) serve(controllers.make_app(), options.address, port, use_threadpool=True)
def test_login_without_cookie(): s = _get_session(True) User.create_user("BillBixby", "hulkrulez", "*****@*****.**") app = controllers.make_app() app = BespinTestApp(app) resp = app.post("/register/login/BillBixby", dict(password="******")) assert resp.cookies_set['auth_tkt']
def test_bad_login_yields_401(): s = _get_session(True) User.create_user("BillBixby", "hulkrulez", "*****@*****.**") app = controllers.make_app() app = BespinTestApp(app) resp = app.post("/register/login/BillBixby", dict(password="******"), status=401)
def test_register_and_verify_user(): config.activate_profile() _clear_db() s = _get_session() app = controllers.make_app() app = BespinTestApp(app) resp = app.post('/register/new/BillBixby', dict(email="*****@*****.**", password="******")) assert resp.content_type == "application/json" data = simplejson.loads(resp.body) assert data == {} assert resp.cookies_set['auth_tkt'] assert app.cookies billbixby = User.find_user("BillBixby") sample_project = get_project(billbixby, billbixby, "SampleProject") files = [file.name for file in sample_project.list_files()] assert "readme.txt" in files # should be able to run again without an exception appearing resp = app.post('/register/new/BillBixby', dict(email="*****@*****.**", password="******"), status=409) # with the cookie set, we should be able to retrieve the # logged in name resp = app.get('/register/userinfo/') assert resp.content_type == 'application/json' data = simplejson.loads(resp.body) assert data['username'] == 'BillBixby' assert 'quota' in data assert data['quota'] == 15728640 assert 'amountUsed' in data resp = app.get("/file/at/BespinSettings/config") app.post("/file/close/BespinSettings/config")
def test_bad_ticket_is_ignored(): _clear_db() app = controllers.make_app() app = BespinTestApp(app) resp = app.post("/register/new/Aldus", dict(password="******", email="*****@*****.**")) app.cookies['auth_tkt'] = app.cookies['auth_tkt'][:-1] resp = app.get("/preview/at/SampleProjectFor%3AAldus/index.html", status=401)
def test_userinfo_also_returns_capabilities(): _clear_db() app = controllers.make_app() app = BespinTestApp(app) resp = app.post("/register/new/BillBixby", dict(email="*****@*****.**", password="******")) resp = app.get("/register/userinfo/") data = simplejson.loads(resp.body) print data assert "serverCapabilities" in data
def test_static_files_with_auth(): _clear_db() app = controllers.make_app() app = BespinTestApp(app) resp = app.get('/editor.html', status=302) assert resp.location == "http://localhost/" resp = app.post('/register/new/Aldus', dict(password="******", email="*****@*****.**")) resp = app.get('/editor.html')
def test_logout(): s, user_manager = _get_user_manager(True) user_manager.create_user("BillBixby", "hulkrulez", "*****@*****.**") app = controllers.make_app() app = TestApp(app) resp = app.post("/register/login/BillBixby", dict(password='******')) resp = app.get("/register/logout/") assert resp.cookies_set['auth_tkt'] == '""'
def test_server_capabilities(): _clear_db() app = controllers.make_app() app = BespinTestApp(app) resp = app.post("/register/new/BillBixby", dict(email="*****@*****.**", password="******")) resp = app.get("/capabilities/") assert resp.content_type == "application/json" data = simplejson.loads(resp.body) print data assert data == dict(capabilities=["vcs"], dojoModulePath={}, javaScriptPlugins=[])
def test_userinfo_also_returns_capabilities(): _clear_db() app = controllers.make_app() app = BespinTestApp(app) resp = app.post('/register/new/BillBixby', dict(email="*****@*****.**", password="******")) resp = app.get('/register/userinfo/') data = simplejson.loads(resp.body) print data assert 'serverCapabilities' in data
def setup_module(module): global app, session config.set_profile('test') config.activate_profile() Base.metadata.drop_all(bind=config.c.dbengine) Base.metadata.create_all(bind=config.c.dbengine) session = config.c.session_factory() User.create_user("BillBixby", "", "*****@*****.**") app = controllers.make_app() app = BespinTestApp(app) app.post("/register/login/BillBixby", dict(password=""))
def test_username_with_bad_characters(): _clear_db() app = controllers.make_app() app = BespinTestApp(app) resp = app.post("/register/new/Thinga%20Majig", dict(password="******", email="thinga@majig"), status=400) resp = app.post("/register/new/Thinga<majig>", dict(password="******", email="thinga@majig"), status=400) resp = app.post("/register/new/Thing/", dict(password="******", email="thinga@majig"), status=400) resp = app.post("/register/new/..", dict(password="******", email="thinga@majig"), status=400)
def setup_module(module): global user_manager, app, session config.set_profile('test') config.activate_profile() model.Base.metadata.drop_all(bind=config.c.dbengine) model.Base.metadata.create_all(bind=config.c.dbengine) session = config.c.sessionmaker(bind=config.c.dbengine) user_manager = model.UserManager(session) user_manager.create_user("BillBixby", "", "*****@*****.**") app = controllers.make_app() app = TestApp(app) app.post("/register/login/BillBixby", dict(password=""))
def test_server_capabilities(): _clear_db() app = controllers.make_app() app = BespinTestApp(app) resp = app.post('/register/new/BillBixby', dict(email="*****@*****.**", password="******")) resp = app.get("/capabilities/") assert resp.content_type == "application/json" data = simplejson.loads(resp.body) print data assert data == dict(capabilities=["vcs"], dojoModulePath={}, javaScriptPlugins=[])
def test_register_existing_user_should_not_authenticate(): s = _get_session(True) app_orig = controllers.make_app() app = BespinTestApp(app_orig) resp = app.post('/register/new/BillBixby', dict(email="*****@*****.**", password="******")) app = BespinTestApp(app_orig) resp = app.post("/register/new/BillBixby", dict(email="*****@*****.**", password="******"), status=409) assert not resp.cookies_set user = User.find_user("BillBixby", 'notangry') assert user is not None
def test_register_existing_user_should_not_authenticate(): s, user_manager = _get_user_manager(True) app_orig = controllers.make_app() app = TestApp(app_orig) resp = app.post('/register/new/BillBixby', dict(email="*****@*****.**", password="******")) app = TestApp(app_orig) resp = app.post("/register/new/BillBixby", dict(email="*****@*****.**", password="******"), status=409) assert not resp.cookies_set user = user_manager.get_user("BillBixby") assert user.password == 'notangry'
def test_password_change_bad_code(): config.set_profile("test") config.activate_profile() _clear_db() app = controllers.make_app() app = BespinTestApp(app) resp = app.post('/register/new/BillBixby', dict(email="*****@*****.**", password="******")) app.reset() resp = app.post('/register/password/BillBixby', dict(code="42", newPassword="******"), status=400)
def test_get_users_settings(): _clear_db() app = controllers.make_app() app = BespinTestApp(app) resp = app.post("/register/new/macgyver", dict(password="******", email="*****@*****.**")) resp = app.put("/file/at/BespinSettings/settings", """ vcsuser Mack Gyver <*****@*****.**> """) s = _get_session() macgyver = User.find_user("macgyver") settings = macgyver.get_settings() assert settings == dict(vcsuser="******")
def test_password_change_bad_code(): config.set_profile("test") config.activate_profile() _clear_db() app = controllers.make_app() app = BespinTestApp(app) resp = app.post('/register/new/BillBixby', dict(email="*****@*****.**", password="******")) app.reset() resp = app.post('/register/password/BillBixby', dict( code="42", newPassword="******"), status=400)
def test_lost_username(send_text_email): config.set_profile("test") config.activate_profile() _clear_db() app = controllers.make_app() app = BespinTestApp(app) resp = app.post('/register/new/BillBixby', dict(email="*****@*****.**", password="******")) resp = app.post('/register/lost/', dict(email='*****@*****.**')) assert send_text_email.called args = send_text_email.call_args[0] assert args[0] == '*****@*****.**' assert args[1].startswith("Your username for ") assert "Your username is:" in args[2] assert "BillBixby" in args[2]
def test_password_change_with_confirmation_code(): config.set_profile("test") config.activate_profile() _clear_db() app = controllers.make_app() app = BespinTestApp(app) resp = app.post('/register/new/BillBixby', dict(email="*****@*****.**", password="******")) app.reset() user = User.find_user("BillBixby") verify_code = controllers._get_password_verify_code(user) resp = app.post('/register/password/BillBixby', dict(code=verify_code, newPassword="******")) user = User.find_user('BillBixby', 'hatetraffic') assert user
def test_users_can_be_locked_out(): config.set_profile("test") config.c.login_failure_tracking = "memory" config.c.login_attempts = "1" config.c.lockout_period = "1" config.activate_profile() app = controllers.make_app() app = BespinTestApp(app) _clear_db() resp = app.post('/register/new/BillBixby', dict(email="*****@*****.**", password="******")) resp = app.post("/register/login/BillBixby", dict(password="******"), status=401) # fail with good password now, because we're locked out resp = app.post("/register/login/BillBixby", dict(password="******"), status=401)
def test_password_change_with_confirmation_code(): config.set_profile("test") config.activate_profile() _clear_db() app = controllers.make_app() app = BespinTestApp(app) resp = app.post('/register/new/BillBixby', dict(email="*****@*****.**", password="******")) app.reset() user = User.find_user("BillBixby") verify_code = controllers._get_password_verify_code(user) resp = app.post('/register/password/BillBixby', dict( code=verify_code, newPassword="******")) user = User.find_user('BillBixby', 'hatetraffic') assert user
def test_lost_password_request(send_text_email): config.set_profile("test") config.activate_profile() _clear_db() app = controllers.make_app() app = BespinTestApp(app) resp = app.post('/register/new/BillBixby', dict(email="*****@*****.**", password="******")) app.reset() resp = app.post('/register/lost/', dict(username='******')) assert send_text_email.called args = send_text_email.call_args[0] assert args[0] == '*****@*****.**' assert args[1].startswith("Requested password change for ") user = User.find_user("BillBixby") verify_code = controllers._get_password_verify_code(user) assert verify_code in args[2]
def test_messages_sent_from_server_to_user(): _clear_db() app = controllers.make_app() app = BespinTestApp(app) resp = app.post("/register/new/macgyver", dict(password="******", email="*****@*****.**")) s = _get_session() macgyver = User.find_user("macgyver") assert len(macgyver.messages) == 0 macgyver.publish(dict(my="message")) s.commit() resp = app.post("/messages/") assert resp.content_type == "application/json" data = simplejson.loads(resp.body) assert len(data) == 1 assert data[0] == dict(my="message") # the message should be consumed resp = app.post("/messages/") data = simplejson.loads(resp.body) assert len(data) == 0
def start(): """Starts the BespinServer on localhost port 8080 for development. You can change the port and allow remote connections by setting server.port or server.address on the command line. paver server.address=your.ip.address server.port=8000 start will allow remote connections (assuming you don't have a firewall blocking the connection) and start the server on port 8000. """ # automatically install Dojo if it's not there already if not (options.dojo.destination / "dojo").exists(): dojo() from bespin import config, controllers from paste.httpserver import serve options.order('server') config.set_profile('dev') if options.server.try_build: config.c.static_dir = (options.build_dir / "frontend").abspath() if options.server.dburl: config.c.dburl = options.server.dburl if options.server. async: config.c.async_jobs = True config_file = options.server.config_file if config_file.exists(): info("Loading config: %s", config_file) code = compile(config_file.bytes(), config_file, "exec") exec code in {} config.activate_profile() port = int(options.port) serve(controllers.make_app(), options.address, port, use_threadpool=True)
def start(): """Starts the BespinServer on localhost port 8080 for development. You can change the port and allow remote connections by setting server.port or server.address on the command line. paver server.address=your.ip.address server.port=8000 start will allow remote connections (assuming you don't have a firewall blocking the connection) and start the server on port 8000. """ from bespin import config, controllers from paste.httpserver import serve options.order('server') config.set_profile('dev') if options.staticdir: config.c.static_dir = path(options.clientdir) / options.staticdir if options.server.dburl: config.c.dburl = options.server.dburl if options.server. async: config.c.async_jobs = True config.c.server_base_url = options.server_base_url config_file = options.server.config_file if config_file.exists(): info("Loading config: %s", config_file) code = compile(config_file.bytes(), config_file, "exec") exec code in {} config.activate_profile() port = int(options.port) serve(controllers.make_app(), options.address, port, use_threadpool=True)
def start(): """Starts the BespinServer on localhost port 8080 for development. You can change the port and allow remote connections by setting server.port or server.address on the command line. paver server.address=your.ip.address server.port=8000 start will allow remote connections (assuming you don't have a firewall blocking the connection) and start the server on port 8000. """ from bespin import config, controllers from paste.httpserver import serve options.order('server') config.set_profile('dev') if options.staticdir: config.c.static_dir = path(options.clientdir) / options.staticdir if options.server.dburl: config.c.dburl = options.server.dburl if options.server.async: config.c.async_jobs = True config.c.server_base_url = options.server_base_url config_file = options.server.config_file if config_file.exists(): info("Loading config: %s", config_file) code = compile(config_file.bytes(), config_file, "exec") exec code in {} config.activate_profile() port = int(options.port) serve(controllers.make_app(), options.address, port, use_threadpool=True)
def setup_module(module): global app config.set_profile('test') app = controllers.make_app() app = BespinTestApp(app) logging.basicConfig(level=logging.DEBUG)
def dev_factory(config): from bespin.controllers import make_app return make_app()
def test_auth_required(): app = controllers.make_app() app = BespinTestApp(app) app.post('/settings/', {'foo' : 'bar'}, status=401) app.get('/settings/', status=401) app.get('/settings/foo', status=401)
def test_api_version_header(): app = controllers.make_app() app = BespinTestApp(app) resp = app.get("/register/userinfo/", status=401) assert resp.headers.get("X-Bespin-API") == "dev"
def setup_module(module): global app config.set_profile('test') app = controllers.make_app() app = TestApp(app)
def setup_module(module): global app config.set_profile('test') app = controllers.make_app() app = BespinTestApp(app)
def test_register_returns_empty_when_not_logged_in(): app = controllers.make_app() app = BespinTestApp(app) resp = app.get('/register/userinfo/', status=401) assert resp.body == ""
def setup_module(module): global app config.set_profile("test") app = controllers.make_app() app = BespinTestApp(app)