Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
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
edx-platform
Commits
7e38c3ad
Commit
7e38c3ad
authored
Feb 14, 2014
by
thedeadparrot
Committed by
Julia Hansbrough
Feb 14, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use a given default for getting a preference
parent
48686793
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
6 deletions
+10
-6
common/djangoapps/user_api/models.py
+3
-3
common/djangoapps/user_api/tests/test_views.py
+7
-3
No files found.
common/djangoapps/user_api/models.py
View file @
7e38c3ad
...
...
@@ -24,15 +24,15 @@ class UserPreference(models.Model):
user_pref
.
save
()
@classmethod
def
get_preference
(
cls
,
user
,
preference_key
):
def
get_preference
(
cls
,
user
,
preference_key
,
default
=
None
):
"""
Gets the user preference value for a given key
Returns
None
if there isn't a preference for the given key
Returns
the given default
if there isn't a preference for the given key
"""
try
:
user_pref
=
cls
.
objects
.
get
(
user
=
user
,
key
=
preference_key
)
return
user_pref
.
value
except
cls
.
DoesNotExist
:
return
None
return
default
common/djangoapps/user_api/tests/test_views.py
View file @
7e38c3ad
...
...
@@ -83,6 +83,10 @@ class ApiTestCase(TestCase):
"""Assert that the given response has the status code 403"""
self
.
assertEqual
(
response
.
status_code
,
403
)
def
assertHttpBadRequest
(
self
,
response
):
"""Assert that the given response has the status code 403"""
self
.
assertEqual
(
response
.
status_code
,
400
)
def
assertHttpMethodNotAllowed
(
self
,
response
):
"""Assert that the given response has the status code 405"""
self
.
assertEqual
(
response
.
status_code
,
405
)
...
...
@@ -358,7 +362,7 @@ class UserPreferenceViewSetTest(UserApiTestCase):
)
class
TestLanguageSetting
(
TestCase
):
class
TestLanguageSetting
(
Api
TestCase
):
"""
Test setting languages
"""
...
...
@@ -369,7 +373,7 @@ class TestLanguageSetting(TestCase):
lang
=
'en'
response
=
self
.
client
.
post
(
reverse
(
'user_api_set_language'
),
{
'language'
:
lang
})
self
.
assert
Equal
(
response
.
status_code
,
200
)
self
.
assert
HttpOK
(
response
)
user_pref
=
UserPreference
.
get_preference
(
user
,
LANGUAGE_KEY
)
self
.
assertEqual
(
user_pref
,
lang
)
...
...
@@ -379,6 +383,6 @@ class TestLanguageSetting(TestCase):
response
=
self
.
client
.
post
(
reverse
(
'user_api_set_language'
))
self
.
assert
Equal
(
response
.
status_code
,
400
)
self
.
assert
HttpBadRequest
(
response
)
self
.
assertIsNone
(
UserPreference
.
get_preference
(
user
,
LANGUAGE_KEY
))
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