Implement flexible configurations
This commit is contained in:
parent
11e6c4a7aa
commit
bf1b8cee09
1
.gitignore
vendored
1
.gitignore
vendored
@ -7,6 +7,7 @@ __pycache__
|
|||||||
refs
|
refs
|
||||||
bower_components
|
bower_components
|
||||||
eosjs.js
|
eosjs.js
|
||||||
|
local_settings.py
|
||||||
|
|
||||||
\#*
|
\#*
|
||||||
.#*
|
.#*
|
||||||
|
@ -23,7 +23,8 @@ from eos.core.objects import *
|
|||||||
class ElectionTestCase(EosTestCase):
|
class ElectionTestCase(EosTestCase):
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpClass(cls):
|
def setUpClass(cls):
|
||||||
client.drop_database('test')
|
db_connect('test')
|
||||||
|
dbinfo.client.drop_database('test')
|
||||||
|
|
||||||
def do_task_assert(self, election, task, next_task):
|
def do_task_assert(self, election, task, next_task):
|
||||||
self.assertEqual(election.workflow.get_task(task).status, WorkflowTask.Status.READY)
|
self.assertEqual(election.workflow.get_task(task).status, WorkflowTask.Status.READY)
|
||||||
@ -65,8 +66,8 @@ class ElectionTestCase(EosTestCase):
|
|||||||
election.save()
|
election.save()
|
||||||
|
|
||||||
# Check that it saved
|
# Check that it saved
|
||||||
self.assertEqual(db[Election._db_name].find_one()['value'], election.serialise())
|
self.assertEqual(dbinfo.db[Election._db_name].find_one()['value'], election.serialise())
|
||||||
self.assertEqual(EosObject.deserialise_and_unwrap(db[Election._db_name].find_one()).serialise(), election.serialise())
|
self.assertEqual(EosObject.deserialise_and_unwrap(dbinfo.db[Election._db_name].find_one()).serialise(), election.serialise())
|
||||||
|
|
||||||
self.assertEqualJSON(EosObject.deserialise_and_unwrap(EosObject.serialise_and_wrap(election)).serialise(), election.serialise())
|
self.assertEqualJSON(EosObject.deserialise_and_unwrap(EosObject.serialise_and_wrap(election)).serialise(), election.serialise())
|
||||||
|
|
||||||
|
@ -49,9 +49,16 @@ else:
|
|||||||
# Database
|
# Database
|
||||||
# ========
|
# ========
|
||||||
|
|
||||||
if is_python:
|
class DBInfo:
|
||||||
client = pymongo.MongoClient()
|
def __init__(self):
|
||||||
db = client['test']
|
self.client = None
|
||||||
|
self.db = None
|
||||||
|
|
||||||
|
dbinfo = DBInfo()
|
||||||
|
|
||||||
|
def db_connect(db_name, mongo_uri='mongodb://localhost:27017/'):
|
||||||
|
dbinfo.client = pymongo.MongoClient(mongo_uri)
|
||||||
|
dbinfo.db = dbinfo.client[db_name]
|
||||||
|
|
||||||
# Fields
|
# Fields
|
||||||
# ======
|
# ======
|
||||||
@ -369,15 +376,15 @@ class DocumentObject(EosObject, metaclass=DocumentObjectType):
|
|||||||
class TopLevelObject(DocumentObject):
|
class TopLevelObject(DocumentObject):
|
||||||
def save(self):
|
def save(self):
|
||||||
#res = db[self._name].replace_one({'_id': self.serialise()['_id']}, self.serialise(), upsert=True)
|
#res = db[self._name].replace_one({'_id': self.serialise()['_id']}, self.serialise(), upsert=True)
|
||||||
res = db[self._db_name].replace_one({'_id': self._fields['_id'].serialise(self._id)}, EosObject.serialise_and_wrap(self), upsert=True)
|
res = dbinfo.db[self._db_name].replace_one({'_id': self._fields['_id'].serialise(self._id)}, EosObject.serialise_and_wrap(self), upsert=True)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_all(cls):
|
def get_all(cls):
|
||||||
return [EosObject.deserialise_and_unwrap(x) for x in db[cls._db_name].find()]
|
return [EosObject.deserialise_and_unwrap(x) for x in dbinfo.db[cls._db_name].find()]
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_by_id(cls, _id):
|
def get_by_id(cls, _id):
|
||||||
return EosObject.deserialise_and_unwrap(db[cls._db_name].find_one(_id))
|
return EosObject.deserialise_and_unwrap(dbinfo.db[cls._db_name].find_one(_id))
|
||||||
|
|
||||||
class EmbeddedObject(DocumentObject):
|
class EmbeddedObject(DocumentObject):
|
||||||
pass
|
pass
|
||||||
|
@ -212,7 +212,8 @@ class MixnetTestCase(EosTestCase):
|
|||||||
class ElectionTestCase(EosTestCase):
|
class ElectionTestCase(EosTestCase):
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpClass(cls):
|
def setUpClass(cls):
|
||||||
client.drop_database('test')
|
db_connect('test')
|
||||||
|
dbinfo.client.drop_database('test')
|
||||||
|
|
||||||
def do_task_assert(self, election, task, next_task):
|
def do_task_assert(self, election, task, next_task):
|
||||||
self.assertEqual(election.workflow.get_task(task).status, WorkflowTask.Status.READY)
|
self.assertEqual(election.workflow.get_task(task).status, WorkflowTask.Status.READY)
|
||||||
|
@ -30,10 +30,26 @@ import eosweb
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
import functools
|
import functools
|
||||||
|
import importlib
|
||||||
import json
|
import json
|
||||||
|
import os
|
||||||
|
|
||||||
app = flask.Flask(__name__)
|
app = flask.Flask(__name__)
|
||||||
|
|
||||||
|
# Load config
|
||||||
|
app.config.from_object('eosweb.core.settings')
|
||||||
|
if 'EOSWEB_SETTINGS' in os.environ:
|
||||||
|
app.config.from_envvar('EOSWEB_SETTINGS')
|
||||||
|
|
||||||
|
# Load app config
|
||||||
|
for app_name in app.config['APPS']:
|
||||||
|
app.config.from_object(app_name + '.settings')
|
||||||
|
if 'EOSWEB_SETTINGS' in os.environ:
|
||||||
|
app.config.from_envvar('EOSWEB_SETTINGS')
|
||||||
|
|
||||||
|
# Connect to database
|
||||||
|
db_connect(app.config['DB_NAME'], app.config['MONGO_URI'])
|
||||||
|
|
||||||
@app.cli.command('test')
|
@app.cli.command('test')
|
||||||
@click.option('--prefix', default=None)
|
@click.option('--prefix', default=None)
|
||||||
@click.option('--lang', default=None)
|
@click.option('--lang', default=None)
|
||||||
@ -45,7 +61,7 @@ def run_tests(prefix, lang):
|
|||||||
@app.cli.command('drop_db_and_setup')
|
@app.cli.command('drop_db_and_setup')
|
||||||
def setup_test_election():
|
def setup_test_election():
|
||||||
# DANGER!
|
# DANGER!
|
||||||
client.drop_database('test')
|
dbinfo.client.drop_database(app.config['DB_NAME'])
|
||||||
|
|
||||||
# Set up election
|
# Set up election
|
||||||
election = PSRElection()
|
election = PSRElection()
|
||||||
|
28
eosweb/core/settings.py
Normal file
28
eosweb/core/settings.py
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
# Eos - Verifiable elections
|
||||||
|
# Copyright © 2017 RunasSudo (Yingtong Li)
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU Affero General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU Affero General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
BASE_URI = 'http://localhost:5000'
|
||||||
|
|
||||||
|
MONGO_URI = 'mongodb://localhost:27017/'
|
||||||
|
DB_NAME = 'eos'
|
||||||
|
|
||||||
|
APPS = [
|
||||||
|
'eosweb.redditauth'
|
||||||
|
]
|
||||||
|
|
||||||
|
AUTH_METHODS = []
|
||||||
|
|
||||||
|
SECRET_KEY = 'FIXME'
|
Loading…
Reference in New Issue
Block a user