edx-enterprise-data 4.11.0__py3-none-any.whl → 4.11.2__py3-none-any.whl

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: edx-enterprise-data
3
- Version: 4.11.0
3
+ Version: 4.11.2
4
4
  Summary: Enterprise Reporting
5
5
  Home-page: https://github.com/openedx/edx-enterprise-data
6
6
  Author: edX
@@ -1,4 +1,4 @@
1
- enterprise_data/__init__.py,sha256=XMnYGYr99mjy4phtEjdvNGwWnbj1RGK7THtFf9jKmXk,225
1
+ enterprise_data/__init__.py,sha256=J1F3IYlsZp1T2MWENx0TWqIMpbl86OmjO6nUtuZqyWs,225
2
2
  enterprise_data/apps.py,sha256=aF6hZwDfI2oWj95tUTm_2ikHueQj-jLj-u0GrgzpsQI,414
3
3
  enterprise_data/clients.py,sha256=GvQupy5TVYfO_IKC3yzXSAgNP54r-PtIjidM5ws9Iks,3947
4
4
  enterprise_data/constants.py,sha256=pS65L4mimz7hd_cLml_mXdU0GJ7hs0X8UQ8MNjC5hCU,234
@@ -17,7 +17,7 @@ enterprise_data/api/v0/views.py,sha256=4RslZ4NZOU-844bnebEQ71ji2utRY7jEijqC45oQQ
17
17
  enterprise_data/api/v1/__init__.py,sha256=4MKmD0y8ANRoaNzSYTwPFVCSfeid_bdzHCHnhR37MIs,144
18
18
  enterprise_data/api/v1/serializers.py,sha256=iLkuaXLRaRkfVyXch__IKXA3OIUH63QUNNGpXOjWPTk,6674
19
19
  enterprise_data/api/v1/urls.py,sha256=Vev34sBjvDSqGUuQQGTu-1ft-ISYUPO_GTOpx0RTiEA,1106
20
- enterprise_data/api/v1/views.py,sha256=pUk3xBWzjhgKzIO7VNL2XkDScghjNRKEUXgwH2MmnY4,20302
20
+ enterprise_data/api/v1/views.py,sha256=a5aIoIXoEExHX91440TUqzI-7EO-S0_-I5ZIU7GjH0c,21398
21
21
  enterprise_data/fixtures/enterprise_enrollment.json,sha256=6onPXXR29pMdTdbl_mn81sDi3Re5jkLUZz2TPMB_1IY,5786
22
22
  enterprise_data/fixtures/enterprise_user.json,sha256=6g8GvNY9j_fh1dvAU80bTAMI2F5vXCkb8a4UjsftMvQ,1970
23
23
  enterprise_data/management/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -85,7 +85,7 @@ enterprise_data/tests/api/v0/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NM
85
85
  enterprise_data/tests/api/v0/test_serializers.py,sha256=Gfty6gy6OQLN318uL1OCPhAZOqSUL50FWc0nC23VMnc,6257
86
86
  enterprise_data/tests/api/v1/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
87
87
  enterprise_data/tests/api/v1/test_serializers.py,sha256=DwgEHcyOP3oqNUPB2O-NkJGeO_cYs9XJiq7791vJLZE,3682
88
- enterprise_data/tests/api/v1/test_views.py,sha256=sGuCyPEHkUWEumXHJrLzVKIynZqzIZ-xdOPnAIUab7g,12795
88
+ enterprise_data/tests/api/v1/test_views.py,sha256=_ex_Cn_aXN3UA3QboHCUnrwPNd3ZSF6nt_lnHPuYrH0,15158
89
89
  enterprise_data_roles/__init__.py,sha256=toCpbypm2uDoWVw29_em9gPFNly8vNUS__C0b4TCqEg,112
90
90
  enterprise_data_roles/admin.py,sha256=QNP0VeWE092vZzpyxOA5UJK1nNGl5e71B1J0RCwo_nU,998
91
91
  enterprise_data_roles/apps.py,sha256=nKi8TyuQ5Q6WGtKs5QeXvUTc3N-YQjKhyBnm2EM3Bng,260
@@ -126,8 +126,8 @@ enterprise_reporting/tests/test_send_enterprise_reports.py,sha256=WtL-RqGgu2x5PP
126
126
  enterprise_reporting/tests/test_utils.py,sha256=7Y5GmeibiC8Q5kIpYuIAkFpeyIDRs2U3ItxsabhR1zM,9493
127
127
  enterprise_reporting/tests/test_vertica_client.py,sha256=-R2yNCGUjRtoXwLMBloVFQkFYrJoo613VCr61gwI3kQ,140
128
128
  enterprise_reporting/tests/utils.py,sha256=xms2LM7DV3wczXEfctOK1ddel1EE0J_YSr17UzbCDy4,1401
129
- edx_enterprise_data-4.11.0.dist-info/LICENSE,sha256=dql8h4yceoMhuzlcK0TT_i-NgTFNIZsgE47Q4t3dUYI,34520
130
- edx_enterprise_data-4.11.0.dist-info/METADATA,sha256=qCLFr5Ej1f1jVH5U9QNerZYYUCwNe8kx7Hyv884kScY,1490
131
- edx_enterprise_data-4.11.0.dist-info/WHEEL,sha256=pkctZYzUS4AYVn6dJ-7367OJZivF2e8RA9b_ZBjif18,92
132
- edx_enterprise_data-4.11.0.dist-info/top_level.txt,sha256=f5F2kU-dob6MqiHJpgZkFzoCD5VMhsdpkTV5n9Tvq3I,59
133
- edx_enterprise_data-4.11.0.dist-info/RECORD,,
129
+ edx_enterprise_data-4.11.2.dist-info/LICENSE,sha256=dql8h4yceoMhuzlcK0TT_i-NgTFNIZsgE47Q4t3dUYI,34520
130
+ edx_enterprise_data-4.11.2.dist-info/METADATA,sha256=mRAQGn1w8rYH-R8ZvH1dN1W5YJtksGkB5qen-w2ZD04,1490
131
+ edx_enterprise_data-4.11.2.dist-info/WHEEL,sha256=pkctZYzUS4AYVn6dJ-7367OJZivF2e8RA9b_ZBjif18,92
132
+ edx_enterprise_data-4.11.2.dist-info/top_level.txt,sha256=f5F2kU-dob6MqiHJpgZkFzoCD5VMhsdpkTV5n9Tvq3I,59
133
+ edx_enterprise_data-4.11.2.dist-info/RECORD,,
@@ -2,6 +2,6 @@
2
2
  Enterprise data api application. This Django app exposes API endpoints used by enterprises.
3
3
  """
4
4
 
5
- __version__ = "4.11.0"
5
+ __version__ = "4.11.2"
6
6
 
7
7
  default_app_config = "enterprise_data.apps.EnterpriseDataAppConfig" # pylint: disable=invalid-name
@@ -2,9 +2,9 @@
2
2
  Views for enterprise api v1.
3
3
  """
4
4
 
5
-
6
5
  from datetime import date, timedelta
7
6
  from logging import getLogger
7
+ from uuid import UUID
8
8
 
9
9
  from django_filters.rest_framework import DjangoFilterBackend
10
10
  from edx_django_utils.cache import TieredCache
@@ -166,7 +166,12 @@ class EnterpriseLearnerEnrollmentViewSet(EnterpriseViewSetMixin, viewsets.ReadOn
166
166
  search_email = query_filters.get('search')
167
167
  if search_email:
168
168
  queryset = queryset.filter(user_email__icontains=search_email)
169
-
169
+ search_all_param = query_filters.get('search_all')
170
+ if search_all_param:
171
+ queryset = queryset.filter(
172
+ Q(user_email__icontains=search_all_param)
173
+ | Q(course_title__icontains=search_all_param)
174
+ )
170
175
  search_course = query_filters.get('search_course')
171
176
  if search_course:
172
177
  queryset = queryset.filter(course_title__icontains=search_course)
@@ -176,7 +181,7 @@ class EnterpriseLearnerEnrollmentViewSet(EnterpriseViewSetMixin, viewsets.ReadOn
176
181
 
177
182
  offer_id = query_filters.get('offer_id')
178
183
  if offer_id:
179
- queryset = queryset.filter(offer_id=offer_id)
184
+ queryset = self.filter_by_offer_id(queryset, offer_id)
180
185
 
181
186
  ignore_null_course_list_price = query_filters.get('ignore_null_course_list_price')
182
187
  if ignore_null_course_list_price:
@@ -192,6 +197,27 @@ class EnterpriseLearnerEnrollmentViewSet(EnterpriseViewSetMixin, viewsets.ReadOn
192
197
 
193
198
  return queryset
194
199
 
200
+ def filter_by_offer_id(self, queryset, offer_id):
201
+ """
202
+ Filter queryset by `offer_id`
203
+ """
204
+ # offer_id field in table contains two types of data
205
+ # 1. integer
206
+ # 2. uuid
207
+ # In table, uuids are stored without hyphen and in lower case
208
+ # but api clients are sending uuids with hyphen and that causes the issue
209
+ # we need to remove the hyphens from uuid, convert the uuid to lower case and then do a compare in DB
210
+
211
+ # if offer_id is a uuid only then do the transformation
212
+ try:
213
+ offer_id_uuid_obj = UUID(offer_id, version=4)
214
+ offer_id = str(offer_id_uuid_obj)
215
+ offer_id = offer_id.replace('-', '')
216
+ except ValueError:
217
+ pass
218
+
219
+ return queryset.filter(offer_id=offer_id)
220
+
195
221
  def filter_active_enrollments(self, queryset):
196
222
  """
197
223
  Filters queryset to include enrollments with course date in future
@@ -160,6 +160,56 @@ class TestEnterpriseLearnerEnrollmentViewSet(JWTTestMixin, APITransactionTestCas
160
160
  self.assertEqual(len(results), 1)
161
161
  self.assertEqual(results[0]['enrollment_id'], learner_enrollment_subsidized.enrollment_id)
162
162
 
163
+ def test_search_by_course_title(self):
164
+ """Test that the course title search works correctly"""
165
+ enterprise_learner = EnterpriseLearnerFactory(
166
+ enterprise_customer_uuid=self.enterprise_id
167
+ )
168
+ course_titles = ['Introduction to Python', 'Introduction to Java', 'Introduction to C++']
169
+
170
+ for title in course_titles:
171
+ EnterpriseLearnerEnrollmentFactory(
172
+ enterprise_customer_uuid=self.enterprise_id,
173
+ is_consent_granted=True,
174
+ enterprise_user_id=enterprise_learner.enterprise_user_id,
175
+ course_title=title,
176
+ )
177
+
178
+ url = reverse('v1:enterprise-learner-enrollment-list', kwargs={'enterprise_id': self.enterprise_id})
179
+ response = self.client.get(url, data={'search_all': 'Introduction to'})
180
+ results = response.json()['results']
181
+ self.assertEqual(len(results), 3)
182
+
183
+ def test_search_by_email(self):
184
+ """Test that the email search works correctly"""
185
+ enterprise_learner = EnterpriseLearnerFactory(
186
+ enterprise_customer_uuid=self.enterprise_id,
187
+ user_email="johndoe@example.com"
188
+ )
189
+ EnterpriseLearnerEnrollmentFactory(
190
+ enterprise_customer_uuid=self.enterprise_id,
191
+ is_consent_granted=True,
192
+ enterprise_user_id=enterprise_learner.enterprise_user_id,
193
+ course_title="Sample course",
194
+ user_email="johndoe@example.com"
195
+ )
196
+ url = reverse('v1:enterprise-learner-enrollment-list', kwargs={'enterprise_id': self.enterprise_id})
197
+ response = self.client.get(url, data={'search_all': 'john'})
198
+ results = response.json()['results']
199
+ self.assertEqual(len(results), 1)
200
+
201
+ def test_search_no_results(self):
202
+ """Test that the search returns no results if no matches are found"""
203
+ EnterpriseLearnerFactory(
204
+ enterprise_customer_uuid=self.enterprise_id,
205
+ user_email="test@example.com"
206
+ )
207
+ search_term = 'nonexistentemail@example.com'
208
+ url = reverse('v1:enterprise-learner-enrollment-list', kwargs={'enterprise_id': self.enterprise_id})
209
+ response = self.client.get(url, data={'search_all': search_term})
210
+ self.assertEqual(response.status_code, status.HTTP_200_OK)
211
+ self.assertEqual(response.json()['count'], 0)
212
+
163
213
 
164
214
  @ddt.ddt
165
215
  @mark.django_db