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
c3e609fe
Commit
c3e609fe
authored
Jul 30, 2013
by
Kevin Chugh
Browse files
Options
Browse Files
Download
Plain Diff
fix merge conflict
parents
5c91edd4
908fd46f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
15 deletions
+37
-15
lms/djangoapps/notification_prefs/tests.py
+31
-1
lms/djangoapps/notification_prefs/views.py
+6
-14
No files found.
lms/djangoapps/notification_prefs/tests.py
View file @
c3e609fe
import
json
from
django.contrib.auth.models
import
AnonymousUser
from
django.core.exceptions
import
PermissionDenied
from
django.http
import
Http404
...
...
@@ -7,7 +9,7 @@ from django.test.utils import override_settings
from
mock
import
Mock
,
patch
from
notification_prefs
import
NOTIFICATION_PREF_KEY
from
notification_prefs.views
import
ajax_enable
,
ajax_disable
,
unsubscribe
from
notification_prefs.views
import
ajax_enable
,
ajax_disable
,
ajax_status
,
unsubscribe
from
student.tests.factories
import
UserFactory
from
user_api.models
import
UserPreference
...
...
@@ -57,6 +59,34 @@ class NotificationPrefViewTest(TestCase):
UserPreference
.
objects
.
filter
(
user
=
user
,
key
=
NOTIFICATION_PREF_KEY
)
.
exists
()
)
# AJAX status view
def
test_ajax_status_get_0
(
self
):
request
=
self
.
request_factory
.
get
(
"dummy"
)
request
.
user
=
self
.
user
response
=
ajax_status
(
request
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertEqual
(
json
.
loads
(
response
.
content
),
{
"status"
:
0
})
def
test_ajax_status_get_1
(
self
):
self
.
create_prefs
()
request
=
self
.
request_factory
.
get
(
"dummy"
)
request
.
user
=
self
.
user
response
=
ajax_status
(
request
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertEqual
(
json
.
loads
(
response
.
content
),
{
"status"
:
1
})
def
test_ajax_status_post
(
self
):
request
=
self
.
request_factory
.
post
(
"dummy"
)
request
.
user
=
self
.
user
response
=
ajax_status
(
request
)
self
.
assertEqual
(
response
.
status_code
,
405
)
def
test_ajax_status_anon_user
(
self
):
request
=
self
.
request_factory
.
get
(
"dummy"
)
request
.
user
=
AnonymousUser
()
self
.
assertRaises
(
PermissionDenied
,
ajax_status
,
request
)
# AJAX enable view
def
test_ajax_enable_get
(
self
):
...
...
lms/djangoapps/notification_prefs/views.py
View file @
c3e609fe
from
base64
import
urlsafe_b64encode
,
urlsafe_b64decode
from
hashlib
import
sha256
import
json
from
Crypto.Cipher
import
AES
from
Crypto
import
Random
...
...
@@ -131,7 +132,7 @@ def ajax_disable(request):
return
HttpResponse
(
status
=
204
)
@require_
POS
T
@require_
GE
T
def
ajax_status
(
request
):
"""
A view that sends notifications status for the authenticated user
...
...
@@ -142,22 +143,13 @@ def ajax_status(request):
if
not
request
.
user
.
is_authenticated
():
raise
PermissionDenied
prefs
=
UserPreference
.
objects
.
get
(
qs
=
UserPreference
.
objects
.
filter
(
user
=
request
.
user
,
key
=
NOTIFICATION_PREF_KEY
,
defaults
=
{
"value"
:
UsernameCipher
.
encrypt
(
request
.
user
.
username
)
}
key
=
NOTIFICATION_PREF_KEY
)
if
prefs
answer
=
true
else
answer
=
false
return
utils
.
JsonResponse
({
'status'
:
answer
})
return
HttpResponse
(
json
.
dumps
({
"status"
:
len
(
qs
)}),
content_type
=
"application/json"
)
@require_GET
...
...
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