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
892159d2
Commit
892159d2
authored
Aug 15, 2016
by
Michael Frey
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create course run image from course api if no marketing site exists for partner
parent
1f8b7db9
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
6 deletions
+31
-6
course_discovery/apps/course_metadata/data_loaders/api.py
+14
-1
course_discovery/apps/course_metadata/data_loaders/tests/test_api.py
+11
-3
course_discovery/apps/course_metadata/tests/mock_data.py
+6
-2
No files found.
course_discovery/apps/course_metadata/data_loaders/api.py
View file @
892159d2
...
@@ -6,7 +6,7 @@ from opaque_keys.edx.keys import CourseKey
...
@@ -6,7 +6,7 @@ from opaque_keys.edx.keys import CourseKey
from
course_discovery.apps.core.models
import
Currency
from
course_discovery.apps.core.models
import
Currency
from
course_discovery.apps.course_metadata.data_loaders
import
AbstractDataLoader
from
course_discovery.apps.course_metadata.data_loaders
import
AbstractDataLoader
from
course_discovery.apps.course_metadata.models
import
(
from
course_discovery.apps.course_metadata.models
import
(
Video
,
Organization
,
Seat
,
CourseRun
,
Program
,
Course
,
CourseOrganization
,
ProgramType
,
Image
,
Video
,
Organization
,
Seat
,
CourseRun
,
Program
,
Course
,
CourseOrganization
,
ProgramType
,
)
)
logger
=
logging
.
getLogger
(
__name__
)
logger
=
logging
.
getLogger
(
__name__
)
...
@@ -122,9 +122,22 @@ class CoursesApiDataLoader(AbstractDataLoader):
...
@@ -122,9 +122,22 @@ class CoursesApiDataLoader(AbstractDataLoader):
'video'
:
self
.
get_courserun_video
(
body
),
'video'
:
self
.
get_courserun_video
(
body
),
'pacing_type'
:
self
.
get_pacing_type
(
body
),
'pacing_type'
:
self
.
get_pacing_type
(
body
),
}
}
# If there is no marketing site setup for this partner, use the image from the course API.
# If there is a marketing site defined, it takes prededence.
if
not
self
.
partner
.
marketing_site_url_root
:
defaults
.
update
({
'image'
:
self
.
get_courserun_image
(
body
)})
CourseRun
.
objects
.
update_or_create
(
key
=
body
[
'id'
],
defaults
=
defaults
)
CourseRun
.
objects
.
update_or_create
(
key
=
body
[
'id'
],
defaults
=
defaults
)
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_pacing_type
(
self
,
body
):
def
get_pacing_type
(
self
,
body
):
pacing
=
body
.
get
(
'pacing'
)
pacing
=
body
.
get
(
'pacing'
)
...
...
course_discovery/apps/course_metadata/data_loaders/tests/test_api.py
View file @
892159d2
...
@@ -126,7 +126,7 @@ class CoursesApiDataLoaderTests(ApiClientTestMixin, DataLoaderTestMixin, TestCas
...
@@ -126,7 +126,7 @@ class CoursesApiDataLoaderTests(ApiClientTestMixin, DataLoaderTestMixin, TestCas
)
)
return
bodies
return
bodies
def
assert_course_run_loaded
(
self
,
body
):
def
assert_course_run_loaded
(
self
,
body
,
use_marketing_url
=
True
):
""" Assert a CourseRun corresponding to the specified data body was properly loaded into the database. """
""" Assert a CourseRun corresponding to the specified data body was properly loaded into the database. """
# Validate the Course
# Validate the Course
...
@@ -148,11 +148,19 @@ class CoursesApiDataLoaderTests(ApiClientTestMixin, DataLoaderTestMixin, TestCas
...
@@ -148,11 +148,19 @@ class CoursesApiDataLoaderTests(ApiClientTestMixin, DataLoaderTestMixin, TestCas
self
.
assertEqual
(
course_run
.
enrollment_end
,
AbstractDataLoader
.
parse_date
(
body
[
'enrollment_end'
]))
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
.
pacing_type
,
self
.
loader
.
get_pacing_type
(
body
))
self
.
assertEqual
(
course_run
.
video
,
self
.
loader
.
get_courserun_video
(
body
))
self
.
assertEqual
(
course_run
.
video
,
self
.
loader
.
get_courserun_video
(
body
))
if
use_marketing_url
:
self
.
assertEqual
(
course_run
.
image
,
None
)
else
:
self
.
assertEqual
(
course_run
.
image
,
self
.
loader
.
get_courserun_image
(
body
))
@responses.activate
@responses.activate
def
test_ingest
(
self
):
@ddt.data
(
True
,
False
)
def
test_ingest
(
self
,
use_marketing_url
):
""" Verify the method ingests data from the Courses API. """
""" Verify the method ingests data from the Courses API. """
api_data
=
self
.
mock_api
()
api_data
=
self
.
mock_api
()
if
not
use_marketing_url
:
self
.
partner
.
marketing_site_url_root
=
None
self
.
assertEqual
(
Course
.
objects
.
count
(),
0
)
self
.
assertEqual
(
Course
.
objects
.
count
(),
0
)
self
.
assertEqual
(
CourseRun
.
objects
.
count
(),
0
)
self
.
assertEqual
(
CourseRun
.
objects
.
count
(),
0
)
...
@@ -166,7 +174,7 @@ class CoursesApiDataLoaderTests(ApiClientTestMixin, DataLoaderTestMixin, TestCas
...
@@ -166,7 +174,7 @@ class CoursesApiDataLoaderTests(ApiClientTestMixin, DataLoaderTestMixin, TestCas
self
.
assertEqual
(
CourseRun
.
objects
.
count
(),
expected_num_course_runs
)
self
.
assertEqual
(
CourseRun
.
objects
.
count
(),
expected_num_course_runs
)
for
datum
in
api_data
:
for
datum
in
api_data
:
self
.
assert_course_run_loaded
(
datum
)
self
.
assert_course_run_loaded
(
datum
,
use_marketing_url
)
# Verify multiple calls to ingest data do NOT result in data integrity errors.
# Verify multiple calls to ingest data do NOT result in data integrity errors.
self
.
loader
.
ingest
()
self
.
loader
.
ingest
()
...
...
course_discovery/apps/course_metadata/tests/mock_data.py
View file @
892159d2
...
@@ -53,7 +53,7 @@ COURSES_API_BODIES = [
...
@@ -53,7 +53,7 @@ COURSES_API_BODIES = [
},
},
'course_video'
:
{
'course_video'
:
{
'uri'
:
None
'uri'
:
None
}
}
,
},
},
'name'
:
'Evolution of the Human Sociality: A Quest for the Origin of Our Social Behavior'
,
'name'
:
'Evolution of the Human Sociality: A Quest for the Origin of Our Social Behavior'
,
'number'
:
'000x'
,
'number'
:
'000x'
,
...
@@ -76,7 +76,11 @@ COURSES_API_BODIES = [
...
@@ -76,7 +76,11 @@ COURSES_API_BODIES = [
},
},
'course_video'
:
{
'course_video'
:
{
'uri'
:
None
'uri'
:
None
}
},
'image'
:
{
'raw'
:
'http://example.com/image.jpg'
,
},
},
},
'name'
:
'Evolution of the Human Sociality: A Quest for the Origin of Our Social Behavior'
,
'name'
:
'Evolution of the Human Sociality: A Quest for the Origin of Our Social Behavior'
,
'number'
:
'000x'
,
'number'
:
'000x'
,
...
...
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