Commit 57af64c4 by Clinton Blackburn

Corrected data sources for Affiliate Window serializer (#120)

ECOM-4601
parent 704d3c7c
......@@ -200,10 +200,15 @@ class ContainedCoursesSerializer(serializers.Serializer): # pylint: disable=abs
class AffiliateWindowSerializer(serializers.ModelSerializer):
""" Serializer for Affiliate Window product feeds. """
# We use a hardcoded value since it is determined by Affiliate Window's taxonomy.
CATEGORY = 'Other Experiences'
pid = serializers.SerializerMethodField()
name = serializers.CharField(source='course_run.course.title')
desc = serializers.CharField(source='course_run.course.short_description')
purl = serializers.CharField(source='course_run.course.marketing_url')
name = serializers.CharField(source='course_run.title')
desc = serializers.CharField(source='course_run.short_description')
purl = serializers.CharField(source='course_run.marketing_url')
imgurl = serializers.CharField(source='course_run.image')
category = serializers.SerializerMethodField()
price = serializers.SerializerMethodField()
......@@ -223,5 +228,4 @@ class AffiliateWindowSerializer(serializers.ModelSerializer):
}
def get_category(self, obj): # pylint: disable=unused-argument
# Using hardcoded value for category. This value comes from an Affiliate Window taxonomy.
return 'Other Experiences'
return self.CATEGORY
......@@ -297,11 +297,15 @@ class AffiliateWindowSerializerTests(TestCase):
seat = SeatFactory(course_run=course_run)
serializer = AffiliateWindowSerializer(seat)
# Verify none of the course run attributes are empty; otherwise, Affiliate Window will report errors.
# pylint: disable=no-member
self.assertTrue(all((course_run.title, course_run.short_description, course_run.marketing_url)))
expected = {
'pid': '{}-{}'.format(course_run.key, seat.type),
'name': course_run.course.title,
'desc': course_run.course.short_description,
'purl': course_run.course.marketing_url,
'name': course_run.title,
'desc': course_run.short_description,
'purl': course_run.marketing_url,
'price': {
'actualp': seat.price
},
......
......@@ -9,6 +9,7 @@ from lxml import etree
from rest_framework.reverse import reverse
from rest_framework.test import APITestCase
from course_discovery.apps.api.serializers import AffiliateWindowSerializer
from course_discovery.apps.api.v1.tests.test_views.mixins import SerializationMixin
from course_discovery.apps.catalogs.tests.factories import CatalogFactory
from course_discovery.apps.core.tests.factories import UserFactory
......@@ -34,7 +35,6 @@ class AffiliateWindowViewSetTests(ElasticsearchTestMixin, SerializationMixin, AP
self.seat_verified = SeatFactory(course_run=self.course_run, type=Seat.VERIFIED)
self.course = self.course_run.course
self.affiliate_url = reverse('api:v1:partners:affiliate_window-detail', kwargs={'pk': self.catalog.id})
self.affiliate_window_category = 'Other Experiences'
self.refresh_index()
def test_without_authentication(self):
......@@ -95,13 +95,13 @@ class AffiliateWindowViewSetTests(ElasticsearchTestMixin, SerializationMixin, AP
def assert_product_xml(self, content, seat):
""" Helper method to verify product data in xml format. """
self.assertEqual(content.find('pid').text, '{}-{}'.format(self.course_run.key, seat.type))
self.assertEqual(content.find('name').text, self.course_run.course.title)
self.assertEqual(content.find('desc').text, self.course_run.course.short_description)
self.assertEqual(content.find('purl').text, self.course_run.course.marketing_url)
self.assertEqual(content.find('name').text, self.course_run.title)
self.assertEqual(content.find('desc').text, self.course_run.short_description)
self.assertEqual(content.find('purl').text, self.course_run.marketing_url)
self.assertEqual(content.find('imgurl').text, self.course_run.image.src)
self.assertEqual(content.find('price/actualp').text, str(seat.price))
self.assertEqual(content.find('currency').text, seat.currency.code)
self.assertEqual(content.find('category').text, self.affiliate_window_category)
self.assertEqual(content.find('category').text, AffiliateWindowSerializer.CATEGORY)
def test_dtd_with_valid_data(self):
""" Verify the XML data produced by the endpoint conforms to the DTD file. """
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment