Commit 47cdf392 by asadiqbal

ENT-342

parent acbf8603
...@@ -29,12 +29,13 @@ from util.testing import UrlResetMixin ...@@ -29,12 +29,13 @@ from util.testing import UrlResetMixin
from openedx.core.djangoapps.theming.tests.test_util import with_comprehensive_theme from openedx.core.djangoapps.theming.tests.test_util import with_comprehensive_theme
from util.tests.mixins.discovery import CourseCatalogServiceMockMixin from util.tests.mixins.discovery import CourseCatalogServiceMockMixin
from util import organizations_helpers as organizations_api from util import organizations_helpers as organizations_api
from openedx.core.djangoapps.catalog.tests.mixins import CatalogIntegrationMixin
@attr(shard=3) @attr(shard=3)
@ddt.ddt @ddt.ddt
@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms') @unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms')
class CourseModeViewTest(UrlResetMixin, ModuleStoreTestCase, EnterpriseServiceMockMixin, CourseCatalogServiceMockMixin): class CourseModeViewTest(CatalogIntegrationMixin, UrlResetMixin, ModuleStoreTestCase, EnterpriseServiceMockMixin, CourseCatalogServiceMockMixin):
""" """
Course Mode View tests Course Mode View tests
""" """
...@@ -155,6 +156,9 @@ class CourseModeViewTest(UrlResetMixin, ModuleStoreTestCase, EnterpriseServiceMo ...@@ -155,6 +156,9 @@ class CourseModeViewTest(UrlResetMixin, ModuleStoreTestCase, EnterpriseServiceMo
for mode in ('audit', 'honor', 'verified'): for mode in ('audit', 'honor', 'verified'):
CourseModeFactory.create(mode_slug=mode, course_id=self.course.id) CourseModeFactory.create(mode_slug=mode, course_id=self.course.id)
catalog_integration = self.create_catalog_integration()
UserFactory(username=catalog_integration.service_username)
self.mock_enterprise_learner_api() self.mock_enterprise_learner_api()
self.mock_course_discovery_api_for_catalog_contains( self.mock_course_discovery_api_for_catalog_contains(
...@@ -185,6 +189,8 @@ class CourseModeViewTest(UrlResetMixin, ModuleStoreTestCase, EnterpriseServiceMo ...@@ -185,6 +189,8 @@ class CourseModeViewTest(UrlResetMixin, ModuleStoreTestCase, EnterpriseServiceMo
for mode in ('audit', 'honor', 'verified'): for mode in ('audit', 'honor', 'verified'):
CourseModeFactory.create(mode_slug=mode, course_id=self.course.id) CourseModeFactory.create(mode_slug=mode, course_id=self.course.id)
catalog_integration = self.create_catalog_integration()
UserFactory(username=catalog_integration.service_username)
self.mock_enterprise_learner_api() self.mock_enterprise_learner_api()
self.mock_course_discovery_api_for_catalog_contains( self.mock_course_discovery_api_for_catalog_contains(
catalog_id=1, course_run_ids=[str(self.course.id)] catalog_id=1, course_run_ids=[str(self.course.id)]
......
...@@ -159,7 +159,6 @@ class ChooseModeView(View): ...@@ -159,7 +159,6 @@ class ChooseModeView(View):
is_course_in_enterprise_catalog = enterprise_api.is_course_in_enterprise_catalog( is_course_in_enterprise_catalog = enterprise_api.is_course_in_enterprise_catalog(
site=request.site, site=request.site,
course_id=course_id, course_id=course_id,
user=request.user,
enterprise_catalog_id=enterprise_learner_data[0]['enterprise_customer']['catalog'] enterprise_catalog_id=enterprise_learner_data[0]['enterprise_customer']['catalog']
) )
......
...@@ -29,6 +29,7 @@ from requests.exceptions import ConnectionError, Timeout ...@@ -29,6 +29,7 @@ from requests.exceptions import ConnectionError, Timeout
from openedx.core.djangoapps.api_admin.utils import course_discovery_api_client from openedx.core.djangoapps.api_admin.utils import course_discovery_api_client
from openedx.core.lib.token_utils import JwtBuilder from openedx.core.lib.token_utils import JwtBuilder
from openedx.core.djangoapps.catalog.models import CatalogIntegration
CONSENT_FAILED_PARAMETER = 'consent_failed' CONSENT_FAILED_PARAMETER = 'consent_failed'
...@@ -455,7 +456,7 @@ def get_dashboard_consent_notification(request, user, course_enrollments): ...@@ -455,7 +456,7 @@ def get_dashboard_consent_notification(request, user, course_enrollments):
return '' return ''
def is_course_in_enterprise_catalog(site, course_id, user, enterprise_catalog_id): def is_course_in_enterprise_catalog(site, course_id, enterprise_catalog_id):
""" """
Verify that the provided course id exists in the site base list of course Verify that the provided course id exists in the site base list of course
run keys from the provided enterprise course catalog. run keys from the provided enterprise course catalog.
...@@ -477,6 +478,17 @@ def is_course_in_enterprise_catalog(site, course_id, user, enterprise_catalog_id ...@@ -477,6 +478,17 @@ def is_course_in_enterprise_catalog(site, course_id, user, enterprise_catalog_id
) )
response = cache.get(cache_key) response = cache.get(cache_key)
if not response: if not response:
catalog_integration = CatalogIntegration.current()
if not catalog_integration.enabled:
LOGGER.error("Catalog integration is not enabled.")
return False
try:
user = User.objects.get(username=catalog_integration.service_username)
except User.DoesNotExist:
LOGGER.exception("Catalog service user '%s' does not exist.", catalog_integration.service_username)
return False
try: try:
# GET: /api/v1/catalogs/{catalog_id}/contains?course_run_id={course_run_ids} # GET: /api/v1/catalogs/{catalog_id}/contains?course_run_id={course_run_ids}
response = course_discovery_api_client(user=user).catalogs(enterprise_catalog_id).contains.get( response = course_discovery_api_client(user=user).catalogs(enterprise_catalog_id).contains.get(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment