Skip to content
Browse files

set_details now uses keyword arguments

  • Loading branch information...
1 parent 27de39f commit 5d1b6fa89b72d59edbd02f56cd0d81116f9b4b89 @alexjg alexjg committed
Showing with 31 additions and 10 deletions.
  1. +4 −4 README.rst
  2. +11 −2 gocardless/__init__.py
  3. +16 −4 test/test_client.py
View
8 README.rst
@@ -15,10 +15,10 @@ the `gocardless.environment` to "sandbox".::
Set your account details:::
- >>> gocardless.set_details("kzCOPw2JtJvRQxKOPEREQTGvxLvkoMS1Eb0Dgl5QVc1W0NKpOEZDvESfGOI_kkG2l", #app_id
- >>> "IO9AlgPsbYNCtFlcOFGROBrGB3Mi07PFYSn2zx4uK5xaWJI1AzwnYeC86x46ji_g", #app_secret
- >>> "5EFkzOrUOZ8t+iaP86NggIy+FOFSD0f7QMnMd+Q3P4mQk17Kzq9G1vYrNlEWFldlg", #access_token
- >>> "02FX1YFDAS" #merchant_id)
+ >>> gocardless.set_details(app_id="kzCOPw2JtJvRQxKOPEREQTGvxLvkoMS1Eb0Dgl5QVc1W0NKpOEZDvESfGOI_kkG2l",
+ >>> app_secret="IO9AlgPsbYNCtFlcOFGROBrGB3Mi07PFYSn2zx4uK5xaWJI1AzwnYeC86x46ji_g",
+ >>> access_token="5EFkzOrUOZ8t+iaP86NggIy+FOFSD0f7QMnMd+Q3P4mQk17Kzq9G1vYrNlEWFldlg",
+ >>> merchant_id="02FX1YFDAS")
You can now use the `gocardless.client` object to generate urls for receiving payments.::
View
13 gocardless/__init__.py
@@ -42,12 +42,21 @@ def get_version():
:py:func:`gocardless.set_details` has been called.
"""
-def set_details(app_id, app_secret, access_token, merchant_id):
+def set_details(app_id=None, app_secret=None, access_token=None, merchant_id=None):
"""Set the global account details to use for requests
The parameters are your security details which can be found
- on your gocardless developer details page.
+ on your gocardless developer details page. All are mandatory
"""
+ if app_id is None:
+ raise ValueError("app_id is required")
+ if app_secret is None:
+ raise ValueError("app_secret is required")
+ if access_token is None:
+ raise ValueError("access_token is required")
+ if merchant_id is None:
+ raise ValueError("merchant_id is required")
+
global client
client = Client(app_id, app_secret, access_token=access_token,
merchant_id=merchant_id)
View
20 test/test_client.py
@@ -112,12 +112,24 @@ def _get_resource_tester(self, resource_name, resource_fixture):
self.assertIsInstance(obj, expected_klass)
def test_set_details_creates_client(self):
- gocardless.set_details(mock_account_details["app_id"],
- mock_account_details["app_secret"],
- mock_account_details["token"],
- mock_account_details["merchant_id"])
+ gocardless.set_details(app_id=mock_account_details["app_id"],
+ app_secret=mock_account_details["app_secret"],
+ access_token=mock_account_details["token"],
+ merchant_id=mock_account_details["merchant_id"])
self.assertIsNotNone(gocardless.client)
+ def test_set_details_valueerror_raised_when_details_not_present(self):
+ details = mock_account_details.copy()
+ details["access_token"] = details["token"]
+ details.pop("token")
+ for key in details.keys():
+ #make sure that every key is required by passing in a hash with
+ #all but one key missing
+ invalid_details = details.copy()
+ invalid_details.pop(key)
+ with self.assertRaises(ValueError):
+ gocardless.set_details(**invalid_details)
+
def test_create_bill(self):
with patch.object(self.client, 'api_post') as mock_post:
expected_path = "/bills"

0 comments on commit 5d1b6fa

Please sign in to comment.
Something went wrong with that request. Please try again.