1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
Answer Tracker Introduction Page
================================
First, we need to set some values for the later tests.
>>> import transaction
>>> from lp.app.enums import ServiceUsage
>>> from lp.registry.interfaces.distribution import IDistributionSet
>>> from lp.registry.interfaces.product import IProductSet
>>> from zope.component import getUtility
>>> login('admin@canonical.com')
>>> firefox = getUtility(IProductSet).getByName('firefox')
>>> ubuntu = getUtility(IDistributionSet).getByName('ubuntu')
>>> firefox.answers_usage = ServiceUsage.LAUNCHPAD
>>> ubuntu.answers_usage = ServiceUsage.LAUNCHPAD
>>> logout()
>>> transaction.commit()
>>> anon_browser.open('http://answers.launchpad.dev/')
>>> print anon_browser.title
Launchpad Answers
It shows the 5 latest questions asked:
>>> latest_questions_asked = find_tag_by_id(
... anon_browser.contents, 'latest-questions-asked')
>>> print latest_questions_asked.first('h2').renderContents()
Latest questions asked
>>> for row in latest_questions_asked.fetch('li'):
... row.first('a').renderContents()
'...: Problemas de Impress\xc3\xa3o no Firefox'
'...: Problema al recompilar kernel con soporte smp (doble-n\xc3\xbacleo)'
'...: Continue playing after shutdown'
'...: Installation failed'
'...: Firefox loses focus and gets stuck'
As well as the 5 latest questions solved:
>>> latest_questions_solved = find_tag_by_id(
... anon_browser.contents, 'latest-questions-solved')
>>> print latest_questions_solved.first('h2').renderContents()
Latest questions solved
>>> for row in latest_questions_solved.fetch('li'):
... row.first('a').renderContents()
'...: mailto: problem in webpage'
The application footer also contains a sample of stats for the application:
# Replace numbers with X in output.
>>> import re
>>> print re.sub('\d+', 'X', extract_text(find_tag_by_id(
... anon_browser.contents, 'application-footer')))
X questions answered and X questions solved out of
X questions asked across X projects
The page also contains the projects actively using the Answer tracker.
(Since sample data contains no projects with a question asked in the
last 60 days, this list is empty):
>>> print extract_text(find_tag_by_id(
... anon_browser.contents, 'most-active-projects'))
Most active projects
Add some recent questions so that this listing contains something.
>>> from lp.answers.testing import QuestionFactory
>>> from lp.testing import login, logout
>>> login('no-priv@canonical.com')
>>> QuestionFactory.createManyByProject([
... ('ubuntu', 2),
... ('firefox', 1)])
>>> logout()
>>> anon_browser.open('http://answers.launchpad.dev/')
>>> print extract_text(find_tag_by_id(
... anon_browser.contents, 'most-active-projects'))
Most active projects
Ubuntu
Mozilla Firefox
Clicking on these project links will bring the user to the project
Answers front page:
>>> anon_browser.getLink('Ubuntu').click()
>>> print anon_browser.url
http://answers.launchpad.dev/ubuntu
>>> print anon_browser.title
Questions : Ubuntu
|