On Thursday, January 16, 2020 at 11:29:21 AM UTC-8, RjOllos wrote:
>
>
>
> On Wednesday, January 15, 2020 at 10:34:32 PM UTC-8, Velu Narasimman wrote:
>>
>> Well, I am getting menu as a dictionary as shown below,
>>
>> {'mainnav': [{'active': False, 'name': 'project', 'label': <Element "a"
>> >}, {'active': False, 'name': 'added_common', 'label': <Element "a">}, {
>> 'active': False, 'name': 'admin', 'label': <Element "a">}, {'active': 
>> False, 'name': 'reports', 'label': <Element "a">}, {'active': False, 
>> 'name': 'metrics', 'label': <Element "a">}, {'active': False, 'name': 
>> 'mytimesheet', 'label': <Element "a">}, {'active': True, 'name': 
>> 'myprojects', 'label': <Element "a">}, {'active': False, 'name': 
>> 'timesheetapproval', 'label': <Element "a">}], 'metanav': [{'active': 
>> False, 'name': 'login', 'label': u'logged in as karthikeyan.nagaraja'}, {
>> 'active': False, 'name': 'logout', 'label': <Element "a">}, {'active': 
>> False, 'name': 'prefs', 'label': <Element "a">}, {'active': False, 'name'
>> : 'about', 'label': <Element "a">}]}
>>
>> I get this, when I refresh the web page in my browser. These menus are 
>> dynamic, differs among different users based on the permissions that they 
>> have in system. But I wish to generate this without using a browser. So how 
>> can I make a web request handling in program itself and the above menus?
>>
>
> Are you calling Chrome.get_navigation_items?
> https://trac.edgewall.org/browser/tags/trac-1.4/trac/web/chrome.py#L862
>
> You'll need to make a MockRequest. For examples, I believe this is done in 
> a few plugins, but I don't recall which off-hand.
>
> I suppose you could use MockRequest from the test module:
> https://trac.edgewall.org/browser/tags/trac-1.4/trac/test.py#L151
>
> - Ryan
>

Or better might be to extract and modify this code to meet your needs:
https://trac.edgewall.org/browser/tags/trac-1.4/trac/web/chrome.py?marks=947-952#L947

With regard to the mock Request object, navigation contributors only check 
permissions like "PERM in req.perm", so your mock could just return True 
for that case.

- Ryan 

-- 
You received this message because you are subscribed to the Google Groups "Trac 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/trac-users/c29954d8-ce06-4de5-bc52-0c5503b6beb7%40googlegroups.com.

Reply via email to