コード例 #1
0
 def test_post_course_specific_consent_bad_api_response(
         self, reverse_mock, *args):  # pylint: disable=unused-argument
     self._login()
     course_id = 'course-v1:does+not+exist'
     data_sharing_consent = True
     enterprise_customer = EnterpriseCustomerFactory(
         name='Starfleet Academy',
         enable_data_sharing_consent=True,
         enforce_data_sharing_consent='at_enrollment',
     )
     ecu = EnterpriseCustomerUserFactory(
         user_id=self.user.id, enterprise_customer=enterprise_customer)
     EnterpriseCourseEnrollment.objects.create(enterprise_customer_user=ecu,
                                               course_id=course_id)
     dsc = DataSharingConsentFactory(
         username=self.user.username,
         course_id=course_id,
         enterprise_customer=enterprise_customer,
         granted=False,
     )
     reverse_mock.return_value = '/dashboard'
     resp = self.client.post(
         self.url,
         data={
             'course_id': course_id,
             'data_sharing_consent': data_sharing_consent,
             'redirect_url': '/successful_enrollment',
             'enterprise_customer_uuid':
             'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa',
         },
     )
     assert resp.status_code == 404
     dsc.refresh_from_db()
     assert dsc.granted is False
コード例 #2
0
    def test_post_course_specific_consent(
            self, defer_creation, consent_provided, expected_redirect_url,
            course_id, license_uuid, reverse_mock,
            course_catalog_api_client_mock, enterprise_catalog_api_client_mock,
            mock_enrollment_api_client, *args):  # pylint: disable=unused-argument,invalid-name
        self._login()
        enterprise_customer = EnterpriseCustomerFactory(
            name='Starfleet Academy',
            enable_data_sharing_consent=True,
            enforce_data_sharing_consent='at_enrollment',
        )
        content_filter = {
            'key': [
                course_id,
            ]
        }
        EnterpriseCustomerCatalogFactory(
            enterprise_customer=enterprise_customer,
            content_filter=content_filter)
        ecu = EnterpriseCustomerUserFactory(
            user_id=self.user.id, enterprise_customer=enterprise_customer)
        enterprise_enrollment = EnterpriseCourseEnrollment.objects.create(
            enterprise_customer_user=ecu,
            course_id=course_id,
        )
        dsc = DataSharingConsentFactory(
            username=self.user.username,
            course_id=course_id,
            enterprise_customer=enterprise_customer,
            granted=consent_provided)

        course_catalog_api_client_mock.return_value.program_exists.return_value = True
        course_catalog_api_client_mock.return_value.get_course_id.return_value = 'edX+DemoX'

        mock_enterprise_catalog_api_client = enterprise_catalog_api_client_mock.return_value
        mock_enterprise_catalog_api_client.enterprise_contains_content_items.return_value = True

        reverse_mock.return_value = '/dashboard'
        course_mode = 'verified'
        mock_enrollment_api_client.return_value.get_course_modes.return_value = [
            course_mode
        ]
        post_data = {
            'enterprise_customer_uuid': enterprise_customer.uuid,
            'course_id': course_id,
            'redirect_url': '/successful_enrollment',
            'failure_url': '/failure_url',
        }
        if defer_creation:
            post_data['defer_creation'] = True
        if consent_provided:
            post_data['data_sharing_consent'] = consent_provided
        if license_uuid:
            post_data['license_uuid'] = license_uuid

        resp = self.client.post(self.url, post_data)

        assert resp.url.endswith(expected_redirect_url)  # pylint: disable=no-member
        assert resp.status_code == 302
        if not defer_creation:
            dsc.refresh_from_db()
            assert dsc.granted is consent_provided

        # we'll only create an enrollment record if (1) creation is not deferred, (2) consent has not been provided,
        # (3) we provide a license_uuid, and (4) we provide a course _run_ id
        if not defer_creation and not consent_provided and license_uuid and course_id.endswith(
                'Demo_Course'):
            assert LicensedEnterpriseCourseEnrollment.objects.filter(
                enterprise_course_enrollment=enterprise_enrollment,
                license_uuid=license_uuid,
            ).exists() is True

            mock_enrollment_api_client.return_value.enroll_user_in_course.assert_called_once_with(
                self.user.username, course_id, course_mode)

        if not license_uuid:
            assert not mock_enrollment_api_client.return_value.enroll_user_in_course.called