def test_handler_sets_consent_and_sends_message(self):
        self.assertFalse(config.is_consent_set())
        xsrf_token = crypto.XsrfTokenManager.create_xsrf_token(self.XSRF_TOKEN)

        response = self.do_post(xsrf_token, True)
        self.assertTrue(config.is_consent_set())
        self.assertTrue(config.REPORT_ALLOWED.value)

        response = self.do_post(xsrf_token, False)
        self.assertFalse(config.REPORT_ALLOWED.value)

        expected = [{
            messaging.Message._INSTALLATION: FAKE_INSTALLATION_ID,
            messaging.Message._TIMESTAMP: FAKE_TIMESTAMP,
            messaging.Message._VERSION: os.environ['GCB_PRODUCT_VERSION'],
            messaging.Message._METRIC: messaging.Message.METRIC_REPORT_ALLOWED,
            messaging.Message._VALUE: True,
            messaging.Message._SOURCE: messaging.Message.BANNER_SOURCE,
        }, {
            messaging.Message._INSTALLATION: FAKE_INSTALLATION_ID,
            messaging.Message._TIMESTAMP: FAKE_TIMESTAMP,
            messaging.Message._VERSION: os.environ['GCB_PRODUCT_VERSION'],
            messaging.Message._METRIC: messaging.Message.METRIC_REPORT_ALLOWED,
            messaging.Message._VALUE: False,
            messaging.Message._SOURCE: messaging.Message.BANNER_SOURCE,
        }]
        self.assertEquals(expected, MockSender.get_sent())
Esempio n. 2
0
    def test_handler_sets_consent_and_sends_message(self):
        self.assertFalse(config.is_consent_set())
        xsrf_token = crypto.XsrfTokenManager.create_xsrf_token(self.XSRF_TOKEN)

        response = self.do_post(xsrf_token, True)
        self.assertTrue(config.is_consent_set())
        self.assertTrue(config.REPORT_ALLOWED.value)

        response = self.do_post(xsrf_token, False)
        self.assertFalse(config.REPORT_ALLOWED.value)

        expected = [{
            messaging.Message._INSTALLATION: FAKE_INSTALLATION_ID,
            messaging.Message._TIMESTAMP: FAKE_TIMESTAMP,
            messaging.Message._VERSION: os.environ['GCB_PRODUCT_VERSION'],
            messaging.Message._METRIC: messaging.Message.METRIC_REPORT_ALLOWED,
            messaging.Message._VALUE: True,
            messaging.Message._SOURCE: messaging.Message.BANNER_SOURCE,
        }, {
            messaging.Message._INSTALLATION: FAKE_INSTALLATION_ID,
            messaging.Message._TIMESTAMP: FAKE_TIMESTAMP,
            messaging.Message._VERSION: os.environ['GCB_PRODUCT_VERSION'],
            messaging.Message._METRIC: messaging.Message.METRIC_REPORT_ALLOWED,
            messaging.Message._VALUE: False,
            messaging.Message._SOURCE: messaging.Message.BANNER_SOURCE,
        }]
        self.assertEquals(expected, MockSender.get_sent())
Esempio n. 3
0
def _make_welcome_form_content():
    """Add content to welcome page to get user's consent for stat collection."""
    if messaging.is_disabled():
        return None

    checkbox = safe_dom.Element(
        'input'
    ).set_attribute(
        'type', 'checkbox'
    ).set_attribute(
        'name', USAGE_REPORTING_CONSENT_CHECKBOX_NAME
    ).set_attribute(
        'value', USAGE_REPORTING_CONSENT_CHECKBOX_VALUE
    )
    if config.REPORT_ALLOWED.value or not config.is_consent_set():
        checkbox.set_attribute('checked', 'checked')

    return safe_dom.Element(
        'div'
        ).set_attribute(
            'style', 'width: 60%; margin: 0 auto; '
        ).append(
            safe_dom.Element(
                'div'
                ).set_attribute(
                    'style', 'float: left; width: 10%; '
                ).add_child(checkbox)
        ).append(
            safe_dom.Element(
                'div'
                ).set_attribute(
                    'style', 'float: left; width: 90%; text-align: left'
                ).add_text(
                    'I agree that Google may collect information about this '
                    'deployment of Course Builder to help improve Google\'s '
                    'products and services and for research purposes.  '
                    'Google will maintain this data in acccordance with '
                ).add_child(
                    safe_dom.A(
                        'http://www.google.com/policies/privacy/'
                        ).add_text(
                            'Google\'s privacy policy'
                        )
                ).add_text(
                    ' and will not associate the data it collects with '
                    'this course or a user.  Your response to this question '
                    'will be sent to Google.'
                )
        ).append(
            safe_dom.Element(
                'div'
                ).set_attribute(
                    'style', 'clear: both; '
                )
        )
def _make_consent_banner(handler):
    if config.is_consent_set() or messaging.is_disabled():
        return None

    template_values = {
        'xsrf_token': handler.create_xsrf_token(
            ConsentBannerRestHandler.XSRF_TOKEN),
        'is_super_admin': roles.Roles.is_super_admin()
    }
    return jinja2.Markup(
        handler.get_template('consent_banner.html', [TEMPLATES_DIR]
    ).render(template_values))
Esempio n. 5
0
def _make_consent_banner(handler):
    if config.is_consent_set() or messaging.is_disabled():
        return None

    template_values = {
        'xsrf_token':
        handler.create_xsrf_token(ConsentBannerRestHandler.XSRF_TOKEN),
        'is_super_admin':
        roles.Roles.is_super_admin()
    }
    return jinja2.Markup(
        handler.get_template('consent_banner.html',
                             [TEMPLATES_DIR]).render(template_values))
Esempio n. 6
0
def _make_welcome_form_content():
    """Add content to welcome page to get user's consent for stat collection."""
    if messaging.is_disabled():
        return None

    checked = config.REPORT_ALLOWED.value or not config.is_consent_set()

    return jinja2.Markup(
        jinja_utils.get_template(
            'course_creation.html', [constants.TEMPLATES_DIR]).render(
        name=USAGE_REPORTING_CONSENT_CHECKBOX_NAME,
        value=USAGE_REPORTING_CONSENT_CHECKBOX_VALUE,
        checked=checked))