예제 #1
0
def test_rendering_confirm_creation(env):
    logger.info('env: %s' % env)
    template = get_template('confirm_creation.jinja2')
    res = {
        'static': '',
    }
    check_render(env, template, res)
예제 #2
0
def test_rendering_jinja_env(env):
    logger.info('env: %s' % env)
    template = get_template('editor_fancy/error_model_exists_generic.jinja2')
    res = {
        'static': '',
        'url_edit': '',
        'library_name': '',
        'widget_name': '',
    }
    check_render(env, template, res)
예제 #3
0
def test_rendering_confirm_bind(env):
    logger.info('env: %s' % env)
    template = get_template('confirm_bind.jinja2')
    app = WebApp.singleton  # XXX
    db_view = app.hi.db_view
    uname = USER1
    user = db_view.user_db.users[uname]
    res = {
        'authenticated_userid': 'paul',
        'static': '',
        'root': '',
        'user_struct': user,
        'candidate_user': user,
        'user_db': db_view.user_db,
    }
    check_render(env, template, res)
예제 #4
0
파일: split_test.py 프로젝트: rusi/mcdp
def document_split():
    html = get_split_test_document()
    soup = BeautifulSoup(html, 'lxml')
    for e in soup.select('.toc'):
        e.extract()
    html = soup.prettify()
    fn = 'out/document_split.html'
    with open(fn, 'w') as f:
        f.write(html)
    logger.info('written on %s' % fn)
     
    
    filename2contents = split_in_files(soup)
    add_prev_next_links(filename2contents)
    update_refs(filename2contents)
        
    d = 'out/sec'
    write_split_files(filename2contents, d)
예제 #5
0
파일: split_test.py 프로젝트: kannode/mcdp
def document_split():
    html = get_split_test_document(test_md)
    soup = BeautifulSoup(html, 'lxml')
    for e in soup.select('.toc'):
        e.extract()
    html = soup.prettify()
    fn = 'out/document_split.html'
    with open(fn, 'w') as f:
        f.write(html)
    logger.info('written on %s' % fn)

    filename2contents = split_in_files(soup)
    id2filename = get_id2filename(filename2contents)
    add_prev_next_links(filename2contents)
    update_refs(filename2contents, id2filename)

    linkbase = 'link.html'
    filename2contents[linkbase] = create_link_base(id2filename)
예제 #6
0
    def f2():
        d = dir_from_package_name('mcdp_web_tests')
        ini = os.path.join(d, 'test1.ini')
        with bootstrap(ini) as env:
            app = WebApp.singleton
            db_view0 = app.hi.db_view
            # create a copy of the DB
            db_data0 = db_view0._data
            db_view1 = DB.view_manager.create_view_instance(DB.db, db_data0)
            db_view1.set_root()
            logger.info('creating copies of the repositories')
            for r in db_view0.repos:
                db_view1.repos[r] = db_view0.repos[r]
            logger.info('creating copies of the repositories [done]')

            app.hi.db_view = db_view1
            db0 = testdb1()
            db_view1.user_db.users['anonymous'] = db_view0.user_db.users[
                'anonymous']
            db_view1.user_db.users[USER1] = db0['user_db']['users']['andrea']
            f(env)
예제 #7
0
def test_lib_creation1(env):
    logger.info('env: %s' % env)
    app = WebApp.singleton # XXX
    db_view = app.hi.db_view
    
    authenticated_userid = 'andrea'
    repo_name = 'bundled'
    shelf_name = 'examples'
    library_name = 'newlibname2'
    # check that it doesn't exist
    assert repo_name in db_view.repos
    repo = db_view.repos[repo_name]
    assert shelf_name in repo.shelves
    shelf = repo.shelves[shelf_name]
    if library_name in shelf.libraries:
        msg = 'The library %r already exists' % library_name
        raise Exception(msg)
    
    url = '/repos/%s/shelves/%s/libraries/:new/%s' % (repo_name, shelf_name, library_name)
    
    mocked = get_context_request(test_env=env, url=url, authenticated_userid=authenticated_userid)
    
    context = mocked.context
    request = mocked.request
    check_isinstance(context, ResourceLibrariesNewLibname)
    assert_equal(context.name, library_name)
    # create library
    view = app.view_shelf_library_new 
    try:
        view(context=context, request=request)
    except HTTPFound as e:
        headers=dict(e._headerlist)
        location = headers['Location']
        logger.debug('redirect to: %r' % location)

    else:
        msg = 'Expected HTTPFound raised'
        raise Exception(msg)
    # now the library should exist
    assert library_name in shelf.libraries
예제 #8
0
파일: shelves.py 프로젝트: rusi/mcdp
def shelves02():
    shelves_schema = DB.shelves
    shelves_data = setup_permissions_data
    shelves_schema.validate(shelves_data)
    shelves = DB.view_manager.create_view_instance(shelves_schema, shelves_data)
    shelves.set_root()
    andrea_subscription = shelves['u_andrea_subscription']
    _andrea_private = shelves['u_andrea_private']
    _andrea_public = shelves['u_andrea_public']
    assert len(shelves) == 3, shelves    
    
    print(andrea_subscription)
    acl =  andrea_subscription.get_acl()
    logger.info(acl)
    assert acl.allowed('discover', 'john', groups=[])
    assert  not acl.allowed('read', 'john', groups=[])
    assert acl.allowed('read', 'john', groups=['subscribers:andrea'])
    
    assert_equal(andrea_subscription.get_desc_short(),  "Andrea's subscribers")
    assert_equal(andrea_subscription.get_desc_long(), 'long desc')
    assert_equal(andrea_subscription.get_authors(), ['user:andrea'])
    assert_equal(andrea_subscription.get_dependencies(), ['u_andrea_public'])
예제 #9
0
def test_toc_numbers1():
    s = r"""
    
<div id='toc'></div>

# Part One {#part:one}

# Chapter One

## Sub One_point_One

Referring to [](#fig:One) and [](#fig:Two) and [](#tab:One).

Also referring only with numbers: 
<a href="#fig:One" class='only_number'></a>,
<a href="#fig:Two" class='only_number'></a>,
<a href="#tab:One" class='only_number'></a>.

<s figure-id="fig:One">Figure One</s>

### Sub sub One_point_One_point_One
#### Par a
#### Par b


## Sub One_point_Two

Referring to subfigures [](#subfig:child1) and [](#subfig:child2).
  
<div figure-id="fig:parent">
    <div figure-id="subfig:child1" figure-caption="child1">
    child1
    </div>
    <div figure-id="subfig:child2" figure-caption="child2">
    child2
    </div>
</div>


<div figure-id="code:code1">
    <pre><code>code1</code></pre>
</div>

## Sub with `code` in the <k>name</k>

# Chapter Two 

<s figure-id="fig:Two">Figure Two</s>

<s figure-id="tab:One">Table One</s>

## Sub Two_point_One

# Part Two {#part:two}

# Chapter Three

\begin{definition}[DefinitionA]\label{def:A}Definition A\end{definition}
\begin{defn}[DefinitionA2]\label{def:A2}Definition A2\end{defn}

\begin{proposition}[PropositionB]\label{prop:B}Proposition B\end{proposition}

\begin{problem}[ProblemC]\label{prob:C}Problem C\end{problem}

\begin{example}[exampleD]\label{exa:D}...\end{example}
\begin{remark}[remarkE]\label{rem:E}...\end{remark}
\begin{lemma}[lammaF]\label{lem:F}...\end{lemma}
\begin{theorem}[theoremG]\label{thm:G}...\end{theorem}
\begin{thm}[theoremG2]\label{thm:G2}...\end{thm}

Citing: 
[](#def:A),
[](#prop:B),
[](#prob:C),
[](#exa:D),
[](#rem:E),
[](#lem:F),
[](#thm:G).

Citing full name:
<a href="#def:A" class="number_name"></a>,
<a href="#prop:B" class="number_name"></a>,
<a href="#prob:C" class="number_name"></a>,
<a href="#exa:D" class="number_name"></a>,
<a href="#rem:E" class="number_name"></a>,
<a href="#lem:F" class="number_name"></a>,
<a href="#thm:G" class="number_name"></a>.

Citing only name:
<a href="#def:A" class="only_name"></a>,
<a href="#prop:B" class="only_name"></a>,
<a href="#prob:C" class="only_name"></a>,
<a href="#exa:D" class="only_name"></a>,
<a href="#rem:E" class="only_name"></a>,
<a href="#lem:F" class="only_name"></a>,
<a href="#thm:G" class="only_name"></a>.


Citing only number:
<a href="#def:A" class="only_number"></a>,
<a href="#prop:B" class="only_number"></a>,
<a href="#prob:C" class="only_number"></a>,
<a href="#exa:D" class="only_number"></a>,
<a href="#rem:E" class="only_number"></a>,
<a href="#lem:F" class="only_number"></a>,
<a href="#thm:G" class="only_number"></a>.


# Appendices {#part:appendices}

# Appendix A {#app:A}
# Appendix B {#app:B}
## App sub B_point_One 
### App subsub B_point_One_point_One

    """
    library = MCDPLibrary()
    raise_errors = True
    realpath = __name__
    s = render_complete(library, s, raise_errors, realpath)

    template = """<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        </head><body></body></html>
        """
    files_contents = [(('a', 'b'), s)]
    stylesheet = 'v_manual_blurb_ready'
    res = manual_join(template=template,
                      files_contents=files_contents,
                      bibfile=None,
                      stylesheet=stylesheet)

    fn = 'out/comptests/test_toc_numbers1.html'  # XXX: write on test folder
    logger.info('written on %s' % fn)
    with open(fn, 'w') as f:
        f.write(res)
예제 #10
0
파일: test_acl.py 프로젝트: rusi/mcdp
def test_privilege1():
    # define schema
    db_schema = Schema()
    schema_user = Schema()
    schema_user.string('name')
    schema_user.string('email', can_be_none=True)
    schema_user.list('groups', SchemaString())
    db_schema.hash('users', schema_user)

    ALLOW = MCDPConstants.ALLOW
    READ = MCDPConstants.Privileges.READ
    WRITE = MCDPConstants.Privileges.WRITE
    # give access control
    admin_can_read = ACLRule(ALLOW, 'group:admin', READ)
    admin_can_modify = ACLRule(ALLOW, 'group:admin', WRITE)
    all_can_read = ACLRule(ALLOW, MCDPConstants.EVERYONE, READ)
    #authenticated_can_read = ACLRule(ALLOW, MCDPConstants.AUTHENTICATED, READ)
    self_can_modify = ACLRule(ALLOW, 'special:user:${path[-2]}', WRITE)
    self_can_read = ACLRule(ALLOW, 'special:user:${path[-2]}', READ)

    # admin can read and modify everything
    db_schema.add_acl_rules([admin_can_modify, admin_can_read])
    # all can read the name
    schema_user['name'].add_acl_rules([all_can_read])
    # only the user itself can read the email
    # schema_user['email'].add_acl_rules([authenticated_can_read])
    # only the user and admins can modify his entry
    schema_user.add_acl_rules(
        [admin_can_modify, admin_can_read, self_can_modify, self_can_read])

    #print db_schema
    db0 = {
        'users': {
            'andrea': {
                'name': 'Andrea',
                'email': '*****@*****.**',
                'groups': ['group:admin', 'group:FDM'],
            },
            'pinco': {
                'name': 'Pinco Pallo',
                'email': None,
                'groups': ['group:FDM'],
            },
        }
    }
    EVERYONE = MCDPConstants.EVERYONE
    AUTHENTICATED = MCDPConstants.AUTHENTICATED
    view_manager = ViewManager(db_schema)
    view_andrea = view_manager.view(db0, 'user:andrea',
                                    ['user:andrea', AUTHENTICATED, EVERYONE])
    view_pinco = view_manager.view(db0, 'user:pinco',
                                   ['user:pinco', AUTHENTICATED, EVERYONE])
    view_admin = view_manager.view(
        db0, 'user:admin1',
        ['user:admin1', 'group:admin', AUTHENTICATED, EVERYONE])

    # andrea is able to read his email
    logger.info('andrea can see ' +
                view_andrea.child('users').child('andrea').email)
    user = view_pinco.child('users').child('andrea')
    # pinco can read andrea's name
    user.name
    # pinco cannot read andrea's email
    email = user.child('email')

    assert not email._schema.get_acl().allowed_('read', [
        'user:pinco',
    ])
    with expect_permissions_error():
        print(user._principals)
        logger.debug(user)
        andrea_s_email = user.email
        logger.debug(andrea_s_email)
        logger.info('! pinco can see ' + andrea_s_email)
    # pinco cannot change andrea's name
    with expect_permissions_error():
        view_pinco.child('users').child('andrea').name = 'invalid'
    # admin can change andrea's name
    view_admin.child('users').child('andrea').name = 'xxx'
    # andrea can change andrea's name
    view_andrea.child('users').child('andrea').name = 'xxx'
예제 #11
0
파일: test_solver2.py 프로젝트: rusi/mcdp
def test_lib_creation1(env):
    logger.info('env: %s' % env)
    app = WebApp.singleton  # XXX

    authenticated_userid = USER1
    repo_name = 'bundled'
    shelf_name = 'uav_energetics'
    library_name = 'droneA_v1'
    model_name = 'Actuation'
    # check that it doesn't exist

    url = ('/repos/%s/shelves/%s/libraries/%s/models/%s/views/solver2/' %
           (repo_name, shelf_name, library_name, model_name))

    mocked = get_context_request(test_env=env,
                                 url=url,
                                 authenticated_userid=authenticated_userid)

    context = mocked.context
    request = mocked.request
    check_isinstance(context, ResourceThingViewSolver)

    # create library
    view = app.view_solver2_base
    try:
        view(context=context, request=request)
    except HTTPFound as e:
        headers = dict(e._headerlist)
        location = headers['Location']
        logger.debug('original url: %s' % request.url)
        logger.debug('redirect to: %r' % location)

    url2 = url + 'submit'
    ui_state = {}
    checkboxes = [
        'ftor_checkbox', 'rtof_checkbox', 'solveforx_checkbox',
        'frtoi_checkbox', 'existsi_checkbox', 'itofr_checkbox'
    ]
    ui_state['area_F'] = '2.0 N'
    ui_state['area_R'] = ''
    for c in checkboxes:
        ui_state[c] = False
    ui_state['ftor_checkbox'] = True
    ui_state['do_approximations'] = False

    ui_state['nu'] = 10
    ui_state['nl'] = 11

    json_body = {'ui_state': ui_state}

    mocked2 = get_context_request(test_env=env,
                                  url=url2,
                                  authenticated_userid=authenticated_userid,
                                  referrer=url,
                                  json_body=json_body)
    view = app.view_solver2_submit

    res = view(context=mocked2.context, request=mocked2.request)

    #print res
    if app.exceptions:
        msg = 'Found these exceptions:'
        msg += '\n'.join(app.exceptions)
        raise Exception(msg)

    assert isinstance(res, dict)
    assert 'ok' in res
    assert res['ok']
    assert '12 W' in res['output_result']

    # now do the other way

    ui_state['ftor_checkbox'] = False  # disable old
    ui_state['rtof_checkbox'] = True
    ui_state['area_R'] = '12 W'

    res2 = view(context=mocked2.context, request=mocked2.request)
    print res2
    if app.exceptions:
        msg = 'Found these exceptions:'
        msg += '\n'.join(app.exceptions)
        raise Exception(msg)

    assert isinstance(res2, dict)
    assert 'ok' in res2
    assert res2['ok']
    assert '2 N' in res2['output_result']