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
428843ba
Commit
428843ba
authored
Oct 12, 2016
by
Renzo Lucioni
Committed by
GitHub
Oct 12, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Delete reduced program data switch (#379)
This switch is no longer necessary. ECOM-5791
parent
450c9313
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
36 additions
and
22 deletions
+36
-22
course_discovery/apps/api/migrations/0002_delete_reduced_program_data_switch.py
+18
-0
course_discovery/apps/api/v1/tests/test_views/mixins.py
+9
-2
course_discovery/apps/api/v1/tests/test_views/test_programs.py
+8
-18
course_discovery/apps/api/v1/views.py
+1
-2
No files found.
course_discovery/apps/api/migrations/0002_delete_reduced_program_data_switch.py
0 → 100644
View file @
428843ba
from
django.db
import
migrations
def
delete_switch
(
apps
,
schema_editor
):
"""Delete the reduced_program_data switch."""
Switch
=
apps
.
get_model
(
'waffle'
,
'Switch'
)
Switch
.
objects
.
filter
(
name
=
'reduced_program_data'
)
.
delete
()
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'waffle'
,
'0001_initial'
),
(
'api'
,
'0001_create_reduced_program_data_switch'
),
]
operations
=
[
migrations
.
RunPython
(
delete_switch
,
reverse_code
=
migrations
.
RunPython
.
noop
),
]
course_discovery/apps/api/v1/tests/test_views/mixins.py
View file @
428843ba
...
...
@@ -8,7 +8,8 @@ from rest_framework.test import APIRequestFactory
from
course_discovery.apps.api.serializers
import
(
CatalogSerializer
,
CourseWithProgramsSerializer
,
CourseSerializerExcludingClosedRuns
,
CourseRunWithProgramsSerializer
,
ProgramSerializer
,
FlattenedCourseRunWithCourseSerializer
CourseRunWithProgramsSerializer
,
MinimalProgramSerializer
,
ProgramSerializer
,
FlattenedCourseRunWithCourseSerializer
,
)
...
...
@@ -41,7 +42,13 @@ class SerializationMixin(object):
return
self
.
_serialize_object
(
CourseRunWithProgramsSerializer
,
run
,
many
,
format
,
extra_context
)
def
serialize_program
(
self
,
program
,
many
=
False
,
format
=
None
,
extra_context
=
None
):
return
self
.
_serialize_object
(
ProgramSerializer
,
program
,
many
,
format
,
extra_context
)
return
self
.
_serialize_object
(
MinimalProgramSerializer
if
many
else
ProgramSerializer
,
program
,
many
,
format
,
extra_context
)
def
serialize_catalog_course
(
self
,
course
,
many
=
False
,
format
=
None
,
extra_context
=
None
):
return
self
.
_serialize_object
(
CourseSerializerExcludingClosedRuns
,
course
,
many
,
format
,
extra_context
)
...
...
course_discovery/apps/api/v1/tests/test_views/test_programs.py
View file @
428843ba
...
...
@@ -2,14 +2,13 @@ import ddt
from
django.core.urlresolvers
import
reverse
from
rest_framework.test
import
APITestCase
,
APIRequestFactory
from
course_discovery.apps.api.serializers
import
MinimalProgramSerializer
,
ProgramSerializer
from
course_discovery.apps.api.serializers
import
MinimalProgramSerializer
from
course_discovery.apps.api.v1.views
import
ProgramViewSet
from
course_discovery.apps.api.v1.tests.test_views.mixins
import
SerializationMixin
from
course_discovery.apps.core.tests.factories
import
USER_PASSWORD
,
UserFactory
from
course_discovery.apps.core.tests.helpers
import
make_image_file
from
course_discovery.apps.course_metadata.choices
import
ProgramStatus
from
course_discovery.apps.course_metadata.models
import
Program
from
course_discovery.apps.course_metadata.tests
import
toggle_switch
from
course_discovery.apps.course_metadata.tests.factories
import
(
CourseFactory
,
CourseRunFactory
,
VideoFactory
,
OrganizationFactory
,
PersonFactory
,
ProgramFactory
,
CorporateEndorsementFactory
,
EndorsementFactory
,
JobOutlookItemFactory
,
ExpectedLearningItemFactory
...
...
@@ -114,14 +113,14 @@ class ProgramViewSetTests(SerializationMixin, APITestCase):
""" Verify the endpoint returns a list of all programs. """
expected
=
[
self
.
create_program
()
for
__
in
range
(
3
)]
expected
.
reverse
()
self
.
assert_list_results
(
self
.
list_path
,
expected
,
36
)
self
.
assert_list_results
(
self
.
list_path
,
expected
,
11
)
def
test_filter_by_type
(
self
):
""" Verify that the endpoint filters programs to those of a given type. """
program_type_name
=
'foo'
program
=
ProgramFactory
(
type__name
=
program_type_name
)
url
=
self
.
list_path
+
'?type='
+
program_type_name
self
.
assert_list_results
(
url
,
[
program
],
14
)
self
.
assert_list_results
(
url
,
[
program
],
8
)
url
=
self
.
list_path
+
'?type=bar'
self
.
assert_list_results
(
url
,
[],
4
)
...
...
@@ -136,11 +135,11 @@ class ProgramViewSetTests(SerializationMixin, APITestCase):
# Create a third program, which should be filtered out.
ProgramFactory
()
self
.
assert_list_results
(
url
,
expected
,
14
)
self
.
assert_list_results
(
url
,
expected
,
8
)
@ddt.data
(
(
ProgramStatus
.
Unpublished
,
False
,
4
),
(
ProgramStatus
.
Active
,
True
,
14
),
(
ProgramStatus
.
Active
,
True
,
8
),
)
@ddt.unpack
def
test_filter_by_marketable
(
self
,
status
,
is_marketable
,
expected_query_count
):
...
...
@@ -158,17 +157,8 @@ class ProgramViewSetTests(SerializationMixin, APITestCase):
""" Verify the endpoint returns marketing URLs without UTM parameters. """
url
=
self
.
list_path
+
'?exclude_utm=1'
program
=
self
.
create_program
()
self
.
assert_list_results
(
url
,
[
program
],
32
,
extra_context
=
{
'exclude_utm'
:
1
})
self
.
assert_list_results
(
url
,
[
program
],
11
,
extra_context
=
{
'exclude_utm'
:
1
})
@ddt.data
(
True
,
False
)
def
test_minimal_serializer_use
(
self
,
is_minimal
):
def
test_minimal_serializer_use
(
self
):
""" Verify that the list view uses the minimal serializer. """
toggle_switch
(
'reduced_program_data'
,
active
=
is_minimal
)
action_serializer_mapping
=
{
'list'
:
MinimalProgramSerializer
if
is_minimal
else
ProgramSerializer
,
'detail'
:
ProgramSerializer
,
}
for
action
,
serializer
in
action_serializer_mapping
.
items
():
self
.
assertEqual
(
ProgramViewSet
(
action
=
action
)
.
get_serializer_class
(),
serializer
)
self
.
assertEqual
(
ProgramViewSet
(
action
=
'list'
)
.
get_serializer_class
(),
MinimalProgramSerializer
)
course_discovery/apps/api/v1/views.py
View file @
428843ba
...
...
@@ -22,7 +22,6 @@ from rest_framework.exceptions import PermissionDenied, ParseError
from
rest_framework.filters
import
DjangoFilterBackend
from
rest_framework.permissions
import
IsAuthenticated
from
rest_framework.response
import
Response
import
waffle
from
course_discovery.apps.api
import
filters
from
course_discovery.apps.api
import
serializers
...
...
@@ -420,7 +419,7 @@ class ProgramViewSet(viewsets.ReadOnlyModelViewSet):
filter_class
=
filters
.
ProgramFilter
def
get_serializer_class
(
self
):
if
self
.
action
==
'list'
and
waffle
.
switch_is_active
(
'reduced_program_data'
)
:
if
self
.
action
==
'list'
:
return
serializers
.
MinimalProgramSerializer
return
serializers
.
ProgramSerializer
...
...
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