~thekorn/launchpadlib/fix-342709-ensure-representation

« back to all changes in this revision

Viewing changes to launchpadlib/docs/modifications.txt

  • Committer: Launchpad Patch Queue Manager
  • Date: 2008-12-08 22:15:52 UTC
  • mfrom: (26.2.5 entry-etag)
  • Revision ID: launchpad@pqm.canonical.com-20081208221552-kehijep15qkn9zv9
[r=barry] [bug=304670] Make launchpadlib take advantage of
        'http_etag' information embedded in entry representations. Also
        make launchpadlib JSON-encode all outgoing strings that will be
        used as named operation arguments.

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
    >>> launchpad = salgado_with_full_permissions.login()
8
8
 
9
9
    >>> salgado = launchpad.people['salgado']
10
 
    >>> salgado.display_name
11
 
    u'Guilherme Salgado'
 
10
    >>> print salgado.display_name
 
11
    Guilherme Salgado
12
12
 
13
13
These objects may have a number of attributes, as well as associated
14
14
collections and entries. Introspection methods give you access to this
31
31
Salgado to batch the changes over the wire for efficiency.
32
32
 
33
33
    >>> salgado.display_name = u'Salgado'
34
 
    >>> launchpad.people['salgado'].display_name
35
 
    u'Guilherme Salgado'
 
34
    >>> print launchpad.people['salgado'].display_name
 
35
    Guilherme Salgado
36
36
 
37
37
Once the changes are saved though, they are saved on the web service.
38
38
 
50
50
through the web service.
51
51
 
52
52
    >>> salgado.lp_save()
53
 
    >>> launchpad.people['salgado'].display_name
54
 
    u'Salgado'
 
53
    >>> print launchpad.people['salgado'].display_name
 
54
    Salgado
55
55
 
56
56
The entry object is a normal Python object like any other. Attributes
57
57
of the entry, like 'display_name', are available as attributes on the
120
120
 
121
121
    >>> print bassists.team_description
122
122
    None
123
 
    >>> bassists.subscription_policy
124
 
    u'Moderated Team'
 
123
    >>> print bassists.subscription_policy
 
124
    Moderated Team
125
125
 
126
126
    >>> bassists.team_description = (
127
127
    ...     u'The most important instrument in the world')
144
144
    >>> bassists_copy.lp_refresh()
145
145
    >>> print bassists.team_description
146
146
    The most important instrument in the world
147
 
    >>> bassists.subscription_policy
148
 
    u'Open Team'
 
147
    >>> print bassists.subscription_policy
 
148
    Open Team
149
149
 
150
150
Some of a resource's attributes may take other resources as values.
151
151
 
163
163
 
164
164
Resources may also be used as arguments to named operations.
165
165
 
166
 
    >>> task.assignee.display_name
167
 
    u'Mark Shuttleworth'
 
166
    >>> print task.assignee.display_name
 
167
    Mark Shuttleworth
168
168
    >>> task.transitionToAssignee(assignee=salgado)
169
 
    >>> task.assignee.display_name
170
 
    u'Guilherme Salgado'
 
169
    >>> print task.assignee.display_name
 
170
    Guilherme Salgado
171
171
 
172
172
    # XXX: salgado, 2008-08-01: Commented because method has been Unexported;
173
173
    # it should be re-enabled after the operation is exported again.
192
192
    ...
193
193
    KeyError: 'salgado'
194
194
 
195
 
    >>> launchpad.people['guilherme'].display_name
196
 
    u'Guilherme Salgado'
 
195
    >>> print launchpad.people['guilherme'].display_name
 
196
    Guilherme Salgado
197
197
 
198
198
Under the covers though, a refresh of the original object has been retrieved
199
199
from Launchpad, so it's save to continue using, and changing it.
200
200
 
201
201
    >>> salgado.display_name = u'Salgado!'
202
202
    >>> salgado.lp_save()
203
 
    >>> launchpad.people['guilherme'].display_name
204
 
    u'Salgado!'
 
203
    >>> print launchpad.people['guilherme'].display_name
 
204
    Salgado!
205
205
 
206
206
It's just as easy to move Salgado back to the old name.
207
207
 
212
212
    ...
213
213
    KeyError: 'guilherme'
214
214
 
215
 
    >>> launchpad.people['salgado'].display_name
216
 
    u'Salgado!'
 
215
    >>> print launchpad.people['salgado'].display_name
 
216
    Salgado!
217
217
 
218
218
 
219
219
== Read-only attributes ==
272
272
made, before making their own changes.
273
273
 
274
274
    >>> second_firefox.lp_refresh()
275
 
    >>> second_firefox.description
276
 
    u'A description.'
 
275
    >>> print second_firefox.description
 
276
    A description.
277
277
 
278
278
    >>> second_firefox.description = 'A conflicting description.'
279
279
    >>> second_firefox.lp_save()
 
280
 
 
281
Conflict detection works even when you operate on an object you
 
282
retrieved from a collection.
 
283
 
 
284
    >>> first_user = first_launchpad.people[:10][0]
 
285
    >>> second_user = second_launchpad.people[:10][0]
 
286
    >>> first_user.name == second_user.name
 
287
    True
 
288
 
 
289
    >>> first_user.display_name = "A display name"
 
290
    >>> first_user.lp_save()
 
291
 
 
292
    >>> second_user.display_name = "A conflicting display name"
 
293
    >>> second_user.lp_save()
 
294
    Traceback (most recent call last):
 
295
    ...
 
296
    HTTPError: HTTP Error 412: Precondition Failed
 
297
 
 
298
    >>> second_user.lp_refresh()
 
299
    >>> print second_user.display_name
 
300
    A display name
 
301
 
 
302
    >>> second_user.display_name = "A conflicting display name"
 
303
    >>> second_user.lp_save()
 
304
 
 
305
    >>> first_user.lp_refresh()
 
306
    >>> print first_user.display_name
 
307
    A conflicting display name
 
308
 
 
309