Esempio n. 1
0
 def setUp(self):
     super(CourseEnrollmentGeographyTests, self).setUp()
     self.page = CourseEnrollmentGeographyPage(self.browser)
     self.course = self.api_client.courses(self.page.course_id)
     self.enrollment_data = sorted(self.course.enrollment(
         demographic.LOCATION),
                                   key=lambda item: item['count'],
                                   reverse=True)
Esempio n. 2
0
class CourseEnrollmentGeographyTests(CoursePageTestsMixin, WebAppTest):
    help_path = 'enrollment/Enrollment_Geography.html'

    def setUp(self):
        super(CourseEnrollmentGeographyTests, self).setUp()
        self.page = CourseEnrollmentGeographyPage(self.browser)
        self.course = self.api_client.courses(self.page.course_id)
        self.enrollment_data = sorted(self.course.enrollment(
            demographic.LOCATION),
                                      key=lambda item: item['count'],
                                      reverse=True)

    def test_page(self):
        super(CourseEnrollmentGeographyTests, self).test_page()
        self._test_enrollment_country_map()
        self._test_enrollment_country_table()
        self._test_metrics()

    def _get_data_update_message(self):
        current_enrollment = self.course.enrollment(demographic.LOCATION)[0]
        last_updated = datetime.datetime.strptime(
            current_enrollment['created'], self.api_datetime_format)
        return 'Geographic student data was last updated %(update_date)s at %(update_time)s UTC.' % \
               self.format_last_updated_date_and_time(last_updated)

    def _test_enrollment_country_map(self):
        """ Verify the geolocation map is loaded. """

        map_selector = "div[data-view=world-map]"

        # Ensure the map is loaded via AJAX
        self.fulfill_loading_promise(map_selector)

        # make sure the map section is present
        element = self.page.q(css=map_selector)
        self.assertTrue(element.present)

        # make sure that the map is present
        element = self.page.q(css=map_selector + " svg[class=datamap]")
        self.assertTrue(element.present)

        # make sure the legend is present
        element = self.page.q(css=map_selector + " svg[class=datamaps-legend]")
        self.assertTrue(element.present)

    def _test_enrollment_country_table(self):
        """ Verify the geolocation enrollment table is loaded. """

        table_section_selector = "div[data-role=enrollment-location-table]"
        self.assertTable(table_section_selector,
                         ['Country', 'Percent', 'Total Enrollment'],
                         'a[data-role=enrollment-location-csv]')

        rows = self.page.browser.find_elements_by_css_selector(
            '{} tbody tr'.format(table_section_selector))
        sum_count = float(
            sum([datum['count'] for datum in self.enrollment_data]))

        for i, row in enumerate(rows):
            columns = row.find_elements_by_css_selector('td')
            enrollment = self.enrollment_data[i]

            expected_percent_display = self.build_display_percentage(
                enrollment['count'], sum_count)

            country_name = enrollment['country']['name']
            if country_name == UNKNOWN_COUNTRY_CODE:
                country_name = u'Unknown Country'

            expected = [
                country_name, expected_percent_display,
                self.format_number(enrollment['count'])
            ]
            actual = [columns[0].text, columns[1].text, columns[2].text]
            self.assertListEqual(actual, expected)
            self.assertIn('text-right', columns[1].get_attribute('class'))

    def _test_metrics(self):
        """ Verify the metrics tiles display the correct information. """

        enrollment_data = [
            datum for datum in self.enrollment_data
            if datum['country']['name'] != 'UNKNOWN'
        ]
        self.assertSummaryPointValueEquals('data-stat-type=num-countries',
                                           unicode(len(enrollment_data)))

        for i in range(0, 3):
            country = enrollment_data[i]['country']['name']
            self.assertSummaryPointValueEquals(
                'data-stat-type=top-country-{0}'.format((i + 1)), country)
class CourseEnrollmentGeographyTests(CoursePageTestsMixin, WebAppTest):
    help_path = 'enrollment/Enrollment_Geography.html'

    def setUp(self):
        super(CourseEnrollmentGeographyTests, self).setUp()
        self.page = CourseEnrollmentGeographyPage(self.browser)
        self.course = self.analytics_api_client.courses(self.page.course_id)
        self.enrollment_data = sorted(self.course.enrollment(demographic.LOCATION),
                                      key=lambda item: item['count'], reverse=True)

    def test_page(self):
        super(CourseEnrollmentGeographyTests, self).test_page()
        self._test_enrollment_country_map()
        self._test_enrollment_country_table()
        self._test_metrics()

    def _get_data_update_message(self):
        current_enrollment = self.course.enrollment(demographic.LOCATION)[0]
        last_updated = datetime.datetime.strptime(current_enrollment['created'], self.api_datetime_format)
        return 'Geographic student data was last updated %(update_date)s at %(update_time)s UTC.' % \
               self.format_last_updated_date_and_time(last_updated)

    def _test_enrollment_country_map(self):
        """ Verify the geolocation map is loaded. """

        map_selector = "div[data-view=world-map]"

        # Ensure the map is loaded via AJAX
        self.fulfill_loading_promise(map_selector)

        # make sure the map section is present
        element = self.page.q(css=map_selector)
        self.assertTrue(element.present)

        # make sure that the map is present
        element = self.page.q(css=map_selector + " svg[class=datamap]")
        self.assertTrue(element.present)

        # make sure the legend is present
        element = self.page.q(css=map_selector + " svg[class=datamaps-legend]")
        self.assertTrue(element.present)

    def _test_enrollment_country_table(self):
        """ Verify the geolocation enrollment table is loaded. """

        table_section_selector = "div[data-role=enrollment-location-table]"
        self.assertTable(table_section_selector, ['Country', 'Percent', 'Current Enrollment'],
                         'a[data-role=enrollment-location-csv]')

        rows = self.page.browser.find_elements_by_css_selector('{} tbody tr'.format(table_section_selector))
        sum_count = float(sum([datum['count'] for datum in self.enrollment_data]))

        for i, row in enumerate(rows):
            columns = row.find_elements_by_css_selector('td')
            enrollment = self.enrollment_data[i]

            expected_percent_display = self.build_display_percentage(enrollment['count'], sum_count)

            country_name = enrollment['country']['name']
            if country_name == UNKNOWN_COUNTRY_CODE:
                country_name = u'Unknown Country'
            # FIXME: because django-countries is different between dashboard and api
            elif country_name == 'United States':
                country_name = u'United States of America'

            expected = [country_name, expected_percent_display, self.format_number(enrollment['count'])]
            actual = [columns[0].text, columns[1].text, columns[2].text]
            self.assertListEqual(actual, expected)
            self.assertIn('text-right', columns[1].get_attribute('class'))

    def _test_metrics(self):
        """ Verify the metrics tiles display the correct information. """

        enrollment_data = [datum for datum in self.enrollment_data if datum['country']['name'] != 'UNKNOWN']
        self.assertSummaryPointValueEquals('data-stat-type=num-countries', unicode(len(enrollment_data)))

        for i in range(0, 3):
            country = enrollment_data[i]['country']['name']
            # FIXME: because django-countries is different between dashboard and api
            if country == 'United States':
                country = u'United Sta...'
            self.assertSummaryPointValueEquals('data-stat-type=top-country-{0}'.format((i + 1)), country)
 def setUp(self):
     super(CourseEnrollmentGeographyTests, self).setUp()
     self.page = CourseEnrollmentGeographyPage(self.browser)
     self.course = self.analytics_api_client.courses(self.page.course_id)
     self.enrollment_data = sorted(self.course.enrollment(demographic.LOCATION),
                                   key=lambda item: item['count'], reverse=True)
class CourseEnrollmentGeographyTests(CoursePageTestsMixin, WebAppTest):
    def setUp(self):
        super(CourseEnrollmentGeographyTests, self).setUp()
        self.page = CourseEnrollmentGeographyPage(self.browser)
        self.course = self.api_client.courses(self.page.course_id)
        self.enrollment_data = sorted(self.course.enrollment(demographic.LOCATION),
                                      key=lambda item: item['count'], reverse=True)

    def test_page(self):
        super(CourseEnrollmentGeographyTests, self).test_page()
        self._test_enrollment_country_map()
        self._test_enrollment_country_table()
        self._test_metrics()

    def _get_data_update_message(self):
        current_enrollment = self.course.enrollment(demographic.LOCATION)[0]
        last_updated = datetime.datetime.strptime(current_enrollment['created'], self.api_datetime_format)
        return 'Geographic student data was last updated %(update_date)s at %(update_time)s UTC.' % \
               self.format_last_updated_date_and_time(last_updated)

    def _test_enrollment_country_map(self):
        """ Verify the geolocation map is loaded. """

        map_selector = "div[data-view=world-map]"

        # Ensure the map is loaded via AJAX
        self.fulfill_loading_promise(map_selector)

        # make sure the map section is present
        element = self.page.q(css=map_selector)
        self.assertTrue(element.present)

        # make sure that the map is present
        element = self.page.q(css=map_selector + " svg[class=datamap]")
        self.assertTrue(element.present)

        # make sure the legend is present
        element = self.page.q(css=map_selector + " svg[class=datamaps-legend]")
        self.assertTrue(element.present)

    def _test_enrollment_country_table(self):
        """ Verify the geolocation enrollment table is loaded. """

        table_section_selector = "div[data-role=enrollment-location-table]"

        # Ensure the table is loaded via AJAX
        self.fulfill_loading_promise(table_section_selector)

        # make sure the map section is present
        element = self.page.q(css=table_section_selector)
        self.assertTrue(element.present)

        # make sure the table is present
        table_selector = table_section_selector + " table"
        element = self.page.q(css=table_selector)
        self.assertTrue(element.present)

        # check the headings
        self.assertTableColumnHeadingsEqual(table_selector, ['Country', 'Percent', 'Total Enrollment'])

        # Verify CSV button has an href attribute
        selector = "a[data-role=enrollment-location-csv]"
        self.assertValidHref(selector)

        # Check the results of the table
        rows = self.page.browser.find_elements_by_css_selector('%s tbody tr' % table_selector)
        self.assertGreater(len(rows), 0)

        sum_count = float(sum([datum['count'] for datum in self.enrollment_data]))

        for i, row in enumerate(rows):
            columns = row.find_elements_by_css_selector('td')
            enrollment = self.enrollment_data[i]
            expected_percent = enrollment['count'] / sum_count * 100
            expected_percent_display = '{:.1f}%'.format(expected_percent) if expected_percent >= 1.0 else '< 1%'
            expected = [enrollment['country']['name'], expected_percent_display, enrollment['count']]
            actual = [columns[0].text, columns[1].text, int(columns[2].text)]
            self.assertListEqual(actual, expected)
            self.assertIn('text-right', columns[1].get_attribute('class'))

    def _test_metrics(self):
        """ Verify the metrics tiles display the correct information. """

        enrollment_data = [datum for datum in self.enrollment_data if datum['country']['name'] != 'UNKNOWN']
        self.assertSummaryPointValueEquals('data-stat-type=num-countries', unicode(len(enrollment_data)))

        for i in range(0, 3):
            country = enrollment_data[i]['country']['name']
            self.assertSummaryPointValueEquals('data-stat-type=top-country-{0}'.format((i + 1)), country)