Skip to content

Commit a8508f6

Browse files
committed
Added test coverage, fix bugs with xapi and basic auth
1 parent ade8c42 commit a8508f6

File tree

3 files changed

+51
-23
lines changed

3 files changed

+51
-23
lines changed

Adyen/client.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,11 +222,13 @@ def call_api(self, request_data, service, action, idempotency=False,
222222

223223
# username at self object has highest priority. fallback to root module
224224
# and ensure that it is set.
225+
xapikey = None
225226
if self.xapikey:
226227
xapikey = self.xapikey
227228
elif 'xapikey' in kwargs:
228229
xapikey = kwargs.pop("xapikey")
229230

231+
username = None
230232
if self.username:
231233
username = self.username
232234
elif 'username' in kwargs:
@@ -237,15 +239,18 @@ def call_api(self, request_data, service, action, idempotency=False,
237239
username = self._store_payout_username(**kwargs)
238240
else:
239241
username = self._review_payout_username(**kwargs)
240-
if not username:
242+
243+
if not username and not xapikey:
241244
errorstring = """Please set your webservice username.
242245
You can do this by running
243246
'Adyen.username = 'Your username'"""
244247
raise AdyenInvalidRequestError(errorstring)
245248
# password at self object has highest priority.
246249
# fallback to root module
247250
# and ensure that it is set.
248-
if self.password:
251+
252+
password = None
253+
if self.password and not xapikey:
249254
password = self.password
250255
elif 'password' in kwargs:
251256
password = kwargs.pop("password")
@@ -255,7 +260,8 @@ def call_api(self, request_data, service, action, idempotency=False,
255260
password = self._store_payout_pass(**kwargs)
256261
else:
257262
password = self._review_payout_pass(**kwargs)
258-
if not password:
263+
264+
if not password and not xapikey:
259265
errorstring = """Please set your webservice password.
260266
You can do this by running
261267
'Adyen.password = 'Your password'"""

test/BaseTest.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import mock
1+
2+
try:
3+
import mock
4+
except Exception:
5+
from unittest import mock
26
import json
37
from Adyen import httpclient
48

test/PaymentTest.py

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,6 @@
44

55

66
class TestPayments(unittest.TestCase):
7-
adyen = Adyen.Adyen()
8-
9-
client = adyen.client
10-
test = BaseTest(adyen)
11-
client.username = "YourWSUser"
12-
client.password = "YourWSPassword"
13-
client.platform = "test"
14-
client.app_name = "appname"
157

168
def test_authorise_success_mocked(self):
179
request = {}
@@ -197,14 +189,40 @@ def test_error_401_mocked(self):
197189
self.adyen.payment.authorise, request)
198190

199191

200-
TestPayments.client.http_force = "requests"
201-
suite = unittest.TestLoader().loadTestsFromTestCase(TestPayments)
202-
unittest.TextTestRunner(verbosity=2).run(suite)
203-
TestPayments.client.http_force = "pycurl"
204-
TestPayments.client.http_init = False
205-
suite = unittest.TestLoader().loadTestsFromTestCase(TestPayments)
206-
unittest.TextTestRunner(verbosity=2).run(suite)
207-
TestPayments.client.http_force = "other"
208-
TestPayments.client.http_init = False
209-
suite = unittest.TestLoader().loadTestsFromTestCase(TestPayments)
210-
unittest.TextTestRunner(verbosity=2).run(suite)
192+
class BasicAuth(TestPayments):
193+
adyen = Adyen.Adyen()
194+
195+
client = adyen.client
196+
test = BaseTest(adyen)
197+
client.username = "YourWSUser"
198+
client.password = "YourWSPassword"
199+
client.platform = "test"
200+
client.app_name = "appname"
201+
202+
203+
class XApiKey(TestPayments):
204+
adyen = Adyen.Adyen()
205+
206+
client = adyen.client
207+
test = BaseTest(adyen)
208+
client.platform = "test"
209+
client.app_name = "appname"
210+
client.xapikey = "YourWSXApiKey"
211+
212+
213+
def test_with(auth):
214+
auth.client.http_force = "requests"
215+
suite = unittest.TestLoader().loadTestsFromTestCase(auth)
216+
unittest.TextTestRunner(verbosity=2).run(suite)
217+
auth.client.http_force = "pycurl"
218+
auth.client.http_init = False
219+
suite = unittest.TestLoader().loadTestsFromTestCase(auth)
220+
unittest.TextTestRunner(verbosity=2).run(suite)
221+
auth.client.http_force = "other"
222+
auth.client.http_init = False
223+
suite = unittest.TestLoader().loadTestsFromTestCase(auth)
224+
unittest.TextTestRunner(verbosity=2).run(suite)
225+
226+
227+
test_with(BasicAuth)
228+
test_with(XApiKey)

0 commit comments

Comments
 (0)