11090.3.7
by Brad Crittenden
Added new doctest for vouchers. |
1 |
Person Vouchers |
2 |
=============== |
|
3 |
||
4 |
Users who own commercial projects with a proprietary license can |
|
5 |
purchase vouchers from the Canonical Shop. The voucher is subsequently |
|
6 |
applied to one of their projects to initiate or renew their |
|
7 |
commerical-use subscription. |
|
8 |
||
9 |
>>> from zope.component import getUtility |
|
10 |
>>> from lp.registry.interfaces.person import IPersonSet |
|
11 |
>>> person_set = getUtility(IPersonSet) |
|
12 |
>>> cprov = person_set.getByName('cprov') |
|
13 |
||
11090.3.10
by Brad Crittenden
Move salesforce to lp.services |
14 |
>>> from lp.services.salesforce.tests.proxy import ( |
11090.3.7
by Brad Crittenden
Added new doctest for vouchers. |
15 |
... SalesforceXMLRPCTestTransport, TestSalesforceVoucherProxy) |
16 |
>>> test_transport = SalesforceXMLRPCTestTransport() |
|
17 |
>>> voucher_proxy = TestSalesforceVoucherProxy() |
|
18 |
||
19 |
A method 'getAllCommercialSubscriptionVouchers' returns a dictionary |
|
20 |
indexed by the valid voucher statuses with a list of the person's |
|
21 |
vouchers in the given state. |
|
22 |
||
23 |
>>> def print_vouchers(voucher_dict): |
|
24 |
... """Pretty print a dictionary of vouchers.""" |
|
25 |
... for voucher_type in sorted(voucher_dict): |
|
26 |
... print voucher_type |
|
27 |
... vouchers = voucher_dict[voucher_type] |
|
28 |
... if len(vouchers) == 0: |
|
29 |
... print " ", None |
|
30 |
... else: |
|
31 |
... for voucher in voucher_dict[voucher_type]: |
|
32 |
... print " ", voucher |
|
33 |
||
34 |
>>> vouchers = cprov.getAllCommercialSubscriptionVouchers(voucher_proxy=voucher_proxy) |
|
35 |
>>> print_vouchers(vouchers) |
|
36 |
Redeemed |
|
37 |
None |
|
38 |
Reserved |
|
39 |
LPCBS12-f78df324-0cc2-11dd-8b6b-000000000004,Reserved,12,unassigned |
|
40 |
LPCBS12-f78df324-0cc2-11dd-8b6b-000000000005,Reserved,12,unassigned |
|
41 |
Unredeemed |
|
42 |
None |
|
43 |
||
44 |
Just the list of redeemable vouchers can be obtained using the |
|
45 |
getRedeemableCommercialSubscriptionVouchers. All vouchers of status |
|
46 |
Unredeemed or Reserved are returned in a single list. |
|
47 |
||
48 |
>>> vouchers = cprov.getRedeemableCommercialSubscriptionVouchers( |
|
49 |
... voucher_proxy=voucher_proxy) |
|
50 |
>>> for voucher in vouchers: |
|
51 |
... print voucher |
|
52 |
LPCBS12-f78df324-0cc2-11dd-8b6b-000000000004,Reserved,12,unassigned |
|
53 |
LPCBS12-f78df324-0cc2-11dd-8b6b-000000000005,Reserved,12,unassigned |
|
54 |
||
55 |
When a voucher is redeemed its status changes. |
|
56 |
||
57 |
>>> voucher = vouchers[0] |
|
58 |
>>> product = factory.makeProduct(name='ubutini') |
|
59 |
>>> result = voucher_proxy.redeemVoucher( |
|
60 |
... voucher.voucher_id, cprov, product) |
|
61 |
>>> print result |
|
62 |
True |
|
63 |
||
64 |
>>> vouchers = cprov.getAllCommercialSubscriptionVouchers(voucher_proxy=voucher_proxy) |
|
65 |
>>> print_vouchers(vouchers) |
|
66 |
Redeemed |
|
67 |
LPCBS12-f78df324-0cc2-11dd-8b6b-000000000004,Redeemed,12,ubutini |
|
68 |
Reserved |
|
69 |
LPCBS12-f78df324-0cc2-11dd-8b6b-000000000005,Reserved,12,unassigned |
|
70 |
Unredeemed |
|
71 |
None |
|
11090.3.8
by Brad Crittenden
Added test and fixed exposed bug in getRedeemableCommercialSubscriptionVouchers. |
72 |
|
73 |
The redeemed voucher is no longer listed in the list of redeemable ones. |
|
74 |
||
75 |
>>> vouchers = cprov.getRedeemableCommercialSubscriptionVouchers( |
|
76 |
... voucher_proxy=voucher_proxy) |
|
77 |
>>> for voucher in vouchers: |
|
78 |
... print voucher |
|
79 |
LPCBS12-f78df324-0cc2-11dd-8b6b-000000000005,Reserved,12,unassigned |