Files
edx-platform/common/test/acceptance/fixtures/catalog.py
Renzo Lucioni 37523939f2 Retrieve marketable MicroMasters from the catalog service
Catalog-based MicroMasters need to be displayed in the LMS. However, the LMS currently retrieves all program data from the soon-to-be-retired programs service. Consuming program data exclusively from the catalog service is out of the question right now; it's too complex to confidently pull off in a week. This is a functional middle ground introduced by ECOM-5460. Cleaning up this debt is tracked by ECOM-4418.
2016-09-07 17:44:54 -04:00

44 lines
1.4 KiB
Python

"""
Tools to create catalog-related data for use in bok choy tests.
"""
import json
import requests
from common.test.acceptance.fixtures import CATALOG_STUB_URL
from common.test.acceptance.fixtures.config import ConfigModelFixture
class CatalogFixture(object):
"""
Interface to set up mock responses from the Catalog stub server.
"""
def install_programs(self, programs):
"""Set response data for the catalog's course run API."""
key = 'catalog.programs'
requests.put(
'{}/set_config'.format(CATALOG_STUB_URL),
data={key: json.dumps(programs)},
)
def install_course_run(self, course_run):
"""Set response data for the catalog's course run API."""
key = 'catalog.{}'.format(course_run['key'])
requests.put(
'{}/set_config'.format(CATALOG_STUB_URL),
data={key: json.dumps(course_run)},
)
class CatalogConfigMixin(object):
"""Mixin providing a method used to configure the catalog integration."""
def set_catalog_configuration(self, is_enabled=False, service_url=CATALOG_STUB_URL):
"""Dynamically adjusts the catalog config model during tests."""
ConfigModelFixture('/config/catalog', {
'enabled': is_enabled,
'internal_api_url': '{}/api/v1/'.format(service_url),
'cache_ttl': 0,
}).install()