Skip to content

Commit

Permalink
feat: remove disused discovery cache
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnagro committed Oct 5, 2023
1 parent f0bb260 commit 98e5f5e
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 87 deletions.
4 changes: 1 addition & 3 deletions enterprise_catalog/apps/api/tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@

from enterprise_catalog.apps.api import tasks
from enterprise_catalog.apps.api.constants import CourseMode
from enterprise_catalog.apps.api_client.discovery_cache import (
CatalogQueryMetadata,
)
from enterprise_catalog.apps.api_client.discovery import CatalogQueryMetadata
from enterprise_catalog.apps.catalog.constants import (
COURSE,
COURSE_RUN,
Expand Down
41 changes: 41 additions & 0 deletions enterprise_catalog/apps/api_client/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,3 +238,44 @@ def get_programs(self, query_params=None):
)

return programs


class CatalogQueryMetadata:
"""
Metadata for a given CatalogQuery from the Discovery API.
Data is cached for 'settings.CATALOG_QUERY_CACHE_TIMEOUT' seconds.
"""
def __init__(self, catalog_query):
"""
Initialize a Catalog Query details instance and load data from
cache or by using the Discovery API client.
Arguments:
catalog_query (CatalogQuery): Catalog Query to retrieve metadata for
"""
self.catalog_query = catalog_query
self.catalog_query_data = self._get_catalog_query_metadata(catalog_query)

@property
def metadata(self):
"""
Return catalog query metadata (will be an empty dict if unavailable)
"""
return self.catalog_query_data

def _get_catalog_query_metadata(self, catalog_query):
"""
Retrieve JSON data containing Catalog Query metadata for the given catalog_query_id.
Making a call to Discovery API Client.
Arguments:
catalog_query (CatalogQuery): Catalog Query object
Returns:
customer_data (dict): Enterprise Customer details OR
Empty dictionary if no data found from API.
"""
client = DiscoveryApiClient()
catalog_query_data = client.get_metadata_by_query(catalog_query)
return catalog_query_data
77 changes: 0 additions & 77 deletions enterprise_catalog/apps/api_client/discovery_cache.py

This file was deleted.

4 changes: 1 addition & 3 deletions enterprise_catalog/apps/catalog/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@
get_most_recent_modified_time,
update_query_parameters,
)
from enterprise_catalog.apps.api_client.discovery_cache import (
CatalogQueryMetadata,
)
from enterprise_catalog.apps.api_client.discovery import CatalogQueryMetadata
from enterprise_catalog.apps.api_client.enterprise_cache import (
EnterpriseCustomerDetails,
)
Expand Down
8 changes: 4 additions & 4 deletions enterprise_catalog/apps/catalog/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def test_is_exec_ed_2u_course(self, content_type, course_type, expected_value):
self.assertEqual(content_metadata.is_exec_ed_2u_course, expected_value)

@override_settings(DISCOVERY_CATALOG_QUERY_CACHE_TIMEOUT=0)
@mock.patch('enterprise_catalog.apps.api_client.discovery_cache.DiscoveryApiClient')
@mock.patch('enterprise_catalog.apps.api_client.discovery.DiscoveryApiClient')
def test_2U_exec_ed_content_inclusion_logic(self, mock_client):
"""
Test that we exclude 2u exec ed courses from the create content metadata task unless the query provided allows
Expand Down Expand Up @@ -86,7 +86,7 @@ def test_2U_exec_ed_content_inclusion_logic(self, mock_client):
self.assertEqual(ContentMetadata.objects.count(), 3)

@override_settings(DISCOVERY_CATALOG_QUERY_CACHE_TIMEOUT=0)
@mock.patch('enterprise_catalog.apps.api_client.discovery_cache.DiscoveryApiClient')
@mock.patch('enterprise_catalog.apps.api_client.discovery.DiscoveryApiClient')
def test_product_source_content_inclusion_logic(self, mock_client):
"""
Test that we exclude 2u exec ed courses from the create content metadata task unless the query provided allows
Expand Down Expand Up @@ -133,7 +133,7 @@ def test_product_source_content_inclusion_logic(self, mock_client):
self.assertEqual(ContentMetadata.objects.count(), 3)

@override_settings(DISCOVERY_CATALOG_QUERY_CACHE_TIMEOUT=0)
@mock.patch('enterprise_catalog.apps.api_client.discovery_cache.DiscoveryApiClient')
@mock.patch('enterprise_catalog.apps.api_client.discovery.DiscoveryApiClient')
def test_contentmetadata_update_from_discovery(self, mock_client):
"""
update_contentmetadata_from_discovery should update or create ContentMetadata
Expand Down Expand Up @@ -219,7 +219,7 @@ def test_contentmetadata_update_from_discovery(self, mock_client):
assert program_cm in associated_metadata

@override_settings(DISCOVERY_CATALOG_QUERY_CACHE_TIMEOUT=0)
@mock.patch('enterprise_catalog.apps.api_client.discovery_cache.DiscoveryApiClient')
@mock.patch('enterprise_catalog.apps.api_client.discovery.DiscoveryApiClient')
def test_contentmetadata_update_from_discovery_ignore_exec_ed(self, mock_client):
"""
update_contentmetadata_from_discovery should update or create ContentMetadata
Expand Down

0 comments on commit 98e5f5e

Please sign in to comment.