Exemplo n.º 1
0
def test_init_template_with_tmpl_name(copy_helper, find_template_dir,
                                      setup_dirs, save_id, localdoc):
    def _find_dir(*args, **kwargs):
        if (args, kwargs) == (('default', 'app'), dict(raise_error=True)):
            # we will copy ``tempaltes/app`` dir
            # and if the template not found in any paths,
            # we will raise error.
            return '/mock/.couchapp/templates/app'
        elif (args, kwargs) == (('default',), dict(tmpl_type='vendor')):
            # we will copy vendor dir
            return None
        elif (args, kwargs) == (tuple(), dict(tmpl_type='vendor')):
            # ``vendor`` not found in the template set
            # consider the case of fallback to ``default``
            return '/opt/couchapp/templates/vendor'
        else:
            raise AssertionError('invalid call {}'.format((args, kwargs)))

    find_template_dir.side_effect = _find_dir

    init_template('/fake', template='default')

    assert copy_helper.called
    assert find_template_dir.called
    assert setup_dirs.called
    assert save_id.called
    assert localdoc.document.called
Exemplo n.º 2
0
def init(conf, *args, **opts):
    if not args:
        dest = os.getcwd()
    else:
        dest = os.path.normpath(os.path.join(os.getcwd(), args[0]))

    if dest is None:
        raise AppError('Unknown dest')

    if opts['empty'] and opts['template']:
        raise AppError('option "empty" cannot use with "template"')

    if util.iscouchapp(dest):
        raise AppError("can't create an app at '{0}'. "
                       "One already exists here.".format(dest))

    if util.findcouchapp(dest):
        raise AppError("can't create an app inside another app '{0}'.".format(
                       util.findcouchapp(dest)))

    # ``couchapp init -e dest``
    if opts['empty']:
        document(dest, create=True)

    # ``couchapp init -t template_name dest``
    elif opts['template']:
        generator.init_template(dest, template=opts['template'])

    # ``couchapp init dest``
    else:
        generator.init_basic(dest)

    logger.info('{0} created.'.format(dest))

    return 0
Exemplo n.º 3
0
def test_init_template_with_tmpl_name(copy_helper, find_template_dir,
                                      setup_dirs, save_id, localdoc):
    def _find_dir(*args, **kwargs):
        if (args, kwargs) == (('default', 'app'), dict(raise_error=True)):
            # we will copy ``tempaltes/app`` dir
            # and if the template not found in any paths,
            # we will raise error.
            return '/mock/.couchapp/templates/app'
        elif (args, kwargs) == (('default', ), dict(tmpl_type='vendor')):
            # we will copy vendor dir
            return None
        elif (args, kwargs) == (tuple(), dict(tmpl_type='vendor')):
            # ``vendor`` not found in the template set
            # consider the case of fallback to ``default``
            return '/opt/couchapp/templates/vendor'
        else:
            raise AssertionError('invalid call {}'.format((args, kwargs)))

    find_template_dir.side_effect = _find_dir

    init_template('/fake', template='default')

    assert copy_helper.called
    assert find_template_dir.called
    assert setup_dirs.called
    assert save_id.called
    assert localdoc.document.called
Exemplo n.º 4
0
def init(conf, *args, **opts):
    if not args:
        dest = os.getcwd()
    else:
        dest = os.path.normpath(os.path.join(os.getcwd(), args[0]))

    if dest is None:
        raise AppError('Unknown dest')

    if opts['empty'] and opts['template']:
        raise AppError('option "empty" cannot use with "template"')

    if util.iscouchapp(dest):
        raise AppError("can't create an app at '{0}'. "
                       "One already exists here.".format(dest))

    if util.findcouchapp(dest):
        raise AppError("can't create an app inside another app '{0}'.".format(
            util.findcouchapp(dest)))

    # ``couchapp init -e dest``
    if opts['empty']:
        document(dest, create=True)

    # ``couchapp init -t template_name dest``
    elif opts['template']:
        generator.init_template(dest, template=opts['template'])

    # ``couchapp init dest``
    else:
        generator.init_basic(dest)

    logger.info('{0} created.'.format(dest))

    return 0
Exemplo n.º 5
0
 def h():
     init_template('/mock', template='vendor')
Exemplo n.º 6
0
 def g():
     init_template('/mock', template='functions')
Exemplo n.º 7
0
 def f():
     init_template('/mock', template='app')
Exemplo n.º 8
0
 def h():
     init_template('/mock', template='vendor')
Exemplo n.º 9
0
 def g():
     init_template('/mock', template='functions')
Exemplo n.º 10
0
 def f():
     init_template('/mock', template='app')