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
81ea8027
Commit
81ea8027
authored
Nov 30, 2016
by
Matthew Piatetsky
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Expose marketing url for typeahead and only show published, non-hidden courses and active programs
ECOM-4738
parent
f7f11417
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
38 additions
and
8 deletions
+38
-8
course_discovery/apps/api/serializers.py
+2
-0
course_discovery/apps/api/tests/test_serializers.py
+4
-2
course_discovery/apps/api/v1/tests/test_views/test_search.py
+25
-4
course_discovery/apps/api/v1/views.py
+7
-2
No files found.
course_discovery/apps/api/serializers.py
View file @
81ea8027
...
@@ -965,6 +965,7 @@ class TypeaheadCourseRunSearchSerializer(serializers.Serializer):
...
@@ -965,6 +965,7 @@ class TypeaheadCourseRunSearchSerializer(serializers.Serializer):
org
=
serializers
.
CharField
()
org
=
serializers
.
CharField
()
title
=
serializers
.
CharField
()
title
=
serializers
.
CharField
()
key
=
serializers
.
CharField
()
key
=
serializers
.
CharField
()
marketing_url
=
serializers
.
CharField
()
class
Meta
:
class
Meta
:
fields
=
[
'key'
,
'title'
]
fields
=
[
'key'
,
'title'
]
...
@@ -975,6 +976,7 @@ class TypeaheadProgramSearchSerializer(serializers.Serializer):
...
@@ -975,6 +976,7 @@ class TypeaheadProgramSearchSerializer(serializers.Serializer):
uuid
=
serializers
.
CharField
()
uuid
=
serializers
.
CharField
()
title
=
serializers
.
CharField
()
title
=
serializers
.
CharField
()
type
=
serializers
.
CharField
()
type
=
serializers
.
CharField
()
marketing_url
=
serializers
.
CharField
()
def
get_orgs
(
self
,
result
):
def
get_orgs
(
self
,
result
):
authoring_organizations
=
[
json
.
loads
(
org
)
for
org
in
result
.
authoring_organization_bodies
]
authoring_organizations
=
[
json
.
loads
(
org
)
for
org
in
result
.
authoring_organization_bodies
]
...
...
course_discovery/apps/api/tests/test_serializers.py
View file @
81ea8027
...
@@ -1110,7 +1110,8 @@ class TypeaheadCourseRunSearchSerializerTests(TestCase):
...
@@ -1110,7 +1110,8 @@ class TypeaheadCourseRunSearchSerializerTests(TestCase):
expected
=
{
expected
=
{
'key'
:
course_run
.
key
,
'key'
:
course_run
.
key
,
'title'
:
course_run
.
title
,
'title'
:
course_run
.
title
,
'org'
:
course_run_key
.
org
'org'
:
course_run_key
.
org
,
'marketing_url'
:
course_run
.
marketing_url
,
}
}
self
.
assertDictEqual
(
serialized_course
.
data
,
expected
)
self
.
assertDictEqual
(
serialized_course
.
data
,
expected
)
...
@@ -1127,7 +1128,8 @@ class TypeaheadProgramSearchSerializerTests(TestCase):
...
@@ -1127,7 +1128,8 @@ class TypeaheadProgramSearchSerializerTests(TestCase):
'uuid'
:
str
(
program
.
uuid
),
'uuid'
:
str
(
program
.
uuid
),
'title'
:
program
.
title
,
'title'
:
program
.
title
,
'type'
:
program
.
type
.
name
,
'type'
:
program
.
type
.
name
,
'orgs'
:
list
(
program
.
authoring_organizations
.
all
()
.
values_list
(
'key'
,
flat
=
True
))
'orgs'
:
list
(
program
.
authoring_organizations
.
all
()
.
values_list
(
'key'
,
flat
=
True
)),
'marketing_url'
:
program
.
marketing_url
,
}
}
def
test_data
(
self
):
def
test_data
(
self
):
...
...
course_discovery/apps/api/v1/tests/test_views/test_search.py
View file @
81ea8027
...
@@ -311,7 +311,7 @@ class TypeaheadSearchViewTests(TypeaheadSerializationMixin, LoginMixin, APITestC
...
@@ -311,7 +311,7 @@ class TypeaheadSearchViewTests(TypeaheadSerializationMixin, LoginMixin, APITestC
""" Test typeahead response. """
""" Test typeahead response. """
title
=
"Python"
title
=
"Python"
course_run
=
CourseRunFactory
(
title
=
title
)
course_run
=
CourseRunFactory
(
title
=
title
)
program
=
ProgramFactory
(
title
=
title
)
program
=
ProgramFactory
(
title
=
title
,
status
=
ProgramStatus
.
Active
)
response
=
self
.
get_typeahead_response
(
title
)
response
=
self
.
get_typeahead_response
(
title
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertEqual
(
response
.
status_code
,
200
)
response_data
=
response
.
json
()
response_data
=
response
.
json
()
...
@@ -324,7 +324,7 @@ class TypeaheadSearchViewTests(TypeaheadSerializationMixin, LoginMixin, APITestC
...
@@ -324,7 +324,7 @@ class TypeaheadSearchViewTests(TypeaheadSerializationMixin, LoginMixin, APITestC
title
=
"Test"
title
=
"Test"
for
i
in
range
(
RESULT_COUNT
+
1
):
for
i
in
range
(
RESULT_COUNT
+
1
):
CourseRunFactory
(
title
=
"{}{}"
.
format
(
title
,
i
))
CourseRunFactory
(
title
=
"{}{}"
.
format
(
title
,
i
))
ProgramFactory
(
title
=
"{}{}"
.
format
(
title
,
i
))
ProgramFactory
(
title
=
"{}{}"
.
format
(
title
,
i
)
,
status
=
ProgramStatus
.
Active
)
response
=
self
.
get_typeahead_response
(
title
)
response
=
self
.
get_typeahead_response
(
title
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertEqual
(
response
.
status_code
,
200
)
response_data
=
response
.
json
()
response_data
=
response
.
json
()
...
@@ -336,7 +336,9 @@ class TypeaheadSearchViewTests(TypeaheadSerializationMixin, LoginMixin, APITestC
...
@@ -336,7 +336,9 @@ class TypeaheadSearchViewTests(TypeaheadSerializationMixin, LoginMixin, APITestC
title
=
"Design"
title
=
"Design"
authoring_organizations
=
OrganizationFactory
.
create_batch
(
3
)
authoring_organizations
=
OrganizationFactory
.
create_batch
(
3
)
course_run
=
CourseRunFactory
(
title
=
title
,
authoring_organizations
=
authoring_organizations
)
course_run
=
CourseRunFactory
(
title
=
title
,
authoring_organizations
=
authoring_organizations
)
program
=
ProgramFactory
(
title
=
title
,
authoring_organizations
=
authoring_organizations
)
program
=
ProgramFactory
(
title
=
title
,
authoring_organizations
=
authoring_organizations
,
status
=
ProgramStatus
.
Active
)
response
=
self
.
get_typeahead_response
(
title
)
response
=
self
.
get_typeahead_response
(
title
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertEqual
(
response
.
status_code
,
200
)
response_data
=
response
.
json
()
response_data
=
response
.
json
()
...
@@ -347,11 +349,30 @@ class TypeaheadSearchViewTests(TypeaheadSerializationMixin, LoginMixin, APITestC
...
@@ -347,11 +349,30 @@ class TypeaheadSearchViewTests(TypeaheadSerializationMixin, LoginMixin, APITestC
""" Test typeahead response with partial term search. """
""" Test typeahead response with partial term search. """
title
=
"Learn Data Science"
title
=
"Learn Data Science"
course_run
=
CourseRunFactory
(
title
=
title
)
course_run
=
CourseRunFactory
(
title
=
title
)
program
=
ProgramFactory
(
title
=
title
)
program
=
ProgramFactory
(
title
=
title
,
status
=
ProgramStatus
.
Active
)
query
=
"Data Sci"
query
=
"Data Sci"
response
=
self
.
get_typeahead_response
(
query
)
response
=
self
.
get_typeahead_response
(
query
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertEqual
(
response
.
status_code
,
200
)
response_data
=
response
.
json
()
response_data
=
response
.
json
()
expected_response_data
=
{
'course_runs'
:
[
self
.
serialize_course_run
(
course_run
)],
'programs'
:
[
self
.
serialize_program
(
program
)]
}
self
.
assertDictEqual
(
response_data
,
expected_response_data
)
def
test_unpublished_and_hidden_courses
(
self
):
""" Verify that typeahead does not return unpublished or hidden courses
or programs that are not active. """
title
=
"Supply Chain"
course_run
=
CourseRunFactory
(
title
=
title
)
CourseRunFactory
(
title
=
title
+
"_unpublished"
,
status
=
CourseRunStatus
.
Unpublished
)
CourseRunFactory
(
title
=
title
+
"_hidden"
,
hidden
=
True
)
program
=
ProgramFactory
(
title
=
title
,
status
=
ProgramStatus
.
Active
)
ProgramFactory
(
title
=
title
+
"_unpublished"
,
status
=
ProgramStatus
.
Unpublished
)
query
=
"Supply"
response
=
self
.
get_typeahead_response
(
query
)
self
.
assertEqual
(
response
.
status_code
,
200
)
response_data
=
response
.
json
()
expected_response_data
=
{
'course_runs'
:
[
self
.
serialize_course_run
(
course_run
)],
expected_response_data
=
{
'course_runs'
:
[
self
.
serialize_course_run
(
course_run
)],
'programs'
:
[
self
.
serialize_program
(
program
)]}
'programs'
:
[
self
.
serialize_program
(
program
)]}
self
.
assertDictEqual
(
response_data
,
expected_response_data
)
self
.
assertDictEqual
(
response_data
,
expected_response_data
)
...
...
course_discovery/apps/api/v1/views.py
View file @
81ea8027
...
@@ -32,6 +32,7 @@ from course_discovery.apps.api.renderers import AffiliateWindowXMLRenderer, Cour
...
@@ -32,6 +32,7 @@ from course_discovery.apps.api.renderers import AffiliateWindowXMLRenderer, Cour
from
course_discovery.apps.api.utils
import
cast2int
from
course_discovery.apps.api.utils
import
cast2int
from
course_discovery.apps.catalogs.models
import
Catalog
from
course_discovery.apps.catalogs.models
import
Catalog
from
course_discovery.apps.core.utils
import
SearchQuerySetWrapper
from
course_discovery.apps.core.utils
import
SearchQuerySetWrapper
from
course_discovery.apps.course_metadata.choices
import
ProgramStatus
from
course_discovery.apps.course_metadata.constants
import
COURSE_ID_REGEX
,
COURSE_RUN_ID_REGEX
from
course_discovery.apps.course_metadata.constants
import
COURSE_ID_REGEX
,
COURSE_RUN_ID_REGEX
from
course_discovery.apps.course_metadata.models
import
Course
,
CourseRun
,
Partner
,
Program
,
Seat
from
course_discovery.apps.course_metadata.models
import
Course
,
CourseRun
,
Partner
,
Program
,
Seat
...
@@ -688,8 +689,12 @@ class TypeaheadSearchView(APIView):
...
@@ -688,8 +689,12 @@ class TypeaheadSearchView(APIView):
def
get_results
(
self
,
query
):
def
get_results
(
self
,
query
):
query
=
'*{}*'
.
format
(
query
.
lower
())
query
=
'*{}*'
.
format
(
query
.
lower
())
course_runs
=
SearchQuerySet
()
.
models
(
CourseRun
)
.
raw_search
(
query
)[:
self
.
RESULT_COUNT
]
course_runs
=
SearchQuerySet
()
.
models
(
CourseRun
)
.
raw_search
(
query
)
programs
=
SearchQuerySet
()
.
models
(
Program
)
.
raw_search
(
query
)[:
self
.
RESULT_COUNT
]
course_runs
=
course_runs
.
filter
(
published
=
True
)
.
exclude
(
hidden
=
True
)
course_runs
=
course_runs
[:
self
.
RESULT_COUNT
]
programs
=
SearchQuerySet
()
.
models
(
Program
)
.
raw_search
(
query
)
programs
=
programs
.
filter
(
status
=
ProgramStatus
.
Active
)
programs
=
programs
[:
self
.
RESULT_COUNT
]
return
course_runs
,
programs
return
course_runs
,
programs
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
...
...
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