def test_program_exists_no_exception(self, response):
     """
     The client should return the appropriate boolean value for program existence depending on the response.
     """
     self.get_data_mock.return_value = response
     assert CourseCatalogApiServiceClient.program_exists('a-s-d-f') == bool(
         response)
Пример #2
0
    def get_course_duration(self, obj):
        """
        Get course's duration as a timedelta.

        Arguments:
            obj (CourseOverview): CourseOverview object

        Returns:
            (timedelta): Duration of a course.
        """
        course_run = None
        duration = None
        site = self.context.get('site')
        if site:
            cache_key = get_cache_key(course_id=obj.id, site=site)
            cached_response = TieredCache.get_cached_response(cache_key)
            if cached_response.is_found:
                course_run = cached_response.value
            else:
                try:
                    _, course_run = CourseCatalogApiServiceClient(site).get_course_and_course_run(str(obj.id))
                    TieredCache.set_all_tiers(cache_key, course_run, CACHE_TIMEOUT)
                except ImproperlyConfigured:
                    LOGGER.warning('CourseCatalogApiServiceClient is improperly configured.')
        if course_run and course_run.get('max_effort') and course_run.get('weeks_to_complete'):
            duration = '{effort} hours per week for {weeks} weeks.'.format(
                effort=course_run['max_effort'],
                weeks=course_run['weeks_to_complete']
            )
        return duration or ''
Пример #3
0
def get_program_data_sharing_consent(username, program_uuid,
                                     enterprise_customer_uuid):
    """
    Get the data sharing consent object associated with a certain user of a customer for a program.

    :param username: The user that grants consent.
    :param program_uuid: The program for which consent is granted.
    :param enterprise_customer_uuid: The consent requester.
    :return: The data sharing consent object
    """
    enterprise_customer = get_enterprise_customer(enterprise_customer_uuid)
    discovery_client = CourseCatalogApiServiceClient(enterprise_customer.site)
    course_ids = discovery_client.get_program_course_keys(program_uuid)
    child_consents = (get_data_sharing_consent(username,
                                               enterprise_customer_uuid,
                                               course_id=individual_course_id)
                      for individual_course_id in course_ids)
    return ProxyDataSharingConsent.from_children(program_uuid, *child_consents)
Пример #4
0
 def setUp(self):
     """
     Set up mocks for the test suite.
     """
     super(TestCourseCatalogApiService, self).setUp()
     self.user_mock = mock.Mock(spec=User)
     self.get_data_mock = self._make_patch(self._make_catalog_api_location("get_edx_api_data"))
     self.jwt_builder_mock = self._make_patch(self._make_catalog_api_location("JwtBuilder"))
     self.integration_config_mock = mock.Mock(enabled=True)
     self.integration_config_mock.get_service_user.return_value = self.user_mock
     self.integration_mock = self._make_patch(self._make_catalog_api_location("CatalogIntegration"))
     self.integration_mock.current.return_value = self.integration_config_mock
     self.api = CourseCatalogApiServiceClient()
Пример #5
0
 def test_program_exists_with_exception(self):
     """
     The client should capture improper configuration for the class method and return False.
     """
     self.integration_mock.current.return_value.enabled = False
     assert not CourseCatalogApiServiceClient.program_exists('a-s-d-f')
Пример #6
0
 def test_success(self, mock_catalog_integration, *args):  # pylint: disable=unused-argument
     mock_integration_config = mock.Mock(enabled=True)
     mock_integration_config.get_service_user.return_value = mock.Mock(spec=User)
     mock_catalog_integration.current.return_value = mock_integration_config
     CourseCatalogApiServiceClient()
Пример #7
0
 def test_raise_error_object_does_not_exist(self, mock_catalog_integration):
     mock_integration_config = mock.Mock(enabled=True)
     mock_integration_config.get_service_user.side_effect = ObjectDoesNotExist
     mock_catalog_integration.current.return_value = mock_integration_config
     with self.assertRaises(ImproperlyConfigured):
         CourseCatalogApiServiceClient()
Пример #8
0
 def test_raise_error_catalog_integration_disabled(self, mock_catalog_integration):
     mock_catalog_integration.current.return_value = mock.Mock(enabled=False)
     with self.assertRaises(ImproperlyConfigured):
         CourseCatalogApiServiceClient()
Пример #9
0
 def test_raise_error_missing_catalog_integration(self, *args):  # pylint: disable=unused-argument
     with self.assertRaises(NotConnectedToOpenEdX):
         CourseCatalogApiServiceClient()