edx-enterprise-subsidy-client 0.4.2__tar.gz → 0.4.3__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.
- {edx-enterprise-subsidy-client-0.4.2 → edx-enterprise-subsidy-client-0.4.3}/CHANGELOG.rst +4 -0
- {edx-enterprise-subsidy-client-0.4.2 → edx-enterprise-subsidy-client-0.4.3}/PKG-INFO +5 -1
- {edx-enterprise-subsidy-client-0.4.2 → edx-enterprise-subsidy-client-0.4.3}/edx_enterprise_subsidy_client/__init__.py +1 -1
- {edx-enterprise-subsidy-client-0.4.2 → edx-enterprise-subsidy-client-0.4.3}/edx_enterprise_subsidy_client/client.py +35 -0
- {edx-enterprise-subsidy-client-0.4.2 → edx-enterprise-subsidy-client-0.4.3}/edx_enterprise_subsidy_client.egg-info/PKG-INFO +5 -1
- {edx-enterprise-subsidy-client-0.4.2 → edx-enterprise-subsidy-client-0.4.3}/tests/test_client.py +37 -0
- {edx-enterprise-subsidy-client-0.4.2 → edx-enterprise-subsidy-client-0.4.3}/LICENSE +0 -0
- {edx-enterprise-subsidy-client-0.4.2 → edx-enterprise-subsidy-client-0.4.3}/LICENSE.txt +0 -0
- {edx-enterprise-subsidy-client-0.4.2 → edx-enterprise-subsidy-client-0.4.3}/MANIFEST.in +0 -0
- {edx-enterprise-subsidy-client-0.4.2 → edx-enterprise-subsidy-client-0.4.3}/README.rst +0 -0
- {edx-enterprise-subsidy-client-0.4.2 → edx-enterprise-subsidy-client-0.4.3}/edx_enterprise_subsidy_client.egg-info/SOURCES.txt +0 -0
- {edx-enterprise-subsidy-client-0.4.2 → edx-enterprise-subsidy-client-0.4.3}/edx_enterprise_subsidy_client.egg-info/dependency_links.txt +0 -0
- {edx-enterprise-subsidy-client-0.4.2 → edx-enterprise-subsidy-client-0.4.3}/edx_enterprise_subsidy_client.egg-info/not-zip-safe +0 -0
- {edx-enterprise-subsidy-client-0.4.2 → edx-enterprise-subsidy-client-0.4.3}/edx_enterprise_subsidy_client.egg-info/requires.txt +0 -0
- {edx-enterprise-subsidy-client-0.4.2 → edx-enterprise-subsidy-client-0.4.3}/edx_enterprise_subsidy_client.egg-info/top_level.txt +0 -0
- {edx-enterprise-subsidy-client-0.4.2 → edx-enterprise-subsidy-client-0.4.3}/requirements/base.in +0 -0
- {edx-enterprise-subsidy-client-0.4.2 → edx-enterprise-subsidy-client-0.4.3}/requirements/constraints.txt +0 -0
- {edx-enterprise-subsidy-client-0.4.2 → edx-enterprise-subsidy-client-0.4.3}/setup.cfg +0 -0
- {edx-enterprise-subsidy-client-0.4.2 → edx-enterprise-subsidy-client-0.4.3}/setup.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: edx-enterprise-subsidy-client
|
|
3
|
-
Version: 0.4.
|
|
3
|
+
Version: 0.4.3
|
|
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.3]
|
|
229
|
+
*******
|
|
230
|
+
* feat: adding new subsidy client method to fetch subsidy aggregate data
|
|
231
|
+
|
|
228
232
|
[0.4.2]
|
|
229
233
|
*******
|
|
230
234
|
* Switch from ``edx-sphinx-theme`` to ``sphinx-book-theme`` since the former is
|
|
@@ -73,6 +73,41 @@ class EnterpriseSubsidyAPIClient:
|
|
|
73
73
|
settings.BACKEND_SERVICE_EDX_OAUTH2_SECRET,
|
|
74
74
|
)
|
|
75
75
|
|
|
76
|
+
def get_subsidy_aggregates_by_learner_url(self, subsidy_uuid):
|
|
77
|
+
"""
|
|
78
|
+
Helper method to fetch subsidy learner aggregate data API url.
|
|
79
|
+
"""
|
|
80
|
+
return f"{self.SUBSIDIES_ENDPOINT}{subsidy_uuid}/aggregates-by-learner"
|
|
81
|
+
|
|
82
|
+
def get_subsidy_aggregates_by_learner_data(self, subsidy_uuid, policy_uuid=None):
|
|
83
|
+
"""
|
|
84
|
+
Client method to fetch subsidy specific learner aggregate data.
|
|
85
|
+
|
|
86
|
+
Args:
|
|
87
|
+
subsidy_uuid (str): Subsidy record UUID
|
|
88
|
+
policy_uuid (string): Optional param to filter subsidy aggregate data by subsidy access policy UUID
|
|
89
|
+
Returns:
|
|
90
|
+
json subsidy learner aggregate data response:
|
|
91
|
+
[{
|
|
92
|
+
'lms_user_id': '1337',
|
|
93
|
+
'enrollment_count': 45,
|
|
94
|
+
} ... ]
|
|
95
|
+
"""
|
|
96
|
+
url = self.get_subsidy_aggregates_by_learner_url(subsidy_uuid)
|
|
97
|
+
if policy_uuid:
|
|
98
|
+
url += f"?subsidy_access_policy_uuid={policy_uuid}"
|
|
99
|
+
try:
|
|
100
|
+
resp = self.client.get(url)
|
|
101
|
+
response_data = resp
|
|
102
|
+
resp.raise_for_status()
|
|
103
|
+
except requests.exceptions.HTTPError as exc:
|
|
104
|
+
logger.exception(
|
|
105
|
+
f'Subsidy client failed to fetch aggregate data for {subsidy_uuid} '
|
|
106
|
+
f'and policy: {policy_uuid}'
|
|
107
|
+
)
|
|
108
|
+
raise exc
|
|
109
|
+
return response_data.json()
|
|
110
|
+
|
|
76
111
|
def get_content_metadata_url(self, content_identifier):
|
|
77
112
|
"""Helper method to generate the subsidy service metadata API url, with a trailing slash."""
|
|
78
113
|
return self.CONTENT_METADATA_ENDPOINT + content_identifier + '/'
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: edx-enterprise-subsidy-client
|
|
3
|
-
Version: 0.4.
|
|
3
|
+
Version: 0.4.3
|
|
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.3]
|
|
229
|
+
*******
|
|
230
|
+
* feat: adding new subsidy client method to fetch subsidy aggregate data
|
|
231
|
+
|
|
228
232
|
[0.4.2]
|
|
229
233
|
*******
|
|
230
234
|
* Switch from ``edx-sphinx-theme`` to ``sphinx-book-theme`` since the former is
|
{edx-enterprise-subsidy-client-0.4.2 → edx-enterprise-subsidy-client-0.4.3}/tests/test_client.py
RENAMED
|
@@ -4,6 +4,9 @@ Tests for edx_enterprise_subsidy_client.py.
|
|
|
4
4
|
import uuid
|
|
5
5
|
from unittest import mock
|
|
6
6
|
|
|
7
|
+
import requests
|
|
8
|
+
from pytest import raises
|
|
9
|
+
|
|
7
10
|
from edx_enterprise_subsidy_client import EnterpriseSubsidyAPIClient, EnterpriseSubsidyAPIClientV2
|
|
8
11
|
from test_utils.utils import MockResponse
|
|
9
12
|
|
|
@@ -16,6 +19,40 @@ def test_client_init():
|
|
|
16
19
|
assert subsidy_client is not None
|
|
17
20
|
|
|
18
21
|
|
|
22
|
+
@mock.patch('edx_enterprise_subsidy_client.client.OAuthAPIClient', return_value=mock.MagicMock())
|
|
23
|
+
def test_client_fetch_subsidy_aggregate_data_success(mock_oauth_client):
|
|
24
|
+
"""
|
|
25
|
+
Test the client's ability to handle api requests to fetch subsidy learner aggregate data from the subsidy service
|
|
26
|
+
"""
|
|
27
|
+
mocked_data = {
|
|
28
|
+
'lms_user_id': '1337',
|
|
29
|
+
'enrollment_count': 10,
|
|
30
|
+
}
|
|
31
|
+
mock_oauth_client.return_value.get.return_value = MockResponse(mocked_data, 200)
|
|
32
|
+
subsidy_service_client = EnterpriseSubsidyAPIClient()
|
|
33
|
+
response = subsidy_service_client.get_subsidy_aggregates_by_learner_data(
|
|
34
|
+
subsidy_uuid=str(uuid.uuid4()),
|
|
35
|
+
)
|
|
36
|
+
assert response == mocked_data
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
@mock.patch('edx_enterprise_subsidy_client.client.OAuthAPIClient', return_value=mock.MagicMock())
|
|
40
|
+
def test_client_fetch_subsidy_aggregate_data_exception_handling(mock_oauth_client):
|
|
41
|
+
"""
|
|
42
|
+
Test the client's ability to properly throw errors when the subsidy service returns an error response.
|
|
43
|
+
"""
|
|
44
|
+
error_message = 'some_error_string'
|
|
45
|
+
mock_oauth_client.return_value.get.return_value = MockResponse(error_message, 400)
|
|
46
|
+
subsidy_service_client = EnterpriseSubsidyAPIClient()
|
|
47
|
+
with raises(requests.exceptions.HTTPError) as exc:
|
|
48
|
+
subsidy_service_client.get_subsidy_aggregates_by_learner_data(
|
|
49
|
+
subsidy_uuid=str(uuid.uuid4()),
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
assert exc.value.response.json() == error_message
|
|
53
|
+
assert exc.value.response.status_code == 400
|
|
54
|
+
|
|
55
|
+
|
|
19
56
|
@mock.patch('edx_enterprise_subsidy_client.client.OAuthAPIClient', return_value=mock.MagicMock())
|
|
20
57
|
def test_client_fetch_subsidy_content_data_success(mock_oauth_client):
|
|
21
58
|
"""
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{edx-enterprise-subsidy-client-0.4.2 → edx-enterprise-subsidy-client-0.4.3}/requirements/base.in
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|