Beispiel #1
0
def test_project_create(func_dir, db_url):
    args = app.create_parser().parse_args(
        ['--db', db_url, 'project', 'create', '-d', func_dir, '-n', 'test'])
    assert args.project_dir == func_dir
    assert args.project_name == 'test'
    assert args.db == db_url

    args.handler(args)
    db.upgrade()
    p = db.session.query(Project).filter_by(path_name=func_dir).first()
    assert p is None
    # on Windows/Python2, another session is create, need to remove
    # this session externally (*)
    db._session.remove()

    args.handler(args)
    p = db.session.query(Project).filter_by(path_name=func_dir).first()
    assert p is not None
    assert p.path_name == func_dir
    assert p.name == 'test'
    db._session.remove()  # same as (*)

    args.handler(args)  # already registered, confirm not occur error
    ps = db.session.query(Project).filter_by(path_name=func_dir).all()
    assert len(ps) == 1
Beispiel #2
0
def test_server_debug(func_init_db):
    args = app.create_parser().parse_args([
        '--db', db.url, '--db-echo', 'server', '-H', 'test.domain', '-p',
        '5001', '-d'
    ])
    assert args.host == 'test.domain'
    assert args.port == 5001
    assert args.debug
    assert args.db == db.url
    assert args.db_echo

    mock_app = MagicMock()
    mock_app_creator = MagicMock(return_value=mock_app)
    with patch('werkzeug.serving.run_simple', MagicMock()) as f, \
            patch('chainerui.app.create_app', mock_app_creator):
        args.handler(args)
        f.assert_not_called()

        db.upgrade()
        args.handler(args)
        f.assert_called_once()
        f.assert_called_with('test.domain',
                             5001,
                             mock_app,
                             use_reloader=True,
                             use_debugger=True,
                             threaded=True)
Beispiel #3
0
def db_handler(args):
    """db_handler."""

    if args.type == 'create':
        if args.db is None:
            db.init_db()
        return

    if not db.setup(url=args.db, echo=args.db_echo):
        return

    if args.type == 'status':
        current_rev = db_revision.current_db_revision()
        print('The current DB schema version:', current_rev)

    if args.type == 'upgrade':
        db.upgrade()

    if args.type == 'revision':
        db_revision.new_revision()

    if args.type == 'drop':
        if args.db is not None:
            db.downgrade()
        db.remove_db()
Beispiel #4
0
def test_check_current_db_revision(func_init_db):
    assert not check_current_db_revision()

    _upgrade()
    assert not check_current_db_revision()

    db.upgrade()
    assert check_current_db_revision()
    def test_check_current_db_revision(self):
        assert not check_current_db_revision()

        self._upgrade()
        assert not check_current_db_revision()

        db.upgrade()
        assert check_current_db_revision()
Beispiel #6
0
def project(func_dir):
    db.setup(test_mode=True)
    db.upgrade()

    project_path = os.path.join(func_dir, 'test_project')
    _setup_test_project(project_path)
    project_name = 'my-project'
    Project.create(project_path, project_name)

    yield (project_path, project_name)

    db.session.remove()
    db.remove_db()
Beispiel #7
0
def test_server_production(db_url):
    args = app.create_parser().parse_args(
        ['--db', db_url, 'server', '-H', 'test.domain', '-p', '5001'])
    assert args.host == 'test.domain'
    assert args.port == 5001
    assert not args.debug
    assert args.db == db_url

    mock_app = MagicMock()
    mock_app_creator = MagicMock(return_value=mock_app)
    mock_server = MagicMock()
    mock_server_init = MagicMock(return_value=mock_server)
    with patch('gevent.pywsgi.WSGIServer', mock_server_init), \
            patch('chainerui.app.create_app', mock_app_creator):
        args.handler(args)
        mock_server.serve_forever.assert_not_called()

        db.upgrade()
        args.handler(args)
        mock_server.serve_forever.assert_called_once()
def result_path(func_dir):
    db.setup(test_mode=True)
    db.upgrade()

    info_path = os.path.join(func_dir, '.chainerui_images')

    with open(os.path.join(func_dir, 'img1_1.png'), 'w') as f:
        f.write('text')
    with open(os.path.join(func_dir, 'img1_2.png'), 'w') as f:
        f.write('text2')
    with open(os.path.join(func_dir, 'img2.png'), 'w') as f:
        f.write('text3')

    test_data = [{
        'iteration':
        1000,
        'epoch':
        1,
        'images':
        OrderedDict([
            ('0', 'img1_1.png'),
            ('1', 'img1_2.png'),
        ])
    }, {
        'iteration': 2000,
        'epoch': 2,
        'custom': 'test',
        'images': OrderedDict([
            ('seg', 'img2.png'),
        ])
    }]
    with open(info_path, 'w') as f:
        json.dump(test_data, f)

    yield (func_dir)

    db.session.remove()
    db.remove_db()
Beispiel #9
0
def func_db(func_init_db):
    db.upgrade()
Beispiel #10
0
def _setup_test_db(project_path, project_name):
    db.upgrade()

    # insert test data
    Project.create(project_path, project_name)