Esempio n. 1
0
    def test_csv_pagination(self):
        """ Verify the endpoint returns properly paginated CSV data"""

        # Create learners, using a cohort name with a comma, to test escaping.
        usernames = [
            'victor',
            'olga',
            'gabe',
        ]
        commaCohort = 'Lions, Tigers, & Bears'
        self.create_learners([{
            'username': username,
            'course_id': self.course_id,
            'cohort': commaCohort
        } for username in usernames])

        # Set last_updated index date
        last_updated = '2015-09-28'
        self.create_update_index(last_updated)

        # Render CSV with one learner per page
        page_size = 1
        prev_page = None

        for idx, username in enumerate(sorted(usernames)):
            page = idx + 1
            response = self.authenticated_get(self.path,
                                              dict(course_id=self.course_id,
                                                   page=page,
                                                   page_size=page_size),
                                              True,
                                              HTTP_ACCEPT='text/csv')

            # Construct expected content data
            expected_data = [{
                "username": username,
                "enrollment_mode": 'honor',
                "name": username,
                "email": f"{username}@example.com",
                "account_url": f"http://lms-host/{username}",
                "cohort": commaCohort,
                "engagements.problems_attempted": 0,
                "engagements.problems_completed": 0,
                "engagements.videos_viewed": 0,
                "engagements.discussion_contributions": 0,
                "engagements.problem_attempts_per_completed": None,
                "enrollment_date": '2015-01-28',
                "last_updated": last_updated,
                "segments": None,
                "user_id": None,
                "language": None,
                "location": None,
                "year_of_birth": None,
                "level_of_education": None,
                "gender": None,
                "mailing_address": None,
                "city": None,
                "country": None,
                "goals": None,
            }]

            # Construct expected links header from pagination data
            prev_url = self.expected_page_url(self.course_id, prev_page,
                                              page_size)
            next_page = page + 1
            next_url = None
            if next_page <= len(usernames):
                next_url = self.expected_page_url(self.course_id, next_page,
                                                  page_size)
            expected_links = PaginatedHeadersMixin.get_paginated_links(
                dict(next=next_url, previous=prev_url))

            self.assertCsvResponseIsValid(response, self.get_csv_filename(),
                                          expected_data,
                                          {'Link': expected_links})
            prev_page = page
    def test_csv_pagination(self):
        """ Verify the endpoint returns properly paginated CSV data"""

        # Create learners, using a cohort name with a comma, to test escaping.
        usernames = ['victor', 'olga', 'gabe', ]
        commaCohort = 'Lions, Tigers, & Bears'
        self.create_learners([{'username': username, 'course_id': self.course_id, 'cohort': commaCohort}
                              for username in usernames])

        # Set last_updated index date
        last_updated = '2015-09-28'
        self.create_update_index(last_updated)

        # Render CSV with one learner per page
        page_size = 1
        prev_page = None

        for idx, username in enumerate(sorted(usernames)):
            page = idx + 1
            response = self.authenticated_get(
                self.path,
                dict(course_id=self.course_id, page=page, page_size=page_size),
                True,
                HTTP_ACCEPT='text/csv'
            )

            # Construct expected content data
            expected_data = [{
                "username": username,
                "enrollment_mode": 'honor',
                "name": username,
                "email": "{}@example.com".format(username),
                "account_url": "http://lms-host/{}".format(username),
                "cohort": commaCohort,
                "engagements.problems_attempted": 0,
                "engagements.problems_completed": 0,
                "engagements.videos_viewed": 0,
                "engagements.discussion_contributions": 0,
                "engagements.problem_attempts_per_completed": None,
                "enrollment_date": '2015-01-28',
                "last_updated": last_updated,
                "segments": None,
                "user_id": None,
                "language": None,
                "location": None,
                "year_of_birth": None,
                "level_of_education": None,
                "gender": None,
                "mailing_address": None,
                "city": None,
                "country": None,
                "goals": None,
            }]

            # Construct expected links header from pagination data
            prev_url = self.expected_page_url(self.course_id, prev_page, page_size)
            next_page = page + 1
            next_url = None
            if next_page <= len(usernames):
                next_url = self.expected_page_url(self.course_id, next_page, page_size)
            expected_links = PaginatedHeadersMixin.get_paginated_links(dict(next=next_url, previous=prev_url))

            self.assertCsvResponseIsValid(response, self.get_csv_filename(), expected_data, {'Link': expected_links})
            prev_page = page