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
8737df79
Commit
8737df79
authored
Aug 08, 2016
by
Umar Nawaz
Committed by
GitHub
Aug 08, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #211 from edx/unawaz/ECOM-4524-get-course-image-from-drupal
changing image source from platform to drupal
parents
90bef354
a69aa009
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
30 deletions
+28
-30
course_discovery/apps/course_metadata/data_loaders.py
+11
-10
course_discovery/apps/course_metadata/tests/mock_data.py
+3
-0
course_discovery/apps/course_metadata/tests/test_data_loaders.py
+14
-20
No files found.
course_discovery/apps/course_metadata/data_loaders.py
View file @
8737df79
...
...
@@ -240,8 +240,8 @@ class CoursesApiDataLoader(AbstractDataLoader):
'short_description'
:
body
[
'short_description'
],
'video'
:
self
.
get_courserun_video
(
body
),
'pacing_type'
:
self
.
get_pacing_type
(
body
),
'image'
:
self
.
get_courserun_image
(
body
),
}
CourseRun
.
objects
.
update_or_create
(
key
=
body
[
'id'
],
defaults
=
defaults
)
def
get_pacing_type
(
self
,
body
):
...
...
@@ -257,15 +257,6 @@ class CoursesApiDataLoader(AbstractDataLoader):
else
:
return
None
def
get_courserun_image
(
self
,
body
):
image
=
None
image_url
=
body
[
'media'
]
.
get
(
'image'
,
{})
.
get
(
'raw'
)
if
image_url
:
image
,
__
=
Image
.
objects
.
get_or_create
(
src
=
image_url
)
return
image
def
get_courserun_video
(
self
,
body
):
video
=
None
video_url
=
body
[
'media'
]
.
get
(
'course_video'
,
{})
.
get
(
'uri'
)
...
...
@@ -378,6 +369,7 @@ class DrupalApiDataLoader(AbstractDataLoader):
course_run
.
marketing_url
=
urljoin
(
self
.
partner
.
marketing_site_url_root
,
body
[
'course_about_uri'
])
course_run
.
start
=
self
.
parse_date
(
body
[
'start'
])
course_run
.
end
=
self
.
parse_date
(
body
[
'end'
])
course_run
.
image
=
self
.
get_courserun_image
(
body
)
self
.
set_staff
(
course_run
,
body
)
...
...
@@ -422,6 +414,15 @@ class DrupalApiDataLoader(AbstractDataLoader):
html_converter
.
body_width
=
None
return
html_converter
.
handle
(
stripped
)
.
strip
()
def
get_courserun_image
(
self
,
body
):
image
=
None
image_url
=
body
[
'image'
]
if
image_url
:
image
,
__
=
Image
.
objects
.
get_or_create
(
src
=
image_url
)
return
image
class
EcommerceApiDataLoader
(
AbstractDataLoader
):
""" Loads course seats from the E-Commerce API. """
...
...
course_discovery/apps/course_metadata/tests/mock_data.py
View file @
8737df79
...
...
@@ -310,6 +310,7 @@ MARKETING_API_BODY = {
'title'
:
EXISTING_COURSE_AND_RUN_DATA
[
0
][
'title'
],
'start'
:
'2015-06-15T13:00:00Z'
,
'end'
:
'2015-12-15T13:00:00Z'
,
'image'
:
'http://example.com/course1-image.jpg'
,
'level'
:
{
'title'
:
'Introductory'
,
},
...
...
@@ -357,6 +358,7 @@ MARKETING_API_BODY = {
}],
'current_language'
:
EXISTING_COURSE_AND_RUN_DATA
[
1
][
'current_language'
],
'subtitle'
:
'Testing 201'
,
'image'
:
'http://example.com/course1-image.jpg'
,
'description'
:
"how to test better"
,
'sponsors'
:
[],
'staff'
:
[{
...
...
@@ -382,6 +384,7 @@ MARKETING_API_BODY = {
}],
'current_language'
:
'en-us'
,
'subtitle'
:
'Nope'
,
'image'
:
'http://example.com/course2-detail.jpg'
,
'description'
:
'what is fake?'
,
'sponsors'
:
[{
'uuid'
:
'123abc'
,
...
...
course_discovery/apps/course_metadata/tests/test_data_loaders.py
View file @
8737df79
...
...
@@ -212,7 +212,6 @@ class CoursesApiDataLoaderTests(ApiClientTestMixin, DataLoaderTestMixin, TestCas
self
.
assertEqual
(
course_run
.
enrollment_start
,
AbstractDataLoader
.
parse_date
(
body
[
'enrollment_start'
]))
self
.
assertEqual
(
course_run
.
enrollment_end
,
AbstractDataLoader
.
parse_date
(
body
[
'enrollment_end'
]))
self
.
assertEqual
(
course_run
.
pacing_type
,
self
.
loader
.
get_pacing_type
(
body
))
self
.
assertEqual
(
course_run
.
image
,
self
.
loader
.
get_courserun_image
(
body
))
self
.
assertEqual
(
course_run
.
video
,
self
.
loader
.
get_courserun_video
(
body
))
@responses.activate
...
...
@@ -272,25 +271,6 @@ class CoursesApiDataLoaderTests(ApiClientTestMixin, DataLoaderTestMixin, TestCas
@ddt.unpack
@ddt.data
(
({},
None
),
({
'image'
:
{}},
None
),
({
'image'
:
{
'raw'
:
None
}},
None
),
({
'image'
:
{
'raw'
:
'http://example.com/image.jpg'
}},
'http://example.com/image.jpg'
),
)
def
test_get_courserun_image
(
self
,
media_body
,
expected_image_url
):
""" Verify the method returns an Image object with the correct URL. """
body
=
{
'media'
:
media_body
}
actual
=
self
.
loader
.
get_courserun_image
(
body
)
if
expected_image_url
:
self
.
assertEqual
(
actual
.
src
,
expected_image_url
)
else
:
self
.
assertIsNone
(
actual
)
@ddt.unpack
@ddt.data
(
(
None
,
None
),
(
'http://example.com/image.mp4'
,
'http://example.com/image.mp4'
),
)
...
...
@@ -464,6 +444,20 @@ class DrupalApiDataLoaderTests(ApiClientTestMixin, DataLoaderTestMixin, TestCase
)
mock_logger
.
exception
.
assert_called_with
(
msg
)
@ddt.unpack
@ddt.data
(
({
'image'
:
{}},
None
),
({
'image'
:
'http://example.com/image.jpg'
},
'http://example.com/image.jpg'
),
)
def
test_get_courserun_image
(
self
,
media_body
,
expected_image_url
):
""" Verify the method returns an Image object with the correct URL. """
actual
=
self
.
loader
.
get_courserun_image
(
media_body
)
if
expected_image_url
:
self
.
assertEqual
(
actual
.
src
,
expected_image_url
)
else
:
self
.
assertIsNone
(
actual
)
@ddt.data
(
(
''
,
''
),
(
'<h1>foo</h1>'
,
'# foo'
),
...
...
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