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
4ffb74de
Commit
4ffb74de
authored
Sep 20, 2016
by
Clinton Blackburn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed broken tests
parent
83a32240
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
75 additions
and
145 deletions
+75
-145
course_discovery/apps/api/serializers.py
+1
-0
course_discovery/apps/api/tests/test_serializers.py
+69
-139
course_discovery/apps/course_metadata/tests/factories.py
+5
-6
No files found.
course_discovery/apps/api/serializers.py
View file @
4ffb74de
...
@@ -333,6 +333,7 @@ class ContainedCourseRunsSerializer(serializers.Serializer):
...
@@ -333,6 +333,7 @@ class ContainedCourseRunsSerializer(serializers.Serializer):
class
MinimalCourseSerializer
(
TimestampModelSerializer
):
class
MinimalCourseSerializer
(
TimestampModelSerializer
):
course_runs
=
MinimalCourseRunSerializer
(
many
=
True
)
owners
=
MinimalOrganizationSerializer
(
many
=
True
,
source
=
'authoring_organizations'
)
owners
=
MinimalOrganizationSerializer
(
many
=
True
,
source
=
'authoring_organizations'
)
class
Meta
:
class
Meta
:
...
...
course_discovery/apps/api/tests/test_serializers.py
View file @
4ffb74de
import
unittest
from
datetime
import
datetime
from
datetime
import
datetime
from
urllib.parse
import
urlencode
from
urllib.parse
import
urlencode
...
@@ -10,7 +9,7 @@ from rest_framework.test import APIRequestFactory
...
@@ -10,7 +9,7 @@ from rest_framework.test import APIRequestFactory
from
course_discovery.apps.api.fields
import
ImageField
from
course_discovery.apps.api.fields
import
ImageField
from
course_discovery.apps.api.serializers
import
(
from
course_discovery.apps.api.serializers
import
(
CatalogSerializer
,
Course
Serializer
,
Course
RunSerializer
,
ContainedCoursesSerializer
,
ImageSerializer
,
CatalogSerializer
,
CourseRunSerializer
,
ContainedCoursesSerializer
,
ImageSerializer
,
SubjectSerializer
,
PrerequisiteSerializer
,
VideoSerializer
,
OrganizationSerializer
,
SeatSerializer
,
SubjectSerializer
,
PrerequisiteSerializer
,
VideoSerializer
,
OrganizationSerializer
,
SeatSerializer
,
PersonSerializer
,
AffiliateWindowSerializer
,
ContainedCourseRunsSerializer
,
CourseRunSearchSerializer
,
PersonSerializer
,
AffiliateWindowSerializer
,
ContainedCourseRunsSerializer
,
CourseRunSearchSerializer
,
ProgramSerializer
,
ProgramSearchSerializer
,
ProgramCourseSerializer
,
NestedProgramSerializer
,
ProgramSerializer
,
ProgramSearchSerializer
,
ProgramCourseSerializer
,
NestedProgramSerializer
,
...
@@ -195,7 +194,6 @@ class CourseRunWithProgramsSerializerTests(TestCase):
...
@@ -195,7 +194,6 @@ class CourseRunWithProgramsSerializerTests(TestCase):
self
.
assertDictEqual
(
serializer
.
data
,
expected
)
self
.
assertDictEqual
(
serializer
.
data
,
expected
)
@unittest.skip
(
'This test is disabled until we can determine why assertDictEqual() fails for two equivalent inputs.'
)
class
FlattenedCourseRunWithCourseSerializerTests
(
TestCase
):
# pragma: no cover
class
FlattenedCourseRunWithCourseSerializerTests
(
TestCase
):
# pragma: no cover
def
serialize_seats
(
self
,
course_run
):
def
serialize_seats
(
self
,
course_run
):
seats
=
{
seats
=
{
...
@@ -245,7 +243,7 @@ class FlattenedCourseRunWithCourseSerializerTests(TestCase): # pragma: no cover
...
@@ -245,7 +243,7 @@ class FlattenedCourseRunWithCourseSerializerTests(TestCase): # pragma: no cover
def
get_expected_data
(
self
,
request
,
course_run
):
def
get_expected_data
(
self
,
request
,
course_run
):
course
=
course_run
.
course
course
=
course_run
.
course
serializer_context
=
{
'request'
:
request
}
serializer_context
=
{
'request'
:
request
}
expected
=
CourseRunSerializer
(
course_run
,
context
=
serializer_context
)
.
data
expected
=
dict
(
CourseRunSerializer
(
course_run
,
context
=
serializer_context
)
.
data
)
expected
.
update
({
expected
.
update
({
'subjects'
:
self
.
serialize_items
(
course
.
subjects
.
all
(),
'name'
),
'subjects'
:
self
.
serialize_items
(
course
.
subjects
.
all
(),
'name'
),
'seats'
:
self
.
serialize_seats
(
course_run
),
'seats'
:
self
.
serialize_seats
(
course_run
),
...
@@ -288,8 +286,6 @@ class FlattenedCourseRunWithCourseSerializerTests(TestCase): # pragma: no cover
...
@@ -288,8 +286,6 @@ class FlattenedCourseRunWithCourseSerializerTests(TestCase): # pragma: no cover
@ddt.ddt
@ddt.ddt
class
ProgramCourseSerializerTests
(
TestCase
):
class
ProgramCourseSerializerTests
(
TestCase
):
maxDiff
=
None
def
setUp
(
self
):
def
setUp
(
self
):
super
(
ProgramCourseSerializerTests
,
self
)
.
setUp
()
super
(
ProgramCourseSerializerTests
,
self
)
.
setUp
()
self
.
request
=
make_request
()
self
.
request
=
make_request
()
...
@@ -310,7 +306,6 @@ class ProgramCourseSerializerTests(TestCase):
...
@@ -310,7 +306,6 @@ class ProgramCourseSerializerTests(TestCase):
self
.
assertSequenceEqual
(
serializer
.
data
,
expected
)
self
.
assertSequenceEqual
(
serializer
.
data
,
expected
)
@unittest.skip
(
'@clintonb to fix later'
)
def
test_with_runs
(
self
):
def
test_with_runs
(
self
):
for
course
in
self
.
course_list
:
for
course
in
self
.
course_list
:
CourseRunFactory
.
create_batch
(
2
,
course
=
course
)
CourseRunFactory
.
create_batch
(
2
,
course
=
course
)
...
@@ -342,74 +337,46 @@ class ProgramCourseSerializerTests(TestCase):
...
@@ -342,74 +337,46 @@ class ProgramCourseSerializerTests(TestCase):
context
=
{
'request'
:
self
.
request
})
.
data
context
=
{
'request'
:
self
.
request
})
.
data
self
.
assertDictEqual
(
serializer
.
data
,
expected
)
self
.
assertDictEqual
(
serializer
.
data
,
expected
)
@unittest.skip
(
'@clintonb to fix later'
)
def
test_with_published_course_runs_only_context
(
self
):
@ddt.data
(
""" Verify setting the published_course_runs_only context value excludes unpublished course runs. """
[
CourseRunStatus
.
Unpublished
,
1
],
# Create a program and course. The course should have both published and un-published course runs.
[
CourseRunStatus
.
Unpublished
,
0
],
course
=
CourseFactory
()
[
CourseRunStatus
.
Published
,
1
],
courses
=
[
course
]
[
CourseRunStatus
.
Published
,
0
]
program
=
ProgramFactory
(
courses
=
courses
)
)
unpublished_course_run
=
CourseRunFactory
(
status
=
CourseRunStatus
.
Unpublished
,
course
=
course
)
@ddt.unpack
CourseRunFactory
(
status
=
CourseRunStatus
.
Published
,
course
=
course
)
def
test_with_published_only_querystring
(
self
,
course_run_status
,
published_course_runs_only
):
"""
# We do NOT expect the results to included the unpublished data
Test the serializer's ability to filter out course_runs based on
expected
=
MinimalCourseSerializer
(
courses
,
many
=
True
,
context
=
{
'request'
:
self
.
request
})
.
data
"published_course_runs_only" query string
expected
[
0
][
'course_runs'
]
=
[
course_run
for
course_run
in
expected
[
0
][
'course_runs'
]
if
"""
course_run
[
'uuid'
]
!=
str
(
unpublished_course_run
.
uuid
)]
expected
=
CourseSerializer
(
self
.
course_list
,
many
=
True
,
context
=
{
'request'
:
self
.
request
})
.
data
self
.
assertEqual
(
len
(
expected
[
0
][
'course_runs'
]),
1
)
for
course
in
self
.
course_list
:
CourseRunFactory
.
create_batch
(
2
,
status
=
course_run_status
,
course
=
course
)
serializer
=
ProgramCourseSerializer
(
serializer
=
ProgramCourseSerializer
(
self
.
course_list
,
courses
,
many
=
True
,
many
=
True
,
context
=
{
context
=
{
'request'
:
self
.
request
,
'request'
:
self
.
request
,
'program'
:
self
.
program
,
'program'
:
program
,
'published_course_runs_only'
:
published_course_runs_only
,
'published_course_runs_only'
:
True
,
}
}
)
)
validate_data
=
serializer
.
data
if
not
published_course_runs_only
or
course_run_status
!=
CourseRunStatus
.
Unpublished
:
self
.
assertSequenceEqual
(
serializer
.
data
,
expected
)
expected
=
MinimalCourseSerializer
(
self
.
course_list
,
many
=
True
,
context
=
{
'request'
:
self
.
request
})
.
data
self
.
assertSequenceEqual
(
validate_data
,
expected
)
class
ProgramSerializerTests
(
TestCase
):
class
ProgramSerializerTests
(
TestCase
):
maxDiff
=
None
def
get_expected_data
(
self
,
program
,
request
):
return
{
@unittest.skip
(
'@clintonb to fix later'
)
'uuid'
:
str
(
program
.
uuid
),
def
test_data
(
self
):
'title'
:
program
.
title
,
request
=
make_request
()
'subtitle'
:
program
.
subtitle
,
org_list
=
OrganizationFactory
.
create_batch
(
1
)
'type'
:
program
.
type
.
name
,
course_list
=
CourseFactory
.
create_batch
(
3
)
'marketing_slug'
:
program
.
marketing_slug
,
for
course
in
course_list
:
'marketing_url'
:
program
.
marketing_url
,
CourseRunFactory
.
create_batch
(
'card_image_url'
:
program
.
card_image_url
,
3
,
'video'
:
VideoSerializer
(
program
.
video
),
course
=
course
,
'banner_image'
:
{
enrollment_start
=
datetime
(
2014
,
1
,
1
),
start
=
datetime
(
2014
,
1
,
1
)
)
corporate_endorsements
=
CorporateEndorsementFactory
.
create_batch
(
1
)
individual_endorsements
=
EndorsementFactory
.
create_batch
(
1
)
staff
=
PersonFactory
.
create_batch
(
1
)
job_outlook_items
=
JobOutlookItemFactory
.
create_batch
(
1
)
expected_learning_items
=
ExpectedLearningItemFactory
.
create_batch
(
1
)
program
=
ProgramFactory
(
authoring_organizations
=
org_list
,
courses
=
course_list
,
credit_backing_organizations
=
org_list
,
corporate_endorsements
=
corporate_endorsements
,
individual_endorsements
=
individual_endorsements
,
expected_learning_items
=
expected_learning_items
,
staff
=
staff
,
job_outlook_items
=
job_outlook_items
,
)
program
.
banner_image
=
make_image_file
(
'test_banner.jpg'
)
program
.
save
()
serializer
=
ProgramSerializer
(
program
,
context
=
{
'request'
:
request
})
expected_banner_image_urls
=
{
size_key
:
{
size_key
:
{
'url'
:
'{}{}'
.
format
(
'url'
:
'{}{}'
.
format
(
'http://testserver'
,
'http://testserver'
,
...
@@ -419,18 +386,7 @@ class ProgramSerializerTests(TestCase):
...
@@ -419,18 +386,7 @@ class ProgramSerializerTests(TestCase):
'height'
:
program
.
banner_image
.
field
.
variations
[
size_key
][
'height'
]
'height'
:
program
.
banner_image
.
field
.
variations
[
size_key
][
'height'
]
}
}
for
size_key
in
program
.
banner_image
.
field
.
variations
for
size_key
in
program
.
banner_image
.
field
.
variations
}
},
expected
=
{
'uuid'
:
str
(
program
.
uuid
),
'title'
:
program
.
title
,
'subtitle'
:
program
.
subtitle
,
'type'
:
program
.
type
.
name
,
'marketing_slug'
:
program
.
marketing_slug
,
'marketing_url'
:
program
.
marketing_url
,
'card_image_url'
:
program
.
card_image_url
,
'video'
:
None
,
'banner_image'
:
expected_banner_image_urls
,
'authoring_organizations'
:
MinimalOrganizationSerializer
(
program
.
authoring_organizations
,
many
=
True
)
.
data
,
'authoring_organizations'
:
MinimalOrganizationSerializer
(
program
.
authoring_organizations
,
many
=
True
)
.
data
,
'credit_redemption_overview'
:
program
.
credit_redemption_overview
,
'credit_redemption_overview'
:
program
.
credit_redemption_overview
,
'courses'
:
ProgramCourseSerializer
(
'courses'
:
ProgramCourseSerializer
(
...
@@ -450,80 +406,56 @@ class ProgramSerializerTests(TestCase):
...
@@ -450,80 +406,56 @@ class ProgramSerializerTests(TestCase):
'job_outlook_items'
:
[
item
.
value
for
item
in
program
.
job_outlook_items
.
all
()],
'job_outlook_items'
:
[
item
.
value
for
item
in
program
.
job_outlook_items
.
all
()],
'languages'
:
[
serialize_language_to_code
(
l
)
for
l
in
program
.
languages
],
'languages'
:
[
serialize_language_to_code
(
l
)
for
l
in
program
.
languages
],
'weeks_to_complete'
:
program
.
weeks_to_complete
,
'weeks_to_complete'
:
program
.
weeks_to_complete
,
'max_hours_effort_per_week'
:
None
,
'max_hours_effort_per_week'
:
program
.
max_hours_effort_per_week
,
'min_hours_effort_per_week'
:
None
,
'min_hours_effort_per_week'
:
program
.
min_hours_effort_per_week
,
'overview'
:
None
,
'overview'
:
program
.
overview
,
'price_ranges'
:
[],
'price_ranges'
:
[],
'status'
:
program
.
status
,
'status'
:
program
.
status
,
'subjects'
:
[]
,
'subjects'
:
SubjectSerializer
(
program
.
subjects
,
many
=
True
)
,
'transcript_languages'
:
[],
'transcript_languages'
:
[
language
.
code
for
language
in
program
.
transcript_languages
],
}
}
def
create_program
(
self
):
organization
=
OrganizationFactory
()
courses
=
CourseFactory
.
create_batch
(
3
)
for
course
in
courses
:
CourseRunFactory
.
create_batch
(
2
,
course
=
course
,
staff
=
[
PersonFactory
()])
corporate_endorsements
=
CorporateEndorsementFactory
.
create_batch
(
1
)
individual_endorsements
=
EndorsementFactory
.
create_batch
(
1
)
job_outlook_items
=
JobOutlookItemFactory
.
create_batch
(
1
)
expected_learning_items
=
ExpectedLearningItemFactory
.
create_batch
(
1
)
program
=
ProgramFactory
(
authoring_organizations
=
[
organization
],
courses
=
courses
,
credit_backing_organizations
=
[
organization
],
corporate_endorsements
=
corporate_endorsements
,
individual_endorsements
=
individual_endorsements
,
expected_learning_items
=
expected_learning_items
,
job_outlook_items
=
job_outlook_items
,
banner_image
=
make_image_file
(
'test_banner.jpg'
)
)
return
program
def
test_data
(
self
):
request
=
make_request
()
program
=
self
.
create_program
()
expected
=
self
.
get_expected_data
(
program
,
request
)
serializer
=
ProgramSerializer
(
program
,
context
=
{
'request'
:
request
})
self
.
assertDictEqual
(
serializer
.
data
,
expected
)
self
.
assertDictEqual
(
serializer
.
data
,
expected
)
def
test_with_exclusions
(
self
):
def
test_
data_
with_exclusions
(
self
):
"""
"""
Verify we can specify program excluded_course_runs and the serializers will
Verify we can specify program excluded_course_runs and the serializers will
render the course_runs with exclusions
render the course_runs with exclusions
"""
"""
request
=
make_request
()
request
=
make_request
()
org_list
=
OrganizationFactory
.
create_batch
(
1
)
program
=
self
.
create_program
()
course_list
=
CourseFactory
.
create_batch
(
4
)
excluded_runs
=
[]
for
course
in
course_list
:
course_runs
=
CourseRunFactory
.
create_batch
(
3
,
course
=
course
,
enrollment_start
=
datetime
(
2014
,
1
,
1
),
start
=
datetime
(
2014
,
1
,
1
)
)
excluded_runs
.
append
(
course_runs
[
0
])
program
=
ProgramFactory
(
authoring_organizations
=
org_list
,
courses
=
course_list
,
excluded_course_runs
=
excluded_runs
)
serializer
=
ProgramSerializer
(
program
,
context
=
{
'request'
:
request
})
expected
=
{
excluded_course_run
=
program
.
courses
.
all
()[
0
]
.
course_runs
.
all
()[
0
]
'uuid'
:
str
(
program
.
uuid
),
program
.
excluded_course_runs
.
add
(
excluded_course_run
)
'title'
:
program
.
title
,
'subtitle'
:
program
.
subtitle
,
'type'
:
program
.
type
.
name
,
'marketing_slug'
:
program
.
marketing_slug
,
'marketing_url'
:
program
.
marketing_url
,
'card_image_url'
:
program
.
card_image_url
,
'banner_image'
:
{},
'video'
:
None
,
'authoring_organizations'
:
MinimalOrganizationSerializer
(
program
.
authoring_organizations
,
many
=
True
)
.
data
,
'credit_redemption_overview'
:
program
.
credit_redemption_overview
,
'courses'
:
ProgramCourseSerializer
(
program
.
courses
,
many
=
True
,
context
=
{
'request'
:
request
,
'program'
:
program
}
)
.
data
,
'corporate_endorsements'
:
CorporateEndorsementSerializer
(
program
.
corporate_endorsements
,
many
=
True
)
.
data
,
'credit_backing_organizations'
:
MinimalOrganizationSerializer
(
program
.
credit_backing_organizations
,
many
=
True
)
.
data
,
'expected_learning_items'
:
[],
'faq'
:
FAQSerializer
(
program
.
faq
,
many
=
True
)
.
data
,
'individual_endorsements'
:
EndorsementSerializer
(
program
.
individual_endorsements
,
many
=
True
)
.
data
,
'staff'
:
PersonSerializer
(
program
.
staff
,
many
=
True
)
.
data
,
'job_outlook_items'
:
[],
'languages'
:
[
serialize_language_to_code
(
l
)
for
l
in
program
.
languages
],
'weeks_to_complete'
:
program
.
weeks_to_complete
,
'max_hours_effort_per_week'
:
None
,
'min_hours_effort_per_week'
:
None
,
'overview'
:
None
,
'price_ranges'
:
[],
'status'
:
program
.
status
,
'subjects'
:
[],
'transcript_languages'
:
[],
}
expected
=
self
.
get_expected_data
(
program
,
request
)
serializer
=
ProgramSerializer
(
program
,
context
=
{
'request'
:
request
})
self
.
assertDictEqual
(
serializer
.
data
,
expected
)
self
.
assertDictEqual
(
serializer
.
data
,
expected
)
...
@@ -650,8 +582,6 @@ class VideoSerializerTests(TestCase):
...
@@ -650,8 +582,6 @@ class VideoSerializerTests(TestCase):
class
OrganizationSerializerTests
(
TestCase
):
class
OrganizationSerializerTests
(
TestCase
):
maxDiff
=
None
def
test_data
(
self
):
def
test_data
(
self
):
organization
=
OrganizationFactory
()
organization
=
OrganizationFactory
()
TAG
=
'test'
TAG
=
'test'
...
...
course_discovery/apps/course_metadata/tests/factories.py
View file @
4ffb74de
...
@@ -239,13 +239,17 @@ class ProgramFactory(factory.django.DjangoModelFactory):
...
@@ -239,13 +239,17 @@ class ProgramFactory(factory.django.DjangoModelFactory):
title
=
factory
.
Sequence
(
lambda
n
:
'test-program-{}'
.
format
(
n
))
# pylint: disable=unnecessary-lambda
title
=
factory
.
Sequence
(
lambda
n
:
'test-program-{}'
.
format
(
n
))
# pylint: disable=unnecessary-lambda
uuid
=
factory
.
LazyFunction
(
uuid4
)
uuid
=
factory
.
LazyFunction
(
uuid4
)
subtitle
=
'test-subtitle'
subtitle
=
FuzzyText
()
type
=
factory
.
SubFactory
(
ProgramTypeFactory
)
type
=
factory
.
SubFactory
(
ProgramTypeFactory
)
status
=
ProgramStatus
.
Unpublished
status
=
ProgramStatus
.
Unpublished
marketing_slug
=
factory
.
Sequence
(
lambda
n
:
'test-slug-{}'
.
format
(
n
))
# pylint: disable=unnecessary-lambda
marketing_slug
=
factory
.
Sequence
(
lambda
n
:
'test-slug-{}'
.
format
(
n
))
# pylint: disable=unnecessary-lambda
banner_image_url
=
FuzzyText
(
prefix
=
'https://example.com/program/banner'
)
banner_image_url
=
FuzzyText
(
prefix
=
'https://example.com/program/banner'
)
card_image_url
=
FuzzyText
(
prefix
=
'https://example.com/program/card'
)
card_image_url
=
FuzzyText
(
prefix
=
'https://example.com/program/card'
)
partner
=
factory
.
SubFactory
(
PartnerFactory
)
partner
=
factory
.
SubFactory
(
PartnerFactory
)
overview
=
FuzzyText
()
weeks_to_complete
=
FuzzyInteger
(
1
)
min_hours_effort_per_week
=
FuzzyInteger
(
2
)
max_hours_effort_per_week
=
FuzzyInteger
(
4
)
credit_redemption_overview
=
FuzzyText
()
credit_redemption_overview
=
FuzzyText
()
@factory.post_generation
@factory.post_generation
...
@@ -289,11 +293,6 @@ class ProgramFactory(factory.django.DjangoModelFactory):
...
@@ -289,11 +293,6 @@ class ProgramFactory(factory.django.DjangoModelFactory):
add_m2m_data
(
self
.
individual_endorsements
,
extracted
)
add_m2m_data
(
self
.
individual_endorsements
,
extracted
)
@factory.post_generation
@factory.post_generation
def
staff
(
self
,
create
,
extracted
,
**
kwargs
):
if
create
:
# pragma: no cover
add_m2m_data
(
self
.
staff
,
extracted
)
@factory.post_generation
def
job_outlook_items
(
self
,
create
,
extracted
,
**
kwargs
):
def
job_outlook_items
(
self
,
create
,
extracted
,
**
kwargs
):
if
create
:
# pragma: no cover
if
create
:
# pragma: no cover
add_m2m_data
(
self
.
job_outlook_items
,
extracted
)
add_m2m_data
(
self
.
job_outlook_items
,
extracted
)
...
...
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