示例#1
0
    def create_course_with_basic_active_course_run(self):
        course = AlgoliaProxyCourseFactory(partner=self.__class__.edxPartner)

        course_run = CourseRunFactory(course=course,
                                      start=self.YESTERDAY,
                                      end=self.YESTERDAY,
                                      status=CourseRunStatus.Published)
        SeatFactory(
            course_run=course_run,
            type=SeatTypeFactory.audit(),
        )
        return course
    def test_csv(self):
        SeatFactory(type=SeatTypeFactory.audit(), course_run=self.course_run)
        SeatFactory(type=SeatTypeFactory.verified(),
                    course_run=self.course_run)
        SeatFactory(type=SeatTypeFactory.credit(),
                    course_run=self.course_run,
                    credit_provider='ASU',
                    credit_hours=9)
        SeatFactory(type=SeatTypeFactory.credit(),
                    course_run=self.course_run,
                    credit_provider='Hogwarts',
                    credit_hours=4)

        url = reverse('api:v1:catalog-csv', kwargs={'id': self.catalog.id})

        with self.assertNumQueries(23):
            response = self.client.get(url)

        course_run = self.serialize_catalog_flat_course_run(self.course_run)
        expected = [
            course_run['announcement'],
            course_run['content_language'],
            course_run['course_key'],
            course_run['end'],
            course_run['enrollment_end'],
            course_run['enrollment_start'],
            course_run['expected_learning_items'],
            course_run['full_description'],
            '',  # image description
            '',  # image height
            course_run['image']['src'],
            '',  # image width
            course_run['key'],
            str(course_run['level_type']),
            course_run['marketing_url'],
            str(course_run['max_effort']),
            str(course_run['min_effort']),
            course_run['modified'],
            course_run['owners'],
            course_run['pacing_type'],
            course_run['prerequisites'],
            course_run['seats']['audit']['type'],
            '{}'.format(course_run['seats']['credit']['credit_hours']),
            '{}'.format(course_run['seats']['credit']['credit_provider']),
            '{}'.format(course_run['seats']['credit']['currency']),
            '{}'.format(str(course_run['seats']['credit']['price'])),
            '{}'.format(course_run['seats']['credit']['type']),
            '{}'.format(course_run['seats']['credit']['upgrade_deadline']),
            course_run['seats']['honor']['type'],
            course_run['seats']['masters']['type'],
            course_run['seats']['professional']['currency'],
            str(course_run['seats']['professional']['price']),
            course_run['seats']['professional']['type'],
            course_run['seats']['professional']['upgrade_deadline'],
            course_run['seats']['verified']['currency'],
            str(course_run['seats']['verified']['price']),
            course_run['seats']['verified']['type'],
            course_run['seats']['verified']['upgrade_deadline'],
            course_run['short_description'],
            course_run['sponsors'],
            course_run['start'],
            course_run['subjects'],
            course_run['title'],
            course_run['video']['description'],
            course_run['video']['image']['description'],
            str(course_run['video']['image']['height']),
            course_run['video']['image']['src'],
            str(course_run['video']['image']['width']),
            course_run['video']['src'],
        ]

        # collect streamed content
        received_content = b''
        for item in response.streaming_content:
            received_content += item

        # convert received content to csv for comparison
        f = StringIO(received_content.decode('utf-8'))
        reader = csv.reader(f)
        content = list(reader)

        assert response.status_code == 200
        assert expected == content[1]