def test_not_from_cron_and_not_admin(self):
     config.set_report_allowed(True)
     actions.logout()
     response = self.get(usage_reporting.StartReportingJobs.URL,
                         expect_errors=True)
     self.assertEquals(403, response.status_int)
     self.assertEquals('Forbidden.', response.body)
    def test_jobs_run(self):
        COURSE = 'test'
        app_context = actions.simple_add_course(COURSE, ADMIN_EMAIL, 'Test')
        actions.register(self, 'Joe Admin', COURSE)
        config.set_report_allowed(True)
        response = self.get(usage_reporting.StartReportingJobs.URL,
                            headers={'X-AppEngine-Cron': 'True'})
        self.assertEquals(200, response.status_int)
        self.assertEquals('OK.', response.body)
        now = int(time.time())
        self.execute_all_deferred_tasks(
            models.StudentLifecycleObserver.QUEUE_NAME)
        self.execute_all_deferred_tasks()

        expected = [{
            messaging.Message._INSTALLATION: FAKE_INSTALLATION_ID,
            messaging.Message._COURSE: FAKE_COURSE_ID,
            messaging.Message._TIMESTAMP: FAKE_TIMESTAMP,
            messaging.Message._VERSION: os.environ['GCB_PRODUCT_VERSION'],
            messaging.Message._METRIC: messaging.Message.METRIC_STUDENT_COUNT,
            messaging.Message._VALUE: 1,
        }, {
            messaging.Message._INSTALLATION: FAKE_INSTALLATION_ID,
            messaging.Message._COURSE: FAKE_COURSE_ID,
            messaging.Message._TIMESTAMP: now - (now % 3600),
            messaging.Message._VERSION: os.environ['GCB_PRODUCT_VERSION'],
            messaging.Message._METRIC: messaging.Message.METRIC_ENROLLED,
            messaging.Message._VALUE: 1,
        }]
        actual = MockSender.get_sent()
        actual.sort(key=lambda x: x['timestamp'])
        self.assertEquals(expected, actual)
        sites.reset_courses()
Exemple #3
0
 def test_not_from_cron_and_not_admin(self):
     config.set_report_allowed(True)
     actions.logout()
     response = self.get(usage_reporting.StartReportingJobs.URL,
                         expect_errors=True)
     self.assertEquals(403, response.status_int)
     self.assertEquals('Forbidden.', response.body)
    def test_on_change_report_allowed(self):
        config.set_report_allowed(True)
        config._on_change_report_allowed(config.REPORT_ALLOWED, False)
        config.set_report_allowed(False)
        config._on_change_report_allowed(config.REPORT_ALLOWED, True)

        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.ADMIN_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.ADMIN_SOURCE,
        }]
        self.assertEquals(expected, MockSender.get_sent())
Exemple #5
0
    def test_jobs_run(self):
        COURSE = 'test'
        app_context = actions.simple_add_course(COURSE, ADMIN_EMAIL, 'Test')
        actions.register(self, 'Joe Admin', COURSE)
        config.set_report_allowed(True)
        response = self.get(usage_reporting.StartReportingJobs.URL,
                            headers={'X-AppEngine-Cron': 'True'})
        self.assertEquals(200, response.status_int)
        self.assertEquals('OK.', response.body)
        now = int(time.time())
        self.execute_all_deferred_tasks(
            models.StudentLifecycleObserver.QUEUE_NAME)
        self.execute_all_deferred_tasks()

        expected = [{
            messaging.Message._INSTALLATION: FAKE_INSTALLATION_ID,
            messaging.Message._COURSE: FAKE_COURSE_ID,
            messaging.Message._TIMESTAMP: FAKE_TIMESTAMP,
            messaging.Message._VERSION: os.environ['GCB_PRODUCT_VERSION'],
            messaging.Message._METRIC: messaging.Message.METRIC_STUDENT_COUNT,
            messaging.Message._VALUE: 1,
        }, {
            messaging.Message._INSTALLATION: FAKE_INSTALLATION_ID,
            messaging.Message._COURSE: FAKE_COURSE_ID,
            messaging.Message._TIMESTAMP: now - (now % 3600),
            messaging.Message._VERSION: os.environ['GCB_PRODUCT_VERSION'],
            messaging.Message._METRIC: messaging.Message.METRIC_ENROLLED,
            messaging.Message._VALUE: 1,
        }]
        actual = MockSender.get_sent()
        actual.sort(key=lambda x: x['timestamp'])
        self.assertEquals(expected, actual)
        sites.reset_courses()
Exemple #6
0
def _welcome_form_submitted(handler):
    """Note value of reporting consent checkbox submitted with Welcome form."""

    consent_val = handler.request.get(USAGE_REPORTING_CONSENT_CHECKBOX_NAME)
    is_allowed = (consent_val == USAGE_REPORTING_CONSENT_CHECKBOX_VALUE)
    config.set_report_allowed(is_allowed)
    messaging.Message.send_instance_message(
        messaging.Message.METRIC_REPORT_ALLOWED, is_allowed,
        source=messaging.Message.WELCOME_SOURCE)
    def test_banner_not_shown_when_choices_have_been_made(self):
        config.set_report_allowed(False)

        # Check super-user role; global admin
        dom = self.parse_html_string(self.get('/admin/global').body)
        self.assertIsNone(dom.find('.//div[@class="consent-banner"]'))

        # check super-user role; dashboard
        dom = self.parse_html_string(self.get('dashboard').body)
        self.assertIsNone(dom.find('.//div[@class="consent-banner"]'))

        # Check non-super role; dashboadd
        actions.logout()
        actions.login(self.NOT_SUPER_EMAIL, is_admin=False)
        dom = self.parse_html_string(self.get('dashboard').body)
        self.assertIsNone(dom.find('.//div[@class="consent-banner"]'))
    def test_banner_not_shown_when_choices_have_been_made(self):
        config.set_report_allowed(False)

        # Check super-user role; global admin
        dom = self.parse_html_string(self.get('/admin/global').body)
        self.assertIsNone(dom.find('.//div[@class="consent-banner"]'))

        # check super-user role; dashboard
        dom = self.parse_html_string(self.get('dashboard').body)
        self.assertIsNone(dom.find('.//div[@class="consent-banner"]'))

        # Check non-super role; dashboadd
        actions.logout()
        actions.login(self.NOT_SUPER_EMAIL, is_admin=False)
        dom = self.parse_html_string(self.get('dashboard').body)
        self.assertIsNone(dom.find('.//div[@class="consent-banner"]'))
    def test_welcome_page_checkbox_state(self):
        # Expect checkbox checked when no setting made
        dom = self.parse_html_string(self.get('/admin/welcome').body)
        checkbox = dom.find('.//input[@type="checkbox"]')
        self.assertEqual('checked', checkbox.attrib['checked'])

        # Expect checkbox unchecked when setting is False
        config.set_report_allowed(False)
        dom = self.parse_html_string(self.get('/admin/welcome').body)
        checkbox = dom.find('.//input[@type="checkbox"]')
        self.assertNotIn('checked', checkbox.attrib)

        # Expect checkbox checked when setting is True
        config.set_report_allowed(True)
        dom = self.parse_html_string(self.get('/admin/welcome').body)
        checkbox = dom.find('.//input[@type="checkbox"]')
        self.assertEqual('checked', checkbox.attrib['checked'])
    def test_welcome_page_checkbox_state(self):
        # Expect checkbox checked when no setting made
        dom = self.parse_html_string(self.get('/admin/welcome').body)
        checkbox = dom.find('.//input[@type="checkbox"]')
        self.assertEqual('checked', checkbox.attrib['checked'])

        # Expect checkbox unchecked when setting is False
        config.set_report_allowed(False)
        dom = self.parse_html_string(self.get('/admin/welcome').body)
        checkbox = dom.find('.//input[@type="checkbox"]')
        self.assertNotIn('checked', checkbox.attrib)

        # Expect checkbox checked when setting is True
        config.set_report_allowed(True)
        dom = self.parse_html_string(self.get('/admin/welcome').body)
        checkbox = dom.find('.//input[@type="checkbox"]')
        self.assertEqual('checked', checkbox.attrib['checked'])
    def post(self):
        request = transforms.loads(self.request.get('request'))

        if not self.assert_xsrf_token_or_fail(request, self.XSRF_TOKEN, {}):
            return

        if not roles.Roles.is_super_admin():
            transforms.send_json_response(self, 401, 'Access denied.', {})
            return

        payload = transforms.loads(request.get('payload'))
        is_allowed = payload['is_allowed']
        config.set_report_allowed(is_allowed)
        messaging.Message.send_instance_message(
            messaging.Message.METRIC_REPORT_ALLOWED, is_allowed,
            source=messaging.Message.BANNER_SOURCE)

        transforms.send_json_response(self, 200, 'OK')
Exemple #12
0
    def post(self):
        request = transforms.loads(self.request.get('request'))

        if not self.assert_xsrf_token_or_fail(request, self.XSRF_TOKEN, {}):
            return

        if not roles.Roles.is_super_admin():
            transforms.send_json_response(self, 401, 'Access denied.', {})
            return

        payload = transforms.loads(request.get('payload'))
        is_allowed = payload['is_allowed']
        config.set_report_allowed(is_allowed)
        messaging.Message.send_instance_message(
            messaging.Message.METRIC_REPORT_ALLOWED,
            is_allowed,
            source=messaging.Message.BANNER_SOURCE)

        transforms.send_json_response(self, 200, 'OK')
    def test_set_report_allowed(self):
        config.set_report_allowed(True)
        self.assertEquals(True, config.REPORT_ALLOWED.value)

        config.set_report_allowed(False)
        self.assertEquals(False, config.REPORT_ALLOWED.value)

        config.set_report_allowed(True)
        self.assertEquals(True, config.REPORT_ALLOWED.value)

        config.set_report_allowed(False)
        self.assertEquals(False, config.REPORT_ALLOWED.value)
    def test_set_report_allowed(self):
        config.set_report_allowed(True)
        self.assertEquals(True, config.REPORT_ALLOWED.value)

        config.set_report_allowed(False)
        self.assertEquals(False, config.REPORT_ALLOWED.value)

        config.set_report_allowed(True)
        self.assertEquals(True, config.REPORT_ALLOWED.value)

        config.set_report_allowed(False)
        self.assertEquals(False, config.REPORT_ALLOWED.value)
    def test_on_change_report_allowed(self):
        config.set_report_allowed(True)
        config._on_change_report_allowed(config.REPORT_ALLOWED, False)
        config.set_report_allowed(False)
        config._on_change_report_allowed(config.REPORT_ALLOWED, True)

        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.ADMIN_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.ADMIN_SOURCE,
        }]
        self.assertEquals(expected, MockSender.get_sent())
 def test_not_from_cron_but_is_admin(self):
     config.set_report_allowed(True)
     response = self.get(usage_reporting.StartReportingJobs.URL,
                         expect_errors=True)
     self.assertEquals(200, response.status_int)
     self.assertEquals('OK.', response.body)
 def test_disallowed(self):
     config.set_report_allowed(False)
     response = self.get(usage_reporting.StartReportingJobs.URL,
                         headers={'X-AppEngine-Cron': 'True'})
     self.assertEquals(200, response.status_int)
     self.assertEquals('Disabled.', response.body)
 def test_disallowed(self):
     config.set_report_allowed(False)
     response = self.get(usage_reporting.StartReportingJobs.URL)
     self.assertEquals(200, response.status_int)
     self.assertEquals('Disabled.', response.body)
 def test_disallowed(self):
     config.set_report_allowed(False)
     response = self.get(usage_reporting.StartReportingJobs.URL)
     self.assertEquals(200, response.status_int)
     self.assertEquals('Disabled.', response.body)
Exemple #20
0
 def test_not_from_cron_but_is_admin(self):
     config.set_report_allowed(True)
     response = self.get(usage_reporting.StartReportingJobs.URL,
                         expect_errors=True)
     self.assertEquals(200, response.status_int)
     self.assertEquals('OK.', response.body)
 def test_disallowed(self):
     config.set_report_allowed(False)
     response = self.get(usage_reporting.StartReportingJobs.URL,
                         headers={'X-AppEngine-Cron': 'True'})
     self.assertEquals(200, response.status_int)
     self.assertEquals('Disabled.', response.body)