[llvm-commits] [zorg] r125866 - /zorg/trunk/llvmlab/llvmlab/ui/app.py
Daniel Dunbar
daniel at zuster.org
Fri Feb 18 08:40:56 PST 2011
Author: ddunbar
Date: Fri Feb 18 10:40:55 2011
New Revision: 125866
URL: http://llvm.org/viewvc/llvm-project?rev=125866&view=rev
Log:
llvmlab: Add App.create_test_instance().
Modified:
zorg/trunk/llvmlab/llvmlab/ui/app.py
Modified: zorg/trunk/llvmlab/llvmlab/ui/app.py
URL: http://llvm.org/viewvc/llvm-project/zorg/trunk/llvmlab/llvmlab/ui/app.py?rev=125866&r1=125865&r2=125866&view=diff
==============================================================================
--- zorg/trunk/llvmlab/llvmlab/ui/app.py (original)
+++ zorg/trunk/llvmlab/llvmlab/ui/app.py Fri Feb 18 10:40:55 2011
@@ -9,27 +9,52 @@
class App(flask.Flask):
@staticmethod
- def create_standalone():
+ def create_standalone(config = None, data = None):
# Construct the application.
app = App(__name__)
# Load the application configuration.
- app.load_config()
+ app.load_config(config)
# Load the database.
- app.load_data()
+ app.load_data(data)
# Load the application routes.
app.register_module(llvmlab.ui.views.ui)
return app
+ @staticmethod
+ def create_test_instance():
+ secret_key = "not so secret"
+
+ # Manually construct a test configuration.
+ #
+ # FIXME: Would be nice to vet that this matches the sample config.
+ config = {
+ "ADMIN_LOGIN" : "admin",
+ "ADMIN_PASSHASH" : hashlib.sha256(
+ "admin" + secret_key).hexdigest(),
+ "ADMIN_NAME" : "Administrator",
+ "ADMIN_EMAIL" : "admin at example.com",
+ "DEBUG" : True,
+ "SECRET_KEY" : secret_key,
+ "DATA_PATH" : None }
+
+ # Construct an empty test database.
+ data = llvmlab.data.Data(users = [])
+
+ return App.create_standalone(config, data)
+
def __init__(self, name):
super(App, self).__init__(name)
- def load_config(self):
- # Load the configuration file.
- self.config.from_envvar("LLVMLAB_CONFIG")
+ def load_config(self, config = None):
+ if config is None:
+ # Load the configuration file.
+ self.config.from_envvar("LLVMLAB_CONFIG")
+ else:
+ self.config.update(config)
# Set the application secret key.
self.secret_key = self.config["SECRET_KEY"]
@@ -37,14 +62,15 @@
# Set the debug mode.
self.debug = self.config["DEBUG"]
- def load_data(self):
- data_path = self.config["DATA_PATH"]
- data_file = open(data_path, "rb")
- data_object = flask.json.load(data_file)
- data_file.close()
+ def load_data(self, data = None):
+ if data is None:
+ data_path = self.config["DATA_PATH"]
+ data_file = open(data_path, "rb")
+ data_object = flask.json.load(data_file)
+ data_file.close()
- # Create the internal Data object.
- data = llvmlab.data.Data.fromdata(data_object)
+ # Create the internal Data object.
+ data = llvmlab.data.Data.fromdata(data_object)
# Set the admin pseudo-user.
data.set_admin_user(llvmlab.user.User(
More information about the llvm-commits
mailing list