Hi,

I'm trying to write a test to verify that all menu items are working. I 
copied the Example from https://github.com/viniciusban/web2py.test to write 
the first test.
The problem is that most of the menu items are only visible after a login. 
Therefore I tried to login with auth.login_bare but it seems that something 
is still missing.
The login works but after calling the menu.py with execfile I don't get all 
menu items.

Any idea?

*models/menu.py:*
if not auth.is_logged_in():
    response.menu = [
         (T('Support'), False, URL('default', 'support'), [])
         ]
else:
    if auth.has_membership('manager'):
         response.menu += [...


*tests/controllers/test_example.py*
from gluon import * 
def test_menu_links(client, web2py):
    db = web2py.db
    auth = Auth(db)

    password = db.auth_user.password.requires[0]('manager')[0]
    user = auth.get_or_create_user({
        'username': 'manager',
        'password': password
    })
    # create group
    group_id = db.auth_group.insert(**{
         'role': 'manager'
    })

    auth.add_membership(group_id=group_id, user_id=user.id)
    db.commit()

    out = auth.login_bare('manager','manager')
    g=copy(current.globalenv)

    # Returns True
    print auth.is_logged_in()
    # Returns True
    print auth.has_membership('manager')

    execfile('applications/app_under_test/models/menu.py', g)

    links = set()
    for i in current.response.menu:
        topmenu = i
        top_links = topmenu[2]
        links.add(top_links)
        submenu = topmenu[3]
        for subitem in submenu:
            links.add(subitem[2])
    print links
    # returns only menu items without auth

Thanks!!!
Raphael

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to