Merge lp:~elopio/payclient/creditcardrequest_equality into lp:payclient

Proposed by Leo Arias
Status: Merged
Approved by: Leo Arias
Approved revision: 7
Merged at revision: 3
Proposed branch: lp:~elopio/payclient/creditcardrequest_equality
Merge into: lp:payclient
Diff against target: 81 lines (+55/-0)
3 files modified
README (+14/-0)
src/payclient/client.py (+7/-0)
src/payclient/tests/test_client.py (+34/-0)
To merge this branch: bzr merge lp:~elopio/payclient/creditcardrequest_equality
Reviewer Review Type Date Requested Status
Matias Bordese (community) Approve
Review via email: mp+155637@code.launchpad.net

Commit message

Implement the equality functions for the CreditClassRequest object.

Description of the change

In order to test the arguments passed to the API client from the helper utilities, we need to compare the actual CreditCardRequest with the expected one. This branch makes that easier.

The branch that will use this feature is:
https://code.launchpad.net/~elopio/u1-test-utils/pay_client_return_response/+merge/155609

To post a comment you must log in.
5. By Leo Arias

Added the not equal test.

6. By Leo Arias

Added a README file.

7. By Leo Arias

Added the missing tests suggested by matias.

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

LGTM

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

<matiasb> elopio: on the first one, I would add another test for eq, with some data (besides the empty case); and you should add a test comparing 2 different kind of requests (PaymentRequest vs CardRequest), since that's also required by your eq check

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'README'
2--- README 1970-01-01 00:00:00 +0000
3+++ README 2013-03-27 17:36:19 +0000
4@@ -0,0 +1,14 @@
5+Getting started:
6+================
7+
8+1. Get the code:
9+
10+ bzr branch lp:payclient
11+
12+2. Install the requirements:
13+
14+ sudo apt-get install python-dateutil python-mock
15+
16+3. Run the tests:
17+
18+ ./tarmat_tests.sh
19
20=== modified file 'src/payclient/client.py'
21--- src/payclient/client.py 2013-03-25 19:52:22 +0000
22+++ src/payclient/client.py 2013-03-27 17:36:19 +0000
23@@ -44,6 +44,13 @@
24 )
25 make_unattended_default = False
26
27+ def __eq__(self, other):
28+ return (isinstance(other, self.__class__)
29+ and self.__dict__ == other.__dict__)
30+
31+ def __ne__(self, other):
32+ return not self.__eq__(other)
33+
34
35 class PaymentRequest(PistonSerializable):
36 _atts = (
37
38=== modified file 'src/payclient/tests/test_client.py'
39--- src/payclient/tests/test_client.py 2013-03-25 20:46:05 +0000
40+++ src/payclient/tests/test_client.py 2013-03-27 17:36:19 +0000
41@@ -54,6 +54,40 @@
42 request = CreditCardRequest()
43 self.assertEqual(request.make_unattended_default, False)
44
45+ def test_equals_with_no_attributes(self):
46+ request1 = CreditCardRequest()
47+ request2 = CreditCardRequest()
48+ self.assertEqual(request1, request2)
49+
50+ def test_equals_with_attributes(self):
51+ params = {
52+ 'shop_id': 'test_shop',
53+ 'open_id': 'test_openid',
54+ 'card_type': 'test_card',
55+ 'card_holder': 'test_name',
56+ 'card_number': '123',
57+ 'card_ccv': '321',
58+ 'card_expiration_month': '12',
59+ 'card_expiration_year': '2013',
60+ 'make_unattended_default': False,
61+ 'billing_address': {
62+ 'address': 'test_address'
63+ },
64+ }
65+ request1 = CreditCardRequest(**params)
66+ request2 = CreditCardRequest(**params)
67+ self.assertEqual(request1, request2)
68+
69+ def test_not_equals_with_attributes(self):
70+ request1 = CreditCardRequest(shop_id='test1')
71+ request2 = CreditCardRequest(shop_id='test2')
72+ self.assertNotEqual(request1, request2)
73+
74+ def test_not_equals_with_different_class(self):
75+ request1 = CreditCardRequest()
76+ request2 = PaymentRequest()
77+ self.assertNotEqual(request1, request2)
78+
79
80 class PaymentRequestTestCase(TestCase):
81 def test_request_attributes(self):

Subscribers

People subscribed via source and target branches

to all changes: