edx-enterprise-subsidy-client 0.4.3__tar.gz → 0.4.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (19) hide show
  1. {edx-enterprise-subsidy-client-0.4.3 → edx_enterprise_subsidy_client-0.4.4}/CHANGELOG.rst +4 -0
  2. {edx-enterprise-subsidy-client-0.4.3 → edx_enterprise_subsidy_client-0.4.4}/PKG-INFO +5 -1
  3. {edx-enterprise-subsidy-client-0.4.3 → edx_enterprise_subsidy_client-0.4.4}/edx_enterprise_subsidy_client/__init__.py +1 -1
  4. {edx-enterprise-subsidy-client-0.4.3 → edx_enterprise_subsidy_client-0.4.4}/edx_enterprise_subsidy_client/client.py +40 -0
  5. {edx-enterprise-subsidy-client-0.4.3 → edx_enterprise_subsidy_client-0.4.4}/edx_enterprise_subsidy_client.egg-info/PKG-INFO +5 -1
  6. {edx-enterprise-subsidy-client-0.4.3 → edx_enterprise_subsidy_client-0.4.4}/tests/test_client.py +38 -0
  7. {edx-enterprise-subsidy-client-0.4.3 → edx_enterprise_subsidy_client-0.4.4}/LICENSE +0 -0
  8. {edx-enterprise-subsidy-client-0.4.3 → edx_enterprise_subsidy_client-0.4.4}/LICENSE.txt +0 -0
  9. {edx-enterprise-subsidy-client-0.4.3 → edx_enterprise_subsidy_client-0.4.4}/MANIFEST.in +0 -0
  10. {edx-enterprise-subsidy-client-0.4.3 → edx_enterprise_subsidy_client-0.4.4}/README.rst +0 -0
  11. {edx-enterprise-subsidy-client-0.4.3 → edx_enterprise_subsidy_client-0.4.4}/edx_enterprise_subsidy_client.egg-info/SOURCES.txt +0 -0
  12. {edx-enterprise-subsidy-client-0.4.3 → edx_enterprise_subsidy_client-0.4.4}/edx_enterprise_subsidy_client.egg-info/dependency_links.txt +0 -0
  13. {edx-enterprise-subsidy-client-0.4.3 → edx_enterprise_subsidy_client-0.4.4}/edx_enterprise_subsidy_client.egg-info/not-zip-safe +0 -0
  14. {edx-enterprise-subsidy-client-0.4.3 → edx_enterprise_subsidy_client-0.4.4}/edx_enterprise_subsidy_client.egg-info/requires.txt +0 -0
  15. {edx-enterprise-subsidy-client-0.4.3 → edx_enterprise_subsidy_client-0.4.4}/edx_enterprise_subsidy_client.egg-info/top_level.txt +0 -0
  16. {edx-enterprise-subsidy-client-0.4.3 → edx_enterprise_subsidy_client-0.4.4}/requirements/base.in +0 -0
  17. {edx-enterprise-subsidy-client-0.4.3 → edx_enterprise_subsidy_client-0.4.4}/requirements/constraints.txt +0 -0
  18. {edx-enterprise-subsidy-client-0.4.3 → edx_enterprise_subsidy_client-0.4.4}/setup.cfg +0 -0
  19. {edx-enterprise-subsidy-client-0.4.3 → edx_enterprise_subsidy_client-0.4.4}/setup.py +0 -0
@@ -14,6 +14,10 @@ Change Log
14
14
  Unreleased
15
15
  **********
16
16
 
17
+ [0.4.4]
18
+ *******
19
+ * feat: add support for deposit creation (ENT-9133)
20
+
17
21
  [0.4.3]
18
22
  *******
19
23
  * feat: adding new subsidy client method to fetch subsidy aggregate data
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: edx-enterprise-subsidy-client
3
- Version: 0.4.3
3
+ Version: 0.4.4
4
4
  Summary: Client for interacting with the enterprise-subsidy service.
5
5
  Home-page: https://github.com/openedx/edx-enterprise-subsidy-client
6
6
  Author: edX
@@ -225,6 +225,10 @@ Change Log
225
225
  Unreleased
226
226
  **********
227
227
 
228
+ [0.4.4]
229
+ *******
230
+ * feat: add support for deposit creation (ENT-9133)
231
+
228
232
  [0.4.3]
229
233
  *******
230
234
  * feat: adding new subsidy client method to fetch subsidy aggregate data
@@ -2,6 +2,6 @@
2
2
  Client for interacting with the enterprise-subsidy service..
3
3
  """
4
4
 
5
- __version__ = '0.4.3'
5
+ __version__ = '0.4.4'
6
6
 
7
7
  from .client import EnterpriseSubsidyAPIClient, EnterpriseSubsidyAPIClientV2, get_enterprise_subsidy_api_client
@@ -291,6 +291,7 @@ class EnterpriseSubsidyAPIClientV2(EnterpriseSubsidyAPIClient): # pylint: disab
291
291
  """
292
292
  V2_BASE_URL = EnterpriseSubsidyAPIClient.API_BASE_URL + 'v2/'
293
293
  TRANSACTIONS_LIST_ENDPOINT = V2_BASE_URL + 'subsidies/{subsidy_uuid}/admin/transactions/'
294
+ DEPOSITS_CREATE_ENDPOINT = V2_BASE_URL + 'subsidies/{subsidy_uuid}/admin/deposits/'
294
295
 
295
296
  def list_subsidy_transactions(
296
297
  self, subsidy_uuid, include_aggregates=True,
@@ -370,3 +371,42 @@ class EnterpriseSubsidyAPIClientV2(EnterpriseSubsidyAPIClient): # pylint: disab
370
371
  )
371
372
  response.raise_for_status()
372
373
  return response.json()
374
+
375
+ def create_subsidy_deposit(
376
+ self,
377
+ subsidy_uuid,
378
+ desired_deposit_quantity,
379
+ sales_contract_reference_id,
380
+ sales_contract_reference_provider,
381
+ metadata,
382
+ idempotency_key=None,
383
+ ):
384
+ """
385
+ Creates a deposit in the given subsidy, requires operator-level permissions.
386
+
387
+ Raises:
388
+ requests.exceptions.HTTPError:
389
+ - 403 Forbidden: If auth failed.
390
+ - 429 Too Many Requests: If the ledger was locked (resource contention, try again later).
391
+ - 400 Bad Request: If any of the values were invalid. Reasons include:
392
+ * non-positive quantity.
393
+ * provider slug does not exist in database.
394
+ - 422 Unprocessable Entity: Catchall status for anything that prevented the deposit from being
395
+ created. Reasons include, but are not limited to:
396
+ * Subsidy is inactive.
397
+ * Another deposit with same idempotency_key already exists.
398
+ """
399
+ request_payload = {
400
+ 'desired_deposit_quantity': desired_deposit_quantity,
401
+ 'sales_contract_reference_id': sales_contract_reference_id,
402
+ 'sales_contract_reference_provider': sales_contract_reference_provider,
403
+ 'metadata': metadata,
404
+ }
405
+ if idempotency_key is not None:
406
+ request_payload['idempotency_key'] = idempotency_key
407
+ response = self.client.post(
408
+ self.DEPOSITS_CREATE_ENDPOINT.format(subsidy_uuid=subsidy_uuid),
409
+ json=request_payload,
410
+ )
411
+ response.raise_for_status()
412
+ return response.json()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: edx-enterprise-subsidy-client
3
- Version: 0.4.3
3
+ Version: 0.4.4
4
4
  Summary: Client for interacting with the enterprise-subsidy service.
5
5
  Home-page: https://github.com/openedx/edx-enterprise-subsidy-client
6
6
  Author: edX
@@ -225,6 +225,10 @@ Change Log
225
225
  Unreleased
226
226
  **********
227
227
 
228
+ [0.4.4]
229
+ *******
230
+ * feat: add support for deposit creation (ENT-9133)
231
+
228
232
  [0.4.3]
229
233
  *******
230
234
  * feat: adding new subsidy client method to fetch subsidy aggregate data
@@ -172,3 +172,41 @@ def test_v2_list_subsidy_transactions(mock_oauth_client):
172
172
  'page_size': 1,
173
173
  },
174
174
  )
175
+
176
+
177
+ @mock.patch('edx_enterprise_subsidy_client.client.OAuthAPIClient', return_value=mock.MagicMock())
178
+ def test_client_v2_create_subsidy_deposit(mock_oauth_client):
179
+ """
180
+ Test the client's ability to create subsidy deposits.
181
+ """
182
+ mocked_data = {
183
+ 'uuid': str(uuid.uuid4()),
184
+ }
185
+ mock_post = mock_oauth_client.return_value.post
186
+ mock_post.return_value = MockResponse(mocked_data, 201)
187
+
188
+ subsidy_service_client = EnterpriseSubsidyAPIClientV2()
189
+
190
+ payload = {
191
+ 'subsidy_uuid': uuid.uuid4(),
192
+ 'desired_deposit_quantity': 100,
193
+ 'sales_contract_reference_id': str(uuid.uuid4()),
194
+ 'sales_contract_reference_provider': 'foo-bar',
195
+ 'idempotency_key': 'hello',
196
+ 'metadata': {'key': 'value'},
197
+ }
198
+
199
+ response = subsidy_service_client.create_subsidy_deposit(**payload)
200
+
201
+ assert response == mocked_data
202
+ expected_url = EnterpriseSubsidyAPIClientV2.DEPOSITS_CREATE_ENDPOINT.format(
203
+ subsidy_uuid=payload['subsidy_uuid'],
204
+ )
205
+ expected_post_payload = {
206
+ 'desired_deposit_quantity': 100,
207
+ 'sales_contract_reference_id': payload['sales_contract_reference_id'],
208
+ 'sales_contract_reference_provider': 'foo-bar',
209
+ 'idempotency_key': 'hello',
210
+ 'metadata': {'key': 'value'},
211
+ }
212
+ mock_post.assert_called_once_with(expected_url, json=expected_post_payload)