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
5841d460
Commit
5841d460
authored
Feb 12, 2014
by
Greg Price
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clean up usage of CS API key
parent
a02beb6d
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
59 additions
and
21 deletions
+59
-21
lms/djangoapps/django_comment_client/base/tests.py
+13
-13
lms/djangoapps/django_comment_client/forum/tests.py
+43
-1
lms/lib/comment_client/settings.py
+0
-5
lms/lib/comment_client/utils.py
+3
-2
No files found.
lms/djangoapps/django_comment_client/base/tests.py
View file @
5841d460
...
...
@@ -102,7 +102,7 @@ class ViewsTestCase(UrlResetMixin, ModuleStoreTestCase):
'anonymous'
:
False
,
'course_id'
:
u'MITx/999/Robot_Super_Course'
,
},
params
=
{
'request_id'
:
ANY
},
headers
=
{
'X-Edx-Api-Key'
:
'PUT_YOUR_API_KEY_HERE'
}
,
headers
=
ANY
,
timeout
=
5
)
assert_equal
(
response
.
status_code
,
200
)
...
...
@@ -139,7 +139,7 @@ class ViewsTestCase(UrlResetMixin, ModuleStoreTestCase):
{
'data'
:
None
,
'params'
:
{
'mark_as_read'
:
True
,
'request_id'
:
ANY
},
'headers'
:
{
'X-Edx-Api-Key'
:
'PUT_YOUR_API_KEY_HERE'
}
,
'headers'
:
ANY
,
'timeout'
:
5
}
),
...
...
@@ -148,7 +148,7 @@ class ViewsTestCase(UrlResetMixin, ModuleStoreTestCase):
{
'data'
:
{
'user_id'
:
'1'
},
'params'
:
{
'request_id'
:
ANY
},
'headers'
:
{
'X-Edx-Api-Key'
:
'PUT_YOUR_API_KEY_HERE'
}
,
'headers'
:
ANY
,
'timeout'
:
5
}
),
...
...
@@ -157,7 +157,7 @@ class ViewsTestCase(UrlResetMixin, ModuleStoreTestCase):
{
'data'
:
None
,
'params'
:
{
'mark_as_read'
:
True
,
'request_id'
:
ANY
},
'headers'
:
{
'X-Edx-Api-Key'
:
'PUT_YOUR_API_KEY_HERE'
}
,
'headers'
:
ANY
,
'timeout'
:
5
}
)
...
...
@@ -199,7 +199,7 @@ class ViewsTestCase(UrlResetMixin, ModuleStoreTestCase):
{
'data'
:
None
,
'params'
:
{
'mark_as_read'
:
True
,
'request_id'
:
ANY
},
'headers'
:
{
'X-Edx-Api-Key'
:
'PUT_YOUR_API_KEY_HERE'
}
,
'headers'
:
ANY
,
'timeout'
:
5
}
),
...
...
@@ -208,7 +208,7 @@ class ViewsTestCase(UrlResetMixin, ModuleStoreTestCase):
{
'data'
:
{
'user_id'
:
'1'
},
'params'
:
{
'request_id'
:
ANY
},
'headers'
:
{
'X-Edx-Api-Key'
:
'PUT_YOUR_API_KEY_HERE'
}
,
'headers'
:
ANY
,
'timeout'
:
5
}
),
...
...
@@ -217,7 +217,7 @@ class ViewsTestCase(UrlResetMixin, ModuleStoreTestCase):
{
'data'
:
None
,
'params'
:
{
'mark_as_read'
:
True
,
'request_id'
:
ANY
},
'headers'
:
{
'X-Edx-Api-Key'
:
'PUT_YOUR_API_KEY_HERE'
}
,
'headers'
:
ANY
,
'timeout'
:
5
}
)
...
...
@@ -255,7 +255,7 @@ class ViewsTestCase(UrlResetMixin, ModuleStoreTestCase):
{
'data'
:
None
,
'params'
:
{
'request_id'
:
ANY
},
'headers'
:
{
'X-Edx-Api-Key'
:
'PUT_YOUR_API_KEY_HERE'
}
,
'headers'
:
ANY
,
'timeout'
:
5
}
),
...
...
@@ -264,7 +264,7 @@ class ViewsTestCase(UrlResetMixin, ModuleStoreTestCase):
{
'data'
:
{
'user_id'
:
'1'
},
'params'
:
{
'request_id'
:
ANY
},
'headers'
:
{
'X-Edx-Api-Key'
:
'PUT_YOUR_API_KEY_HERE'
}
,
'headers'
:
ANY
,
'timeout'
:
5
}
),
...
...
@@ -273,7 +273,7 @@ class ViewsTestCase(UrlResetMixin, ModuleStoreTestCase):
{
'data'
:
None
,
'params'
:
{
'request_id'
:
ANY
},
'headers'
:
{
'X-Edx-Api-Key'
:
'PUT_YOUR_API_KEY_HERE'
}
,
'headers'
:
ANY
,
'timeout'
:
5
}
)
...
...
@@ -311,7 +311,7 @@ class ViewsTestCase(UrlResetMixin, ModuleStoreTestCase):
{
'data'
:
None
,
'params'
:
{
'request_id'
:
ANY
},
'headers'
:
{
'X-Edx-Api-Key'
:
'PUT_YOUR_API_KEY_HERE'
}
,
'headers'
:
ANY
,
'timeout'
:
5
}
),
...
...
@@ -320,7 +320,7 @@ class ViewsTestCase(UrlResetMixin, ModuleStoreTestCase):
{
'data'
:
{
'user_id'
:
'1'
},
'params'
:
{
'request_id'
:
ANY
},
'headers'
:
{
'X-Edx-Api-Key'
:
'PUT_YOUR_API_KEY_HERE'
}
,
'headers'
:
ANY
,
'timeout'
:
5
}
),
...
...
@@ -329,7 +329,7 @@ class ViewsTestCase(UrlResetMixin, ModuleStoreTestCase):
{
'data'
:
None
,
'params'
:
{
'request_id'
:
ANY
},
'headers'
:
{
'X-Edx-Api-Key'
:
'PUT_YOUR_API_KEY_HERE'
}
,
'headers'
:
ANY
,
'timeout'
:
5
}
)
...
...
lms/djangoapps/django_comment_client/forum/tests.py
View file @
5841d460
...
...
@@ -11,7 +11,7 @@ from django_comment_client.forum import views
from
courseware.tests.modulestore_config
import
TEST_DATA_MIXED_MODULESTORE
from
nose.tools
import
assert_true
# pylint: disable=E0611
from
mock
import
patch
,
Mock
,
ANY
from
mock
import
patch
,
Mock
,
ANY
,
call
import
logging
...
...
@@ -243,6 +243,48 @@ class SingleThreadTestCase(ModuleStoreTestCase):
@override_settings
(
MODULESTORE
=
TEST_DATA_MIXED_MODULESTORE
)
@patch
(
'requests.request'
)
class
CommentsServiceRequestHeadersTestCase
(
UrlResetMixin
,
ModuleStoreTestCase
):
@patch.dict
(
"django.conf.settings.FEATURES"
,
{
"ENABLE_DISCUSSION_SERVICE"
:
True
})
def
setUp
(
self
):
username
=
"foo"
password
=
"bar"
# Invoke UrlResetMixin
super
(
CommentsServiceRequestHeadersTestCase
,
self
)
.
setUp
()
self
.
course
=
CourseFactory
.
create
()
self
.
student
=
UserFactory
.
create
(
username
=
username
,
password
=
password
)
CourseEnrollmentFactory
.
create
(
user
=
self
.
student
,
course_id
=
self
.
course
.
id
)
self
.
assertTrue
(
self
.
client
.
login
(
username
=
username
,
password
=
password
)
)
def
assert_all_calls_have_header
(
self
,
mock_request
,
key
,
value
):
expected
=
call
(
ANY
,
# method
ANY
,
# url
data
=
ANY
,
params
=
ANY
,
headers
=
PartialDictMatcher
({
key
:
value
}),
timeout
=
ANY
)
for
actual
in
mock_request
.
call_args_list
:
self
.
assertEqual
(
expected
,
actual
)
@override_settings
(
COMMENTS_SERVICE_KEY
=
"test_api_key"
)
def
test_api_key
(
self
,
mock_request
):
mock_request
.
side_effect
=
make_mock_request_impl
(
"dummy"
,
"dummy"
)
self
.
client
.
get
(
reverse
(
"django_comment_client.forum.views.forum_form_discussion"
,
kwargs
=
{
"course_id"
:
self
.
course
.
id
}
),
)
self
.
assert_all_calls_have_header
(
mock_request
,
"X-Edx-Api-Key"
,
"test_api_key"
)
@override_settings
(
MODULESTORE
=
TEST_DATA_MIXED_MODULESTORE
)
class
InlineDiscussionUnicodeTestCase
(
ModuleStoreTestCase
,
UnicodeTestMixin
):
def
setUp
(
self
):
self
.
course
=
CourseFactory
.
create
()
...
...
lms/lib/comment_client/settings.py
View file @
5841d460
...
...
@@ -6,8 +6,3 @@ else:
SERVICE_HOST
=
'http://localhost:4567'
PREFIX
=
SERVICE_HOST
+
'/api/v1'
if
hasattr
(
settings
,
"COMMENTS_SERVICE_KEY"
):
API_KEY
=
settings
.
COMMENTS_SERVICE_KEY
else
:
API_KEY
=
"PUT_YOUR_API_KEY_HERE"
lms/lib/comment_client/utils.py
View file @
5841d460
...
...
@@ -3,9 +3,10 @@ from dogapi import dog_stats_api
import
json
import
logging
import
requests
import
settings
from
django.conf
import
settings
from
time
import
time
from
uuid
import
uuid4
from
django.utils.translation
import
get_language
log
=
logging
.
getLogger
(
__name__
)
...
...
@@ -52,7 +53,7 @@ def request_timer(request_id, method, url):
def
perform_request
(
method
,
url
,
data_or_params
=
None
,
*
args
,
**
kwargs
):
if
data_or_params
is
None
:
data_or_params
=
{}
headers
=
{
'X-Edx-Api-Key'
:
settings
.
API_KEY
}
headers
=
{
'X-Edx-Api-Key'
:
getattr
(
settings
,
"COMMENTS_SERVICE_KEY"
,
None
)
}
request_id
=
uuid4
()
request_id_dict
=
{
'request_id'
:
request_id
}
...
...
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