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
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
10 deletions
+36
-10
course_discovery/apps/course_metadata/lookups.py
+9
-2
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
dal
import
autocomplete
from
django.db.models
import
Q
from
django.db.models
import
Q
from
django.template.loader
import
render_to_string
from
django.template.loader
import
render_to_string
...
@@ -57,9 +58,15 @@ class VideoAutocomplete(autocomplete.Select2QuerySetView):
...
@@ -57,9 +58,15 @@ class VideoAutocomplete(autocomplete.Select2QuerySetView):
class
PersonAutocomplete
(
autocomplete
.
Select2QuerySetView
):
class
PersonAutocomplete
(
autocomplete
.
Select2QuerySetView
):
def
get_queryset
(
self
):
def
get_queryset
(
self
):
if
self
.
request
.
user
.
is_authenticated
()
and
self
.
request
.
user
.
is_staff
:
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
:
if
self
.
q
:
qs
=
qs
.
filter
(
Q
(
given_name__icontains
=
self
.
q
)
|
Q
(
family_name__icontains
=
self
.
q
))
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
qs
...
...
course_discovery/apps/course_metadata/tests/test_lookups.py
View file @
3951f428
...
@@ -167,16 +167,19 @@ class AutocompleteTests(TestCase):
...
@@ -167,16 +167,19 @@ class AutocompleteTests(TestCase):
position_title
=
'professor'
position_title
=
'professor'
PositionFactory
.
create
(
person
=
self
.
instructors
[
0
],
title
=
position_title
,
organization
=
self
.
organizations
[
0
])
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
(
self
.
assertContains
(
response
,
'<p>{position} at {organization}</p>'
.
format
(
position
=
position_title
,
position
=
position_title
,
organization
=
self
.
organizations
[
0
]
.
name
))
organization
=
self
.
organizations
[
0
]
.
name
))
def
test_instructor_image_in_label
(
self
):
def
test_instructor_image_in_label
(
self
):
""" Verify that instructor label contains profile image url.
""" Verify that instructor label contains profile image url."""
"""
response
=
self
.
client
.
get
(
response
=
self
.
client
.
get
(
reverse
(
'admin_metadata:person-autocomplete'
))
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
[
0
]
.
get_profile_image_url
)
self
.
assertContains
(
response
,
self
.
instructors
[
1
]
.
get_profile_image_url
)
self
.
assertContains
(
response
,
self
.
instructors
[
1
]
.
get_profile_image_url
)
...
@@ -185,3 +188,19 @@ class AutocompleteTests(TestCase):
...
@@ -185,3 +188,19 @@ class AutocompleteTests(TestCase):
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertEqual
(
response
.
status_code
,
200
)
data
=
json
.
loads
(
response
.
content
.
decode
(
'utf-8'
))
data
=
json
.
loads
(
response
.
content
.
decode
(
'utf-8'
))
self
.
assertEqual
(
len
(
data
[
'results'
]),
expected_length
)
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):
...
@@ -180,12 +180,12 @@ class OrganizationGroupUserViewTests(TestCase):
expected_results
=
[
expected_results
=
[
{
{
"id"
:
self
.
org_user2
.
id
,
"full_name"
:
self
.
org_user2
.
username
},
{
"id"
:
self
.
org_user1
.
id
,
"id"
:
self
.
org_user1
.
id
,
"full_name"
:
self
.
org_user1
.
full_name
"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