示例#1
0
    def test_coupon_product_details(self):
        """Verify the endpoint returns all coupon information."""
        coupon = self.create_coupon(partner=self.partner)
        url = reverse('api:v2:product-detail', kwargs={'pk': coupon.id})
        response = self.client.get(url)
        self.assertEqual(response.status_code, 200)

        request = RequestFactory(SERVER_NAME=self.site.domain).get('/')
        request.user = self.user
        request.site = self.site
        expected = ProductSerializer(coupon, context={'request': request}).data
        self.assertDictEqual(response.data, expected)
示例#2
0
    def test_preview_success(self):
        """ Verify the endpoint returns a list of catalogs from the Catalog API. """
        self.mock_access_token_response()
        seat = self.course.create_or_update_seat('verified', False, 0, self.partner)
        self.mock_course_runs_endpoint(self.site_configuration.discovery_api_url, course_run=self.course)

        url = '{path}?query=id:course*&seat_types=verified'.format(path=reverse('api:v2:catalog-preview-list'))
        response = self.client.get(url)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(
            json.loads(response.content)['seats'][0],
            ProductSerializer(seat, context={'request': response.wsgi_request}).data
        )
示例#3
0
    def test_catalog_products(self):
        """Verify the endpoint returns all products associated with a specific catalog."""
        path = reverse(
            'api:v2:catalog-product-list',
            kwargs={'parent_lookup_stockrecords__catalogs': self.catalog.id}
        )
        response = self.client.get(path)
        response_data = json.loads(response.content)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response_data['count'], 0)
        self.assertListEqual(response_data['results'], [])

        self.catalog.stock_records.add(self.stock_record)

        response = self.client.get(path)
        response_data = json.loads(response.content)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response_data['count'], 1)

        expected_data = ProductSerializer(self.stock_record.product, context={'request': response.wsgi_request}).data
        self.assertListEqual(response_data['results'], [expected_data])