Esempio n. 1
0
    def update_course_runs(self, course_runs, enterprise_customer, enterprise_context):
        """
        Update Marketing urls in course metadata and return updated course.

        Arguments:
            course_runs (list): List of course runs.
            enterprise_customer (EnterpriseCustomer): enterprise customer instance.
            enterprise_context (dict): The context to inject into URLs.

        Returns:
            (dict): Dictionary containing updated course metadata.
        """
        updated_course_runs = []
        for course_run in course_runs:
            track_selection_url = utils.get_course_track_selection_url(
                course_run=course_run,
                query_parameters=dict(enterprise_context, **utils.get_enterprise_utm_context(enterprise_customer)),
            )

            enrollment_url = enterprise_customer.get_course_run_enrollment_url(course_run.get('key'))

            course_run.update({
                'enrollment_url': enrollment_url,
                'track_selection_url': track_selection_url,
            })

            # Update marketing urls in course metadata to include enterprise related info.
            marketing_url = course_run.get('marketing_url')
            if marketing_url:
                query_parameters = dict(enterprise_context, **utils.get_enterprise_utm_context(enterprise_customer))
                course_run.update({'marketing_url': utils.update_query_parameters(marketing_url, query_parameters)})

            # Add updated course run to the list.
            updated_course_runs.append(course_run)
        return updated_course_runs
Esempio n. 2
0
    def update_course_runs(self, course_runs, catalog_id, enterprise_customer):
        """
        Update Marketing urls in course metadata adn return updated course.

        Arguments:
            course_runs (list): List of course runs.
            catalog_id (int): Course catalog identifier.
            enterprise_customer (EnterpriseCustomer): enterprise customer instance.

        Returns:
            (dict): Dictionary containing updated course metadata.
        """
        updated_course_runs = []

        query_parameters = {
            'tpa_hint': enterprise_customer
            and enterprise_customer.identity_provider,
            'enterprise_id': enterprise_customer and enterprise_customer.uuid,
            'catalog_id': catalog_id,
        }

        for course_run in course_runs:
            track_selection_url = utils.get_course_track_selection_url(
                course_run=course_run,
                query_parameters=query_parameters,
            )

            enrollment_url = enterprise_customer.get_course_enrollment_url(
                course_run.get('key'))

            # Add/update track selection url in course run metadata.
            course_run.update({
                'track_selection_url': track_selection_url,
                'enrollment_url': enrollment_url
            })

            # Update marketing urls in course metadata to include enterprise related info.
            if course_run.get('marketing_url'):
                course_run.update({
                    "marketing_url":
                    utils.update_query_parameters(
                        course_run.get('marketing_url'), query_parameters),
                })

            # Add updated course run to the list.
            updated_course_runs.append(course_run)

        return updated_course_runs
Esempio n. 3
0
    def test_get_course_track_selection_url(self, course_run, query_parameters,
                                            expected_url_parts):
        """
        Test `get_course_track_selection_url` helper method.
        """
        course_root = "course_modes/choose/{course_id}/".format(
            course_id=course_run.get('key', ''))

        with mock.patch('enterprise.utils.reverse', return_value=course_root):
            url = utils.get_course_track_selection_url(course_run,
                                                       query_parameters)

            # Make sure course run url returned by get_course_track_selection_url
            # contains all the expected url parts.
            # We can not assert whole urls because we can not determine the position of these query parameters.
            # e.g. `http://<base>?course=test-course&tpa_hint=test-shib` and
            # `http://<base>?tpa_hint=test-shib&course=test-course` are both same urls but different strings.
            for url_part in expected_url_parts:
                assert url_part in url
Esempio n. 4
0
 def test_get_course_track_selection_url_raises_exception(self):
     """
     Test `get_course_track_selection_url` raises exception for missing `key` in course run.
     """
     with raises(KeyError):
         utils.get_course_track_selection_url({}, {})