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
=== modified file 'requirements.txt'
--- requirements.txt 2013-03-26 23:14:30 +0000
+++ requirements.txt 2013-04-05 21:17:20 +0000
@@ -5,6 +5,6 @@
5pyflakes5pyflakes
6Twisted6Twisted
7bzr+ssh://bazaar.launchpad.net/~bloodearnest/localmail/trunk7bzr+ssh://bazaar.launchpad.net/~bloodearnest/localmail/trunk
8bzr+http://bazaar.launchpad.net/~ubuntuone-hackers/payclient/trunk@38bzr+http://bazaar.launchpad.net/~ubuntuone-hackers/payclient/trunk@4
9bzr+http://bazaar.launchpad.net/~canonical-isd-qa/selenium-simple-test/trunk@3679bzr+http://bazaar.launchpad.net/~canonical-isd-qa/selenium-simple-test/trunk@367
10bzr+http://bazaar.launchpad.net/~canonical-isd-hackers/canonical-identity-provider/ssoclient@310bzr+http://bazaar.launchpad.net/~canonical-isd-hackers/canonical-identity-provider/ssoclient@3
1111
=== modified file 'u1testutils/pay/client.py'
--- u1testutils/pay/client.py 2013-03-27 20:54:15 +0000
+++ u1testutils/pay/client.py 2013-04-05 21:17:20 +0000
@@ -59,22 +59,6 @@
59 country is the name of the country in english.59 country is the name of the country in english.
6060
61 """61 """
62 billing_address_dict = {62 credit_card_request = payclient.CreditCardRequest.from_data_objects(
63 'street': billing_address.street_line1,63 shop_id, user.openid, credit_card, billing_address)
64 'state': billing_address.state,
65 'country': billing_address.get_country_code(),
66 'postal': billing_address.postal_code
67 }
68 kwargs = dict(
69 shop_id=shop_id,
70 open_id=user.openid,
71 card_type=credit_card.card_type,
72 card_holder=credit_card.name_on_card,
73 card_number=credit_card.card_number,
74 card_ccv=credit_card.ccv_number,
75 card_expiration_month=credit_card.expiration_month,
76 card_expiration_year=credit_card.expiration_year,
77 billing_address=billing_address_dict
78 )
79 credit_card_request = payclient.CreditCardRequest(**kwargs)
80 return self.client.new_credit_card(data=credit_card_request)64 return self.client.new_credit_card(data=credit_card_request)
8165
=== modified file 'u1testutils/pay/data.py'
--- u1testutils/pay/data.py 2013-03-27 18:36:28 +0000
+++ u1testutils/pay/data.py 2013-04-05 21:17:20 +0000
@@ -14,20 +14,11 @@
1414
15import uuid15import uuid
1616
1717import payclient.data
18class CreditCard(object):18
1919
20 def __init__(self, card_type, name_on_card, card_number, ccv_number,20class CreditCard(payclient.data.CreditCard):
21 expiration_month, expiration_year):21 """Extends the payclient CreditCard to add factory methods for testing."""
22 self.card_type = card_type
23 self.name_on_card = name_on_card
24 self.card_number = card_number
25 self.ccv_number = ccv_number
26 self.expiration_month = expiration_month
27 self.expiration_year = expiration_year
28
29 def __repr__(self):
30 return '%s(%r)' % (self.__class__, self.__dict__)
3122
32 @classmethod23 @classmethod
33 def make_test_visa_card(cls, unique_id=None):24 def make_test_visa_card(cls, unique_id=None):
@@ -43,19 +34,24 @@
43 expiration_month, expiration_year)34 expiration_month, expiration_year)
4435
4536
46class Address(object):37class Address(payclient.data.Address):
4738 """Extends the payclient Address to add factory methods for testing.
48 def __init__(self, street_line1=None, street_line2=None, city=None,39
49 state=None, postal_code=None, country=None):40 It also receives a country name in the constructor, instead of a country
41 code, receives the street_line2 and city, and concatenates street_line1
42 and street_line2 in the street attribute that the parent class receives.
43
44 """
45
46 def __init__(self, street_line1, street_line2, city, state, postal_code,
47 country):
48 self.country = country
50 self.street_line1 = street_line149 self.street_line1 = street_line1
51 self.street_line2 = street_line250 self.street_line2 = street_line2
52 self.city = city51 self.city = city
53 self.state = state52 street = '{0}\n{1}'.format(street_line1, street_line2)
54 self.postal_code = postal_code53 super(Address, self).__init__(
55 self.country = country54 street, state, postal_code, self._get_country_code())
56
57 def __repr__(self):
58 return '%s(%r)' % (self.__class__, self.__dict__)
5955
60 @classmethod56 @classmethod
61 def make_unique(cls, unique_id=None):57 def make_unique(cls, unique_id=None):
@@ -70,7 +66,7 @@
70 return cls(66 return cls(
71 street_line1, street_line2, city, state, postal_code, country)67 street_line1, street_line2, city, state, postal_code, country)
7268
73 def get_country_code(self):69 def _get_country_code(self):
74 # TODO add more?70 # TODO add more?
75 country_data = {'United States': 'US'}71 country_data = {'United States': 'US'}
76 return country_data.get(self.country)72 return country_data.get(self.country)
7773
=== modified file 'u1testutils/pay/selftests/unit/test_pay_api_client.py'
--- u1testutils/pay/selftests/unit/test_pay_api_client.py 2013-03-27 20:54:15 +0000
+++ u1testutils/pay/selftests/unit/test_pay_api_client.py 2013-04-05 21:17:20 +0000
@@ -73,21 +73,7 @@
73 as mock_api_call:73 as mock_api_call:
74 api_client.add_new_credit_card(74 api_client.add_new_credit_card(
75 shop_id, self.user, self.credit_card, self.billing_address)75 shop_id, self.user, self.credit_card, self.billing_address)
76 expected_params = {
77 'shop_id': shop_id,
78 'open_id': self.user.openid,
79 'card_type': self.credit_card.card_type,
80 'card_holder': self.credit_card.name_on_card,
81 'card_number': self.credit_card.card_number,
82 'card_ccv': self.credit_card.ccv_number,
83 'card_expiration_month': self.credit_card.expiration_month,
84 'card_expiration_year': self.credit_card.expiration_year,
85 'billing_address': {
86 'street': self.billing_address.street_line1,
87 'state': self.billing_address.state,
88 'postal': self.billing_address.postal_code,
89 'country': 'US',
90 }
91 }
92 mock_api_call.assert_called_with(76 mock_api_call.assert_called_with(
93 data=payclient.CreditCardRequest(**expected_params))77 data=payclient.CreditCardRequest.from_data_objects(
78 shop_id, self.user.openid, self.credit_card,
79 self.billing_address))

Subscribers

People subscribed via source and target branches

to all changes: