예제 #1
0
    def test_affiliate_with_supported_seats(self):
        """ Verify that endpoint returns course runs for verified and professional seats only. """
        response = self.client.get(self.affiliate_url)

        self.assertEqual(response.status_code, 200)
        root = ET.fromstring(response.content)
        self.assertEqual(1, len(root.findall('product')))
        self.assert_product_xml(
            root.findall('product/[pid="{}-{}"]'.format(
                self.course_run.key, self.seat_verified.type.slug))[0],
            self.seat_verified)

        # Add professional seat
        seat_professional = SeatFactory(course_run=self.course_run,
                                        type=SeatTypeFactory.professional())

        response = self.client.get(self.affiliate_url)
        root = ET.fromstring(response.content)
        self.assertEqual(2, len(root.findall('product')))

        self.assert_product_xml(
            root.findall('product/[pid="{}-{}"]'.format(
                self.course_run.key, self.seat_verified.type.slug))[0],
            self.seat_verified)
        self.assert_product_xml(
            root.findall('product/[pid="{}-{}"]'.format(
                self.course_run.key, seat_professional.type.slug))[0],
            seat_professional)
예제 #2
0
    def mock_courses_api(self):
        # Create existing seats to be removed by ingest
        audit_run_type = CourseRunType.objects.get(slug=CourseRunType.AUDIT)
        credit_run_type = CourseRunType.objects.get(slug=CourseRunType.CREDIT_VERIFIED_AUDIT)
        verified_run_type = CourseRunType.objects.get(slug=CourseRunType.VERIFIED_AUDIT)
        audit_run = CourseRunFactory(title_override='audit', key='audit/course/run', type=audit_run_type)
        verified_run = CourseRunFactory(title_override='verified', key='verified/course/run', type=verified_run_type)
        credit_run = CourseRunFactory(title_override='credit', key='credit/course/run', type=credit_run_type)
        no_currency_run = CourseRunFactory(title_override='no currency', key='nocurrency/course/run',
                                           type=verified_run_type)

        professional_type = SeatTypeFactory.professional()
        SeatFactory(course_run=audit_run, type=professional_type)
        SeatFactory(course_run=verified_run, type=professional_type)
        SeatFactory(course_run=credit_run, type=professional_type)
        SeatFactory(course_run=no_currency_run, type=professional_type)

        bodies = mock_data.ECOMMERCE_API_BODIES
        url = self.api_url + 'courses/'
        responses.add_callback(
            responses.GET,
            url,
            callback=mock_api_callback(url, bodies),
            content_type=JSON
        )
        return bodies