def setUp(self): """Launch pserve using webtest with test settings""" self.appconf = get_app(test_ini) self.app = TestApp(self.appconf) #For speed, allow cookie setting. # self.app.cookiejar.set_policy(DefaultCookiePolicy(allowed_domains=[])) # This sets global var "engine" - in the case of SQLite this is a fresh RAM # DB each time. If we only did this on class instantiation the database would # be dirty and one test could influence another. # TODO - add a test that tests this. server.choose_engine("SQLite") # Punch in new administrator account with direct server call # This will implicitly generate the tables. user_id = server.create_user("administrators", "administrator", "administrator", "administrator") #server.touch_to_add_user_group("administrator", "administrators") server.touch_to_add_password(user_id, "adminpass") self.app.authorization = ('Basic', ('administrator', 'adminpass')) # This sorts out the auth token cookie. self.app.get('/users') self.app.authorization = None
def setUp(self): """Launch app using webtest with test settings""" self.appconf = get_app(test_ini) self.app = TestApp(self.appconf) #All auth via BasicAuth - never return the session cookie. self.app.cookiejar.set_policy(DefaultCookiePolicy(allowed_domains=[])) # This sets global var "engine" - in the case of SQLite this is a fresh RAM # DB each time. If we only did this on class instantiation the database would # be dirty and one test could influence another. # TODO - add a test that tests this. server.choose_engine("SQLite") # Punch in new user account with direct server call # This will implicitly generate the tables. user_id = self.create_user("testuser") #Here is what the user should look like when inspected self.user_json = { "name" : "testuser testuser", "handle" : "*****@*****.**", "id" : 1, "credits" : 0, "username": "******"} #print("user_id is %s" % str(user_id)) #print("user_from_db_is %s" % server.get_user_id_from_name("testuser")) server.touch_to_add_password(user_id, "asdf") # And log in as this user for all tests (via BasicAuth) # FIXME - switch to token auth to speed up the tests. self.app.authorization = ('Basic', ('testuser', 'asdf'))
def setUp(self): """Launch pserve using webtest with test settings""" #Nope, do this for each test... #self.appconf = get_app(test_ini) #self.app = TestApp(self.appconf) server.choose_engine("SQLite") # Sets global var "engine" - in the # case of SQLite this is a fresh RAM # DB each time. # Create new user. For not much reason. user_id = server.create_user("users", "testuser", "testuser", "testuser") server.touch_to_add_credit(user_id, 200)
def setUp(self): """Launch pserve using webtest with test settings""" self.appconf = get_app(test_ini) self.app = TestApp(self.appconf) # Punch in new administrator account with direct server call server.choose_engine("SQLite") # Sets global var "engine" - in the # case of SQLite this is a fresh RAM # DB each time. # Create new user. This will implicitly generate the tables. id1 = server.create_user(None, "testuser", "testuser", "testuser") server.touch_to_add_user_group("testuser", "users") server.touch_to_add_password(id1, "testpass") id2 = server.create_user(None, "administrator", "administrator", "administrator") server.touch_to_add_user_group("administrator", "administrators") server.touch_to_add_password(id2, "adminpass")
def main(global_config, **settings): """ Set routes, authentication policies, and add callbacks to modify responses.""" agent_spec = [("agent", get_secret(settings, "agent"), "agents")] hap = HybridAuthenticationPolicy(hardcoded=agent_spec, secret=get_secret(settings, "authtkt"), realm="eos_db") config = Configurator(settings=settings, authentication_policy=hap, root_factory="eos_db.views.PermissionsMap") config.add_subscriber(add_cors_callback, NewRequest) config.add_subscriber(add_cookie_callback, NewRequest) # Needed to ensure proper 401 responses config.add_forbidden_view(hap.get_forbidden_view) # Do this if you need extra info generated by the Configurator, but # we do not. # settings = config.registry.settings # Set the engine, but only if it's not already set. This is useful # for testing where we can re-initialise the webapp while leaving the # database in place. server.choose_engine(settings["server"], replace=False) # Top-level home page. Yields API call list. config.add_route("home", "/") # User-related API calls (callable by users) config.add_route("users", "/users") # Return user list config.add_route("my_user", "/user") # Return info about me (including credit) config.add_route("my_password", "/user/password") # Set my password (only for admins or self) config.add_route("my_touches", "/user/touches") # Get server touches # User-related API calls (callable by Actors/Admins) config.add_route("user", "/users/{name}") # Get user details or # Put new user or # Delete user config.add_route("user_touches", "/users/{name}/touches") # Get server touches config.add_route("user_password", "/users/{name}/password") # Put new password # Get password verification by posting # password=asdf ?? Or not? config.add_route("user_credit", "/users/{name}/credit") # Put new credit or debit # Get current balance # Server-related API calls config.add_route("servers", "/servers") # Return server list config.add_route("server", "/servers/{name}") # Get server details or # Post new server or # Delete server # This is used by the agents. Can help to be absolutely sure you are talking # about the right server. config.add_route("server_by_id", "/servers/by_id/{id}") # Server state-related calls. config.add_route("states", "/states") # Get summary count of servers in each state config.add_route("state", "/states/{name}") # Get list of servers in # the given state. config.add_route("deboosts", "/deboost_jobs") # Get list of servers wanting deboost # Define PUT calls to put the server into various states. Each call is backed # by a separate function in views.py, and mostly these just add a touch, but # they may implement custom functionality, for example to check and deduct # credit when boosting, or to limit who can change to certain states. for state in server.get_state_list(): config.add_route("server_" + state, "/servers/{name}/" + state) config.add_route("server_by_id_" + state, "/servers/by_id/{id}/" + state) # Call to state, owner, touches and get/set specification. for action in ("specification", "state", "owner", "touches"): config.add_route("server_" + action, "/servers/{name}/" + action) config.add_route("server_by_id_" + action, "/servers/by_id/{id}/" + action) # Call the extend boost which does not correspond to any state change for action in ("extend_boost",): config.add_route("server_" + action, "/servers/{name}/" + action) config.add_route("server_by_id_" + action, "/servers/by_id/{id}/" + action) config.scan() return config.make_wsgi_app()
def main(global_config, **settings): """ Set routes, authentication policies, and add callbacks to modify responses.""" agent_spec = [('agent', get_secret(settings, 'agent'), 'agents')] hap = HybridAuthenticationPolicy(hardcoded=agent_spec, secret=get_secret(settings, "authtkt"), realm="eos_db") config = Configurator(settings=settings, authentication_policy=hap, root_factory='eos_db.views.PermissionsMap') config.add_subscriber(add_cors_callback, NewRequest) config.add_subscriber(add_cookie_callback, NewRequest) # Needed to ensure proper 401 responses config.add_forbidden_view(hap.get_forbidden_view) # Do this if you need extra info generated by the Configurator, but # we do not. #settings = config.registry.settings # Load the default configuration file, based on the .ini file name # And hey, I found a use for global_config! settings_json = global_config['__file__'][:-4] + ".settings.json" if os.path.isfile(settings_json): server.load_config_json(settings_json) # Set the engine, but only if it's not already set. This is useful # for testing where we can re-initialise the webapp while leaving the # database in place. server.choose_engine(settings['server'], replace=False) # Endpoints that can be called without authentication # Top-level home page. Yields API call list. config.add_route('home', '/') # View of BoostLevels from settings.py config.add_route('boostlevels', '/boostlevels') # User-related API calls (callable by users) config.add_route('users', '/users') # Return user list config.add_route('my_user', '/user') # Return info about me (including credit) config.add_route( 'my_password', '/user/password') # Set my password (only for admins or self) config.add_route('my_touches', '/user/touches') # Get server touches # User-related API calls (callable by Actors/Admins) config.add_route('user', '/users/{name}') # Get user details or # Put new user or # Delete user config.add_route('user_touches', '/users/{name}/touches') # Get server touches config.add_route('user_password', '/users/{name}/password') # Put new password # Get password verification by posting # password=asdf ?? Or not? config.add_route('user_credit', '/users/{name}/credit') # Put new credit or debit # Get current balance # Server-related API calls config.add_route('servers', '/servers') # Return server list config.add_route('server', '/servers/{name}') # Get server details or # Post new server or # Delete server #This is used by the agents. Can help to be absolutely sure you are talking #about the right server. config.add_route('server_by_id', '/servers/by_id/{id}') # Server state-related calls. config.add_route('states', '/states') # Get summary count of servers in each state config.add_route('state', '/states/{name}') # Get list of servers in # the given state. config.add_route('deboosts', '/deboost_jobs') # Get list of servers wanting deboost #Define PUT calls to put the server into various states. Each call is backed #by a separate function in views.py, and mostly these just add a touch, but #they may implement custom functionality, for example to check and deduct #credit when boosting, or to limit who can change to certain states. for state in server.get_state_list(): config.add_route('server_' + state, '/servers/{name}/' + state) config.add_route('server_by_id_' + state, '/servers/by_id/{id}/' + state) #Call to state, owner, touches and get/set specification. for action in ('specification', 'state', 'owner', 'touches'): config.add_route('server_' + action, '/servers/{name}/' + action) config.add_route('server_by_id_' + action, '/servers/by_id/{id}/' + action) # Call the extend boost which does not correspond to any state change for action in ('extend_boost', ): config.add_route('server_' + action, '/servers/{name}/' + action) config.add_route('server_by_id_' + action, '/servers/by_id/{id}/' + action) config.scan() return config.make_wsgi_app()
def setUp(self): choose_engine('SQLite')