Skip to content

Commit

Permalink
feat: add enterprise_groups to project apps (#479)
Browse files Browse the repository at this point in the history
* feat: add enterprise_groups to project apps
  • Loading branch information
katrinan029 authored Jun 5, 2024
1 parent 61f5180 commit 7a77948
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 4 deletions.
13 changes: 13 additions & 0 deletions enterprise_access/apps/api_client/enterprise_catalog_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,16 @@ def catalog_content_metadata(self, catalog_uuid, content_keys, traverse_paginati
response = self.client.get(endpoint, params=query_params)
response.raise_for_status()
return response.json()

def get_content_metadata_count(self, catalog_uuid):
"""
Returns the count of content metadata for a catalog.
Arguments:
catalog_uuid (UUID): UUID of the enterprise catalog to check.
Returns:
The number of content metadata for a catalog.
"""
endpoint = self.enterprise_catalog_endpoint + str(catalog_uuid) + '/get_content_metadata/'
response = self.client.get(endpoint)
response.raise_for_status()
return response.json()['count']
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,21 @@ def test_catalog_content_metadata_raises_http_error(self, mock_oauth_client):
'traverse_pagination': True,
},
)

@mock.patch('enterprise_access.apps.api_client.base_oauth.OAuthAPIClient')
def test_get_content_metadata_count(self, mock_oauth_client):
mock_response_json = {
'count': 2
}
request_response = Response()
request_response.status_code = 200
mock_oauth_client.return_value.get.return_value.json.return_value = mock_response_json

catalog_uuid = uuid4()
client = EnterpriseCatalogApiClient()
fetched_metadata = client.get_content_metadata_count(catalog_uuid)

self.assertEqual(fetched_metadata, mock_response_json['count'])
mock_oauth_client.return_value.get.assert_called_with(
f'http://enterprise-catalog.example.com/api/v1/enterprise-catalogs/{catalog_uuid}/get_content_metadata/',
)
Empty file.
4 changes: 4 additions & 0 deletions enterprise_access/apps/enterprise_groups/constants.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
"""
Constants for the enterprise_groups app.
"""

DAYS_TO_PURGE_PII = 90

BRAZE_GROUPS_EMAIL_CAMPAIGNS_FIRST_REMINDER_DAY = 5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ def handle(self, *args, **options):
policy_group_association.subsidy_access_policy.subsidy_expiration_datetime
)
catalog_uuid = policy_group_association.subsidy_access_policy.catalog_uuid
catalog_count = enterprise_catalog_client.catalog_content_metadata(
catalog_count = enterprise_catalog_client.get_content_metadata_count(
catalog_uuid
)['count']
)

for pending_enterprise_customer_user in pending_enterprise_customer_users:
pending_enterprise_customer_user["subsidy_expiration_datetime"] = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def test_email_groups_command(
"user_email": "[email protected]",
},
]
mock_enterprise_catalog_client().catalog_content_metadata.return_value = {
mock_enterprise_catalog_client().get_content_metadata_count.return_value = {
'count': 5
}
mock_lms_api_client().get_pending_enterprise_group_memberships.return_value = (
Expand Down
2 changes: 1 addition & 1 deletion enterprise_access/apps/enterprise_groups/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def send_group_reminder_emails(pending_enterprise_users):
pending_enterprise_user["catalog_count"],
pending_enterprise_user["subsidy_expiration_datetime"],
)

logger.info(f'Sending braze campaign group reminder email to {recipient}.')
braze_client_instance.send_campaign_message(
braze_properties["braze_campaign_id"],
recipients=[recipient],
Expand Down
1 change: 1 addition & 0 deletions enterprise_access/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def root(*path_fragments):
'enterprise_access.apps.events',
'enterprise_access.apps.subsidy_access_policy',
'enterprise_access.apps.content_assignments',
'enterprise_access.apps.enterprise_groups',
)

INSTALLED_APPS += THIRD_PARTY_APPS
Expand Down

0 comments on commit 7a77948

Please sign in to comment.