Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
course-discovery
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
course-discovery
Commits
57af64c4
Commit
57af64c4
authored
Jun 02, 2016
by
Clinton Blackburn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Corrected data sources for Affiliate Window serializer (#120)
ECOM-4601
parent
704d3c7c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
13 deletions
+21
-13
course_discovery/apps/api/serializers.py
+9
-5
course_discovery/apps/api/tests/test_serializers.py
+7
-3
course_discovery/apps/api/v1/tests/test_views/test_affiliate_window.py
+5
-5
No files found.
course_discovery/apps/api/serializers.py
View file @
57af64c4
...
@@ -200,10 +200,15 @@ class ContainedCoursesSerializer(serializers.Serializer): # pylint: disable=abs
...
@@ -200,10 +200,15 @@ class ContainedCoursesSerializer(serializers.Serializer): # pylint: disable=abs
class
AffiliateWindowSerializer
(
serializers
.
ModelSerializer
):
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
()
pid
=
serializers
.
SerializerMethodField
()
name
=
serializers
.
CharField
(
source
=
'course_run.
course.
title'
)
name
=
serializers
.
CharField
(
source
=
'course_run.title'
)
desc
=
serializers
.
CharField
(
source
=
'course_run.
course.
short_description'
)
desc
=
serializers
.
CharField
(
source
=
'course_run.short_description'
)
purl
=
serializers
.
CharField
(
source
=
'course_run.
course.
marketing_url'
)
purl
=
serializers
.
CharField
(
source
=
'course_run.marketing_url'
)
imgurl
=
serializers
.
CharField
(
source
=
'course_run.image'
)
imgurl
=
serializers
.
CharField
(
source
=
'course_run.image'
)
category
=
serializers
.
SerializerMethodField
()
category
=
serializers
.
SerializerMethodField
()
price
=
serializers
.
SerializerMethodField
()
price
=
serializers
.
SerializerMethodField
()
...
@@ -223,5 +228,4 @@ class AffiliateWindowSerializer(serializers.ModelSerializer):
...
@@ -223,5 +228,4 @@ class AffiliateWindowSerializer(serializers.ModelSerializer):
}
}
def
get_category
(
self
,
obj
):
# pylint: disable=unused-argument
def
get_category
(
self
,
obj
):
# pylint: disable=unused-argument
# Using hardcoded value for category. This value comes from an Affiliate Window taxonomy.
return
self
.
CATEGORY
return
'Other Experiences'
course_discovery/apps/api/tests/test_serializers.py
View file @
57af64c4
...
@@ -297,11 +297,15 @@ class AffiliateWindowSerializerTests(TestCase):
...
@@ -297,11 +297,15 @@ class AffiliateWindowSerializerTests(TestCase):
seat
=
SeatFactory
(
course_run
=
course_run
)
seat
=
SeatFactory
(
course_run
=
course_run
)
serializer
=
AffiliateWindowSerializer
(
seat
)
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
=
{
expected
=
{
'pid'
:
'{}-{}'
.
format
(
course_run
.
key
,
seat
.
type
),
'pid'
:
'{}-{}'
.
format
(
course_run
.
key
,
seat
.
type
),
'name'
:
course_run
.
course
.
title
,
'name'
:
course_run
.
title
,
'desc'
:
course_run
.
course
.
short_description
,
'desc'
:
course_run
.
short_description
,
'purl'
:
course_run
.
course
.
marketing_url
,
'purl'
:
course_run
.
marketing_url
,
'price'
:
{
'price'
:
{
'actualp'
:
seat
.
price
'actualp'
:
seat
.
price
},
},
...
...
course_discovery/apps/api/v1/tests/test_views/test_affiliate_window.py
View file @
57af64c4
...
@@ -9,6 +9,7 @@ from lxml import etree
...
@@ -9,6 +9,7 @@ from lxml import etree
from
rest_framework.reverse
import
reverse
from
rest_framework.reverse
import
reverse
from
rest_framework.test
import
APITestCase
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.api.v1.tests.test_views.mixins
import
SerializationMixin
from
course_discovery.apps.catalogs.tests.factories
import
CatalogFactory
from
course_discovery.apps.catalogs.tests.factories
import
CatalogFactory
from
course_discovery.apps.core.tests.factories
import
UserFactory
from
course_discovery.apps.core.tests.factories
import
UserFactory
...
@@ -34,7 +35,6 @@ class AffiliateWindowViewSetTests(ElasticsearchTestMixin, SerializationMixin, AP
...
@@ -34,7 +35,6 @@ class AffiliateWindowViewSetTests(ElasticsearchTestMixin, SerializationMixin, AP
self
.
seat_verified
=
SeatFactory
(
course_run
=
self
.
course_run
,
type
=
Seat
.
VERIFIED
)
self
.
seat_verified
=
SeatFactory
(
course_run
=
self
.
course_run
,
type
=
Seat
.
VERIFIED
)
self
.
course
=
self
.
course_run
.
course
self
.
course
=
self
.
course_run
.
course
self
.
affiliate_url
=
reverse
(
'api:v1:partners:affiliate_window-detail'
,
kwargs
=
{
'pk'
:
self
.
catalog
.
id
})
self
.
affiliate_url
=
reverse
(
'api:v1:partners:affiliate_window-detail'
,
kwargs
=
{
'pk'
:
self
.
catalog
.
id
})
self
.
affiliate_window_category
=
'Other Experiences'
self
.
refresh_index
()
self
.
refresh_index
()
def
test_without_authentication
(
self
):
def
test_without_authentication
(
self
):
...
@@ -95,13 +95,13 @@ class AffiliateWindowViewSetTests(ElasticsearchTestMixin, SerializationMixin, AP
...
@@ -95,13 +95,13 @@ class AffiliateWindowViewSetTests(ElasticsearchTestMixin, SerializationMixin, AP
def
assert_product_xml
(
self
,
content
,
seat
):
def
assert_product_xml
(
self
,
content
,
seat
):
""" Helper method to verify product data in xml format. """
""" 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
(
'pid'
)
.
text
,
'{}-{}'
.
format
(
self
.
course_run
.
key
,
seat
.
type
))
self
.
assertEqual
(
content
.
find
(
'name'
)
.
text
,
self
.
course_run
.
course
.
title
)
self
.
assertEqual
(
content
.
find
(
'name'
)
.
text
,
self
.
course_run
.
title
)
self
.
assertEqual
(
content
.
find
(
'desc'
)
.
text
,
self
.
course_run
.
course
.
short_description
)
self
.
assertEqual
(
content
.
find
(
'desc'
)
.
text
,
self
.
course_run
.
short_description
)
self
.
assertEqual
(
content
.
find
(
'purl'
)
.
text
,
self
.
course_run
.
course
.
marketing_url
)
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
(
'imgurl'
)
.
text
,
self
.
course_run
.
image
.
src
)
self
.
assertEqual
(
content
.
find
(
'price/actualp'
)
.
text
,
str
(
seat
.
price
))
self
.
assertEqual
(
content
.
find
(
'price/actualp'
)
.
text
,
str
(
seat
.
price
))
self
.
assertEqual
(
content
.
find
(
'currency'
)
.
text
,
seat
.
currency
.
code
)
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
):
def
test_dtd_with_valid_data
(
self
):
""" Verify the XML data produced by the endpoint conforms to the DTD file. """
""" Verify the XML data produced by the endpoint conforms to the DTD file. """
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment