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
3951f428
Commit
3951f428
authored
Feb 24, 2017
by
tasawernawaz
Committed by
Tasawer Nawaz
Feb 24, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update the backend for UUID
ECOM-7185
parent
bad6e829
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
12 deletions
+38
-12
course_discovery/apps/course_metadata/lookups.py
+11
-4
course_discovery/apps/course_metadata/tests/test_lookups.py
+23
-4
course_discovery/apps/publisher/api/tests/test_views.py
+4
-4
No files found.
course_discovery/apps/course_metadata/lookups.py
View file @
3951f428
import
uuid
from
dal
import
autocomplete
from
django.db.models
import
Q
from
django.template.loader
import
render_to_string
...
...
@@ -57,11 +58,17 @@ class VideoAutocomplete(autocomplete.Select2QuerySetView):
class
PersonAutocomplete
(
autocomplete
.
Select2QuerySetView
):
def
get_queryset
(
self
):
if
self
.
request
.
user
.
is_authenticated
()
and
self
.
request
.
user
.
is_staff
:
q
s
=
Person
.
objects
.
all
()
q
ueryset
=
Person
.
objects
.
all
()
if
self
.
q
:
qs
=
qs
.
filter
(
Q
(
given_name__icontains
=
self
.
q
)
|
Q
(
family_name__icontains
=
self
.
q
))
return
qs
qs
=
queryset
.
filter
(
Q
(
given_name__icontains
=
self
.
q
)
|
Q
(
family_name__icontains
=
self
.
q
))
if
not
qs
:
try
:
q_uuid
=
uuid
.
UUID
(
self
.
q
)
.
hex
qs
=
queryset
.
filter
(
uuid
=
q_uuid
)
except
ValueError
:
pass
return
qs
return
[]
...
...
course_discovery/apps/course_metadata/tests/test_lookups.py
View file @
3951f428
...
...
@@ -167,16 +167,19 @@ class AutocompleteTests(TestCase):
position_title
=
'professor'
PositionFactory
.
create
(
person
=
self
.
instructors
[
0
],
title
=
position_title
,
organization
=
self
.
organizations
[
0
])
response
=
self
.
client
.
get
(
reverse
(
'admin_metadata:person-autocomplete'
))
response
=
self
.
client
.
get
(
reverse
(
'admin_metadata:person-autocomplete'
)
+
'?q={q}'
.
format
(
q
=
'ins'
)
)
self
.
assertContains
(
response
,
'<p>{position} at {organization}</p>'
.
format
(
position
=
position_title
,
organization
=
self
.
organizations
[
0
]
.
name
))
def
test_instructor_image_in_label
(
self
):
""" Verify that instructor label contains profile image url.
"""
response
=
self
.
client
.
get
(
reverse
(
'admin_metadata:person-autocomplete'
))
""" Verify that instructor label contains profile image url."""
response
=
self
.
client
.
get
(
reverse
(
'admin_metadata:person-autocomplete'
)
+
'?q={q}'
.
format
(
q
=
'ins'
)
)
self
.
assertContains
(
response
,
self
.
instructors
[
0
]
.
get_profile_image_url
)
self
.
assertContains
(
response
,
self
.
instructors
[
1
]
.
get_profile_image_url
)
...
...
@@ -185,3 +188,19 @@ class AutocompleteTests(TestCase):
self
.
assertEqual
(
response
.
status_code
,
200
)
data
=
json
.
loads
(
response
.
content
.
decode
(
'utf-8'
))
self
.
assertEqual
(
len
(
data
[
'results'
]),
expected_length
)
def
test_instructor_autocomplete_with_uuid
(
self
):
""" Verify instructor autocomplete returns the data with valid uuid. """
uuid
=
self
.
instructors
[
0
]
.
uuid
response
=
self
.
client
.
get
(
reverse
(
'admin_metadata:person-autocomplete'
)
+
'?q={q}'
.
format
(
q
=
uuid
)
)
self
.
_assert_response
(
response
,
1
)
def
test_instructor_autocomplete_with_invalid_uuid
(
self
):
""" Verify instructor autocomplete returns empty list without giving error. """
uuid
=
'invalid-uuid'
response
=
self
.
client
.
get
(
reverse
(
'admin_metadata:person-autocomplete'
)
+
'?q={q}'
.
format
(
q
=
uuid
)
)
self
.
_assert_response
(
response
,
0
)
course_discovery/apps/publisher/api/tests/test_views.py
View file @
3951f428
...
...
@@ -180,12 +180,12 @@ class OrganizationGroupUserViewTests(TestCase):
expected_results
=
[
{
"id"
:
self
.
org_user2
.
id
,
"full_name"
:
self
.
org_user2
.
username
},
{
"id"
:
self
.
org_user1
.
id
,
"full_name"
:
self
.
org_user1
.
full_name
},
{
"id"
:
self
.
org_user2
.
id
,
"full_name"
:
self
.
org_user2
.
username
}
]
...
...
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