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
28674761
Commit
28674761
authored
Mar 20, 2013
by
Will Daly
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added __init__.py and test_mock_xqueue_server.py,
which should have been included in the last commit
parent
8f055ab0
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
78 additions
and
0 deletions
+78
-0
lms/djangoapps/courseware/mock_xqueue_server/__init__.py
+0
-0
lms/djangoapps/courseware/mock_xqueue_server/test_mock_xqueue_server.py
+78
-0
No files found.
lms/djangoapps/courseware/mock_xqueue_server/__init__.py
0 → 100644
View file @
28674761
lms/djangoapps/courseware/mock_xqueue_server/test_mock_xqueue_server.py
0 → 100644
View file @
28674761
import
mock
import
unittest
import
threading
import
json
import
urllib
import
urlparse
import
time
from
mock_xqueue_server
import
MockXQueueServer
,
MockXQueueRequestHandler
class
MockXQueueServerTest
(
unittest
.
TestCase
):
'''
A mock version of the XQueue server that listens on a local
port and responds with pre-defined grade messages.
Used for lettuce BDD tests in lms/courseware/features/problems.feature
and lms/courseware/features/problems.py
This is temporary and will be removed when XQueue is
rewritten using celery.
'''
def
setUp
(
self
):
# Create the server
server_port
=
8034
self
.
server_url
=
'http://127.0.0.1:
%
d'
%
server_port
self
.
server
=
MockXQueueServer
(
server_port
,
{
'correct'
:
True
,
'score'
:
1
,
'msg'
:
''
})
# Start the server in a separate daemon thread
server_thread
=
threading
.
Thread
(
target
=
self
.
server
.
serve_forever
)
server_thread
.
daemon
=
True
server_thread
.
start
()
def
tearDown
(
self
):
# Stop the server, freeing up the port
self
.
server
.
shutdown
()
def
test_grade_request
(
self
):
# Patch post_to_url() so we can intercept
# outgoing POST requests from the server
MockXQueueRequestHandler
.
post_to_url
=
mock
.
Mock
()
# Send a grade request
callback_url
=
'http://127.0.0.1:8000/test_callback'
grade_header
=
json
.
dumps
({
'lms_callback_url'
:
callback_url
,
'lms_key'
:
'test_queuekey'
,
'queue_name'
:
'test_queue'
})
grade_body
=
json
.
dumps
({
'student_info'
:
'test'
,
'grader_payload'
:
'test'
,
'student_response'
:
'test'
})
grade_request
=
{
'xqueue_header'
:
grade_header
,
'xqueue_body'
:
grade_body
}
response_handle
=
urllib
.
urlopen
(
self
.
server_url
+
'/xqueue/submit'
,
urllib
.
urlencode
(
grade_request
))
response_dict
=
json
.
loads
(
response_handle
.
read
())
# Expect that the response is success
self
.
assertEqual
(
response_dict
[
'return_code'
],
0
)
# Wait a bit before checking that the server posted back
time
.
sleep
(
3
)
# Expect that the server tries to post back the grading info
xqueue_body
=
json
.
dumps
({
'correct'
:
True
,
'score'
:
1
,
'msg'
:
'<div></div>'
})
expected_callback_dict
=
{
'xqueue_header'
:
grade_header
,
'xqueue_body'
:
xqueue_body
}
MockXQueueRequestHandler
.
post_to_url
.
assert_called_with
(
callback_url
,
expected_callback_dict
)
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