Esempio n. 1
0
def setup_app(config_obj):

    app = Flask(__name__)
    app.config.from_object(config_obj)

    database.init_db(app)

    app.register_blueprint(frontend, url_prefix='')
    app.register_blueprint(ipxe, url_prefix='/ipxe')
    app.register_blueprint(hosts, url_prefix='/api/1.0/hosts')
    app.register_blueprint(groups, url_prefix='/api/1.0/groups')
    app.register_blueprint(templates, url_prefix='/api/1.0/templates')
    app.register_blueprint(power, url_prefix='/api/1.0/power')
    return app
Esempio n. 2
0
    def setUp(self):
        app = Flask(__name__)
        app.config.from_object(settings)
        app.testing = True
        app.config['MONGO_DBNAME'] = 'bergenholmtest'
        database.init_db(app)

        app.register_blueprint(frontend, url_prefix='')
        app.register_blueprint(ipxe, url_prefix='/ipxe')
        app.register_blueprint(hosts, url_prefix='/api/1.0/hosts')
        app.register_blueprint(groups, url_prefix='/api/1.0/groups')
        app.register_blueprint(templates, url_prefix='/api/1.0/templates')
        app.register_blueprint(power, url_prefix='/api/1.0/power')

        self.app = app
        self.client = app.test_client()
        self.mongo = database.mongo

        with self.app.test_request_context('/'):
            self.mongo.db.hosts.remove()
            self.mongo.db.groups.remove()
            self.mongo.db.templates.remove()

            params = {u"_id": self.host_id}
            params.update(self.host_params)
            self.mongo.db.hosts.insert(params)

            self.mongo.db.groups.insert({
                u"_id": u"default",
                u"base_url": u"http://127.0.0.1"})

            params = {u"_id": self.group_id}
            params.update(self.group_params)
            self.mongo.db.groups.insert(params)

            self.mongo.db.templates.insert({
                u"_id": self.template_id,
                u"content": self.template})