~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/answers/stories/webservice.txt

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-05-09 22:53:33 UTC
  • mfrom: (12959.4.23 anwers-api-0)
  • Revision ID: launchpad@pqm.canonical.com-20110509225333-lu5q3l2zce8erpbx
[r=benji][bug=780078] Export answer contact management over the API.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
Working with Launchpad Answers over the API
 
2
===========================================
 
3
 
 
4
Users can work with question targets and questions over the api to
 
5
search and update questions. This demonstration will use a project, it's
 
6
contact, and asker, and three questions.
 
7
 
 
8
    >>> from zope.component import getUtility
 
9
    >>> from canonical.launchpad.testing.pages import webservice_for_person
 
10
    >>> from canonical.launchpad.webapp.interfaces import OAuthPermission
 
11
    >>> from lp.app.enums import ServiceUsage
 
12
    >>> from lp.services.worlddata.interfaces.language import ILanguageSet
 
13
    >>> from lp.testing.sampledata import ADMIN_EMAIL
 
14
    >>> lang_set = getUtility(ILanguageSet)
 
15
 
 
16
    >>> login(ADMIN_EMAIL)
 
17
    >>> _contact = factory.makePerson(name='contact')
 
18
    >>> _project = factory.makeProduct(name='my-project', owner=_contact)
 
19
    >>> _contact.addLanguage(lang_set['en'])
 
20
    >>> _project.answers_usage = ServiceUsage.LAUNCHPAD
 
21
    >>> success = _project.addAnswerContact(_contact, _contact)
 
22
    >>> _team = factory.makeTeam(owner=_contact, name='my-team')
 
23
    >>> _team_project = factory.makeProduct(name='team-project', owner=_team)
 
24
    >>> _asker = factory.makePerson(name='asker')
 
25
    >>> _question_1 = factory.makeQuestion(
 
26
    ...     target=_project, title="Q 1", owner=_asker)
 
27
    >>> _question_2 = factory.makeQuestion(
 
28
    ...     target=_project, title="Q 2", owner=_asker)
 
29
    >>> _question_3 = factory.makeQuestion(
 
30
    ...     target=_team_project, title="Q 3", owner=_asker)
 
31
    >>> logout()
 
32
 
 
33
    >>> contact_webservice = webservice_for_person(
 
34
    ...     _contact, permission=OAuthPermission.WRITE_PUBLIC)
 
35
 
 
36
 
 
37
Answer contacts
 
38
---------------
 
39
 
 
40
Users can add or remove themselves as an answer contact for a project. The
 
41
user must have a preferred language. Scripts should call the
 
42
canUserAlterAnswerContact method first to verify that the person can
 
43
be added.
 
44
 
 
45
    >>> project = contact_webservice.get(
 
46
    ...     '/my-project', api_version='devel').jsonBody()
 
47
    >>> contact = contact_webservice.get(
 
48
    ...     '/~contact', api_version='devel').jsonBody()
 
49
    >>> contact_webservice.named_get(
 
50
    ...     project['self_link'], 'canUserAlterAnswerContact',
 
51
    ...     person=contact['self_link'], api_version='devel').jsonBody()
 
52
    True
 
53
 
 
54
    >>> contact_webservice.named_post(
 
55
    ...     project['self_link'], 'removeAnswerContact',
 
56
    ...     person=contact['self_link'], api_version='devel').jsonBody()
 
57
    True
 
58
 
 
59
    >>> contact_webservice.named_post(
 
60
    ...     project['self_link'], 'addAnswerContact',
 
61
    ...     person=contact['self_link'], api_version='devel').jsonBody()
 
62
    True
 
63
 
 
64
User can also make the teams they administer answer contacts if the team has a
 
65
preferred language.
 
66
 
 
67
    >>> team = contact_webservice.get(
 
68
    ...     '/~my-team', api_version='devel').jsonBody()
 
69
    >>> contact_webservice.named_get(
 
70
    ...     project['self_link'], 'canUserAlterAnswerContact',
 
71
    ...     person=team['self_link'], api_version='devel').jsonBody()
 
72
    True
 
73
 
 
74
    >>> contact_webservice.named_post(
 
75
    ...     team['self_link'], 'addLanguage',
 
76
    ...     language='/+languages/fr', api_version='devel').jsonBody()
 
77
    >>> contact_webservice.named_post(
 
78
    ...     project['self_link'], 'addAnswerContact',
 
79
    ...     person=team['self_link'], api_version='devel').jsonBody()
 
80
    True
 
81
 
 
82
 
 
83
Anyone can get the collection of languages spoken by at least one
 
84
answer contact.
 
85
 
 
86
    >>> languages = anon_webservice.named_get(
 
87
    ...     project['self_link'], 'getSupportedLanguages',
 
88
    ...     api_version='devel').jsonBody()
 
89
    >>> print_self_link_of_entries(languages)
 
90
    http://.../+languages/en
 
91
    http://.../+languages/fr
 
92
 
 
93
    >>> english = languages['entries'][0]
 
94
 
 
95
Anyone can retrieve the collection of answer contacts for a language.
 
96
 
 
97
    >>> contacts = anon_webservice.named_get(
 
98
    ...     project['self_link'], 'getAnswerContactsForLanguage',
 
99
    ...     language=english['self_link'], api_version='devel').jsonBody()
 
100
    >>> print_self_link_of_entries(contacts)
 
101
    http://.../~contact
 
102
 
 
103
 
 
104
Questions
 
105
---------
 
106
 
 
107
Anyone can retrieve a question from a `IQuestionTarget`.
 
108
 
 
109
    >>> question_1 = anon_webservice.named_get(
 
110
    ...     project['self_link'], 'getQuestion', question_id=_question_1.id,
 
111
    ...     api_version='devel').jsonBody()
 
112
    >>> print question_1['title']
 
113
    Q 1