示例#1
0
def create_app(config_file):
    app = Flask("muffin")
    app.config.from_pyfile(config_file)

    if app.debug:
        app.logger.setLevel(logging.DEBUG)

    # set up wanted middleware
    if app.config.get('PROFILE', False):  # pragma: no cover
        # no-cover we don't want to verify profile configs
        app.wsgi_app = ProfilerMiddleware(app.wsgi_app, restrictions=[10])

    def before_request():
        g.muffin_start_request = time.clock()

    def after_request(response):
        end = time.clock()
        response.headers['X-ElapsedTime'] = end - g.muffin_start_request
        return response

    app.before_request(before_request)
    app.after_request(after_request)

    # init backend
    backend.init_app(app)

    # install error handlers
    app.register_blueprint(muffin_error.muffin_error)

    # register api blueprints
    register_api(app, url_prefix="/api/v2")

    return app
示例#2
0
def test_set_alchemy_uri(app):
    if 'SQLALCHEMY_DATABASE_URI' in app.config:
        del app.config['SQLALCHEMY_DATABASE_URI']

    app.config['SQLALCHEMY_DATABASE_URI'] = 'ThisWillNotChange'
    backend.init_app(app)
    assert app.config['SQLALCHEMY_DATABASE_URI'] == 'ThisWillNotChange'
示例#3
0
def test_empty_shard_config(app):
    if 'SQLALCHEMY_DATABASE_URI' in app.config:
        del app.config['SQLALCHEMY_DATABASE_URI']

    app.config['DATABASES'] = {}

    with pytest.raises(backend.BackendException):
        backend.init_app(app)
示例#4
0
def test_empty_config(app):
    if 'SQLALCHEMY_DATABASE_URI' in app.config:
        del app.config['SQLALCHEMY_DATABASE_URI']

    backend.init_app(app)

    assert 'SQLALCHEMY_DATABASE_URI' in app.config

    db_uri = app.config['SQLALCHEMY_DATABASE_URI']
    assert db_uri.startswith('sqlite')
示例#5
0
    def run(self):  # pylint: disable=E0202
        app = flask.current_app
        random.seed(123)

        print("seeding database...")
        start = time.clock()
        backend.init_app(app)
        backend.init_tables(drop_tables=True)

        # backend.insert_projects()

        print("done, elapsed time: {}s".format((time.clock() - start)))
示例#6
0
def test_single_shard(app):
    if 'SQLALCHEMY_DATABASE_URI' in app.config:
        del app.config['SQLALCHEMY_DATABASE_URI']

    d = app.config['DATABASES'] = {}
    ds = d['default'] = {}
    ds['db'] = 'testmuffin'
    backend.init_app(app)

    assert 'SQLALCHEMY_DATABASE_URI' in app.config

    db_uri = app.config['SQLALCHEMY_DATABASE_URI']
    assert db_uri.startswith('sqlite')
    assert db_uri.endswith('testmuffin.db')
示例#7
0
def test_multiple_shard(app):
    if 'SQLALCHEMY_DATABASE_URI' in app.config:
        del app.config['SQLALCHEMY_DATABASE_URI']

    if 'SQLALCHEMY_BINDS' in app.config:
        del app.config['SQLALCHEMY_BINDS']

    d = app.config['DATABASES'] = {}
    ds = d['default'] = {}
    ds['db'] = 'testmuffin'

    ss = d['second'] = {'type': 'testing'}
    ss['db'] = 'secondshard'

    backend.init_app(app)

    binds = app.config['SQLALCHEMY_BINDS']

    assert 'second' in binds
    ss_uri = binds['second']
    assert ss_uri.startswith('testing')
    assert ss_uri.endswith('secondshard')
示例#8
0
def create_app(config_file):
    app = Flask("muffin")
    app.config.from_pyfile(config_file)

    if app.debug:
        app.logger.setLevel(logging.DEBUG)

    # set up wanted middleware
    if app.config.get('PROFILE', False):  # pragma: no cover
        # no-cover we don't want to verify profile configs
        app.wsgi_app = ProfilerMiddleware(app.wsgi_app, restrictions=[10])

    # init backend
    backend.init_app(app)

    # install error handlers
    app.register_blueprint(muffin_error.muffin_error)

    # register api blueprints
    register_api(app, url_prefix="/api/v2")

    return app
示例#9
0
def test_backend(app):  # pylint:disable=W0621
    be.init_app(app)
    be.init_tables(drop_tables=True)
    return be
示例#10
0
文件: seed.py 项目: Kryndex/muffin
    def run(self):  # pylint: disable=E0202
        app = flask.current_app
        random.seed(123)

        print("seeding database...")
        start = time.clock()
        backend.init_app(app)
        backend.init_tables(drop_tables=True)

        # backend.insert_projects()

        backend.insert_testsuites([{
            "name": "TestSuite Name",
            "description": "A cool description",
            "metadata": "{}"
        }, {
            "name":
            "Another testsuite",
            "description":
            "A boring description",
            "metadata":
            str(json.dumps({"platform": "windows"}))
        }])

        backend.insert_runs([
            # a completed succesful run
            (
                {
                    "id": 1,
                    "testsuite_id": 1,
                    "createdAt": datetime.datetime.now(),
                    "metadata": str(json.dumps({"build_version_id": "1337"}))
                },
                {
                    "testsuite_run_id": 1,
                    "startedAt": datetime.datetime.now(),
                },
                {
                    "testsuite_run_id": 1,
                    "endedAt": datetime.datetime.now(),
                    "result": 0  # succesful
                }),
            # a failed finished run
            (
                {
                    "id": 2,
                    "testsuite_id": 1,
                    "createdAt": datetime.datetime.now(),
                    "metadata": str(json.dumps({"build_version_id": "1338"}))
                },
                {
                    "testsuite_run_id": 2,
                    "startedAt": datetime.datetime.now(),
                },
                {
                    "testsuite_run_id": 2,
                    "endedAt": datetime.datetime.now(),
                    "result": 1  # failed
                }),
            # running run
            ({
                "id": 3,
                "testsuite_id": 1,
                "createdAt": datetime.datetime.now(),
                "metadata": str(json.dumps({"build_version_id": "1338"}))
            }, {
                "testsuite_run_id": 3,
                "startedAt": datetime.datetime.now(),
            }, None),
            # run that has yet to start
            ({
                "id": 4,
                "testsuite_id": 1,
                "createdAt": datetime.datetime.now(),
                "metadata": str(json.dumps({"build_version_id": "1338"}))
            }, None, None)
        ])

        backend.insert_tags([{
            "tag_id": 1,
            "name": "Mantle",
            "metadata": "{}"
        }], [{
            "tag_id": 1,
            "suite_id": 1
        }])

        # for i in range(0,4):
        #    # the first 4 runs are all for the same test suite
        #    backend.insert_tests(
        #        [
        #
        #        ])

        print("done, elapsed time: {}s".format((time.clock() - start)))