Merge lp:~elopio/u1-test-utils/payclient_data_objects into lp:u1-test-utils

Proposed by Leo Arias
Status: Merged
Approved by: Leo Arias
Approved revision: 47
Merged at revision: 43
Proposed branch: lp:~elopio/u1-test-utils/payclient_data_objects
Merge into: lp:u1-test-utils
Diff against target: 143 lines (+27/-61)
4 files modified
requirements.txt (+1/-1)
u1testutils/pay/client.py (+2/-18)
u1testutils/pay/data.py (+21/-25)
u1testutils/pay/selftests/unit/test_pay_api_client.py (+3/-17)
To merge this branch: bzr merge lp:~elopio/u1-test-utils/payclient_data_objects
Reviewer Review Type Date Requested Status
Matias Bordese (community) Approve
Review via email: mp+157435@code.launchpad.net

Commit message

Updated the payclient helpers to use the new data object factory method of CreditCardRequest. Also removed the duplicated bits of data objects.

To post a comment you must log in.
Revision history for this message
Leo Arias (elopio) wrote :

<pindonga> elopio, on the second mp: l. 8: this should be the result of landing the previous branch, not your own :)
<pindonga> elopio, l. 84: why redefine __init__ ? why not instead call super() and just add the extra pieces you need?
<pindonga> and I think that's sit
<elopio> pindonga: l. 8, yes, I left it in case you wanted to run the tests. I have it as work in progress to make sure I'll change it before landing.
<elopio> l. 84, I changed the country_code to a lazy property. So the super __init__ will fail if it tries to set it. I don't know a better solution. ideas?
<pindonga> elopio, you could just call super.__init__ passing country_code=self._get_country_code(country)
<pindonga> no need to have the lazy property at all
<elopio> pindonga: that makes more sense, right. I'll change it.

Revision history for this message
Leo Arias (elopio) wrote :

Reported bug #1165210 to follow up on the magic mock thing.

Revision history for this message
Leo Arias (elopio) wrote :
Revision history for this message
Matias Bordese (matiasb) wrote :

+1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'requirements.txt'
2--- requirements.txt 2013-03-26 23:14:30 +0000
3+++ requirements.txt 2013-04-05 21:17:20 +0000
4@@ -5,6 +5,6 @@
5 pyflakes
6 Twisted
7 bzr+ssh://bazaar.launchpad.net/~bloodearnest/localmail/trunk
8-bzr+http://bazaar.launchpad.net/~ubuntuone-hackers/payclient/trunk@3
9+bzr+http://bazaar.launchpad.net/~ubuntuone-hackers/payclient/trunk@4
10 bzr+http://bazaar.launchpad.net/~canonical-isd-qa/selenium-simple-test/trunk@367
11 bzr+http://bazaar.launchpad.net/~canonical-isd-hackers/canonical-identity-provider/ssoclient@3
12
13=== modified file 'u1testutils/pay/client.py'
14--- u1testutils/pay/client.py 2013-03-27 20:54:15 +0000
15+++ u1testutils/pay/client.py 2013-04-05 21:17:20 +0000
16@@ -59,22 +59,6 @@
17 country is the name of the country in english.
18
19 """
20- billing_address_dict = {
21- 'street': billing_address.street_line1,
22- 'state': billing_address.state,
23- 'country': billing_address.get_country_code(),
24- 'postal': billing_address.postal_code
25- }
26- kwargs = dict(
27- shop_id=shop_id,
28- open_id=user.openid,
29- card_type=credit_card.card_type,
30- card_holder=credit_card.name_on_card,
31- card_number=credit_card.card_number,
32- card_ccv=credit_card.ccv_number,
33- card_expiration_month=credit_card.expiration_month,
34- card_expiration_year=credit_card.expiration_year,
35- billing_address=billing_address_dict
36- )
37- credit_card_request = payclient.CreditCardRequest(**kwargs)
38+ credit_card_request = payclient.CreditCardRequest.from_data_objects(
39+ shop_id, user.openid, credit_card, billing_address)
40 return self.client.new_credit_card(data=credit_card_request)
41
42=== modified file 'u1testutils/pay/data.py'
43--- u1testutils/pay/data.py 2013-03-27 18:36:28 +0000
44+++ u1testutils/pay/data.py 2013-04-05 21:17:20 +0000
45@@ -14,20 +14,11 @@
46
47 import uuid
48
49-
50-class CreditCard(object):
51-
52- def __init__(self, card_type, name_on_card, card_number, ccv_number,
53- expiration_month, expiration_year):
54- self.card_type = card_type
55- self.name_on_card = name_on_card
56- self.card_number = card_number
57- self.ccv_number = ccv_number
58- self.expiration_month = expiration_month
59- self.expiration_year = expiration_year
60-
61- def __repr__(self):
62- return '%s(%r)' % (self.__class__, self.__dict__)
63+import payclient.data
64+
65+
66+class CreditCard(payclient.data.CreditCard):
67+ """Extends the payclient CreditCard to add factory methods for testing."""
68
69 @classmethod
70 def make_test_visa_card(cls, unique_id=None):
71@@ -43,19 +34,24 @@
72 expiration_month, expiration_year)
73
74
75-class Address(object):
76-
77- def __init__(self, street_line1=None, street_line2=None, city=None,
78- state=None, postal_code=None, country=None):
79+class Address(payclient.data.Address):
80+ """Extends the payclient Address to add factory methods for testing.
81+
82+ It also receives a country name in the constructor, instead of a country
83+ code, receives the street_line2 and city, and concatenates street_line1
84+ and street_line2 in the street attribute that the parent class receives.
85+
86+ """
87+
88+ def __init__(self, street_line1, street_line2, city, state, postal_code,
89+ country):
90+ self.country = country
91 self.street_line1 = street_line1
92 self.street_line2 = street_line2
93 self.city = city
94- self.state = state
95- self.postal_code = postal_code
96- self.country = country
97-
98- def __repr__(self):
99- return '%s(%r)' % (self.__class__, self.__dict__)
100+ street = '{0}\n{1}'.format(street_line1, street_line2)
101+ super(Address, self).__init__(
102+ street, state, postal_code, self._get_country_code())
103
104 @classmethod
105 def make_unique(cls, unique_id=None):
106@@ -70,7 +66,7 @@
107 return cls(
108 street_line1, street_line2, city, state, postal_code, country)
109
110- def get_country_code(self):
111+ def _get_country_code(self):
112 # TODO add more?
113 country_data = {'United States': 'US'}
114 return country_data.get(self.country)
115
116=== modified file 'u1testutils/pay/selftests/unit/test_pay_api_client.py'
117--- u1testutils/pay/selftests/unit/test_pay_api_client.py 2013-03-27 20:54:15 +0000
118+++ u1testutils/pay/selftests/unit/test_pay_api_client.py 2013-04-05 21:17:20 +0000
119@@ -73,21 +73,7 @@
120 as mock_api_call:
121 api_client.add_new_credit_card(
122 shop_id, self.user, self.credit_card, self.billing_address)
123- expected_params = {
124- 'shop_id': shop_id,
125- 'open_id': self.user.openid,
126- 'card_type': self.credit_card.card_type,
127- 'card_holder': self.credit_card.name_on_card,
128- 'card_number': self.credit_card.card_number,
129- 'card_ccv': self.credit_card.ccv_number,
130- 'card_expiration_month': self.credit_card.expiration_month,
131- 'card_expiration_year': self.credit_card.expiration_year,
132- 'billing_address': {
133- 'street': self.billing_address.street_line1,
134- 'state': self.billing_address.state,
135- 'postal': self.billing_address.postal_code,
136- 'country': 'US',
137- }
138- }
139 mock_api_call.assert_called_with(
140- data=payclient.CreditCardRequest(**expected_params))
141+ data=payclient.CreditCardRequest.from_data_objects(
142+ shop_id, self.user.openid, self.credit_card,
143+ self.billing_address))

Subscribers

People subscribed via source and target branches

to all changes: