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
8c946f8b
Commit
8c946f8b
authored
Dec 02, 2014
by
Jesse Zoldak
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #6104 from edx/zoldak/heartbeat-mock-tests
Mock the modulestore for the heartbeat tests
parents
927249bc
6f1bccd5
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
19 deletions
+20
-19
common/djangoapps/heartbeat/tests/test_heartbeat.py
+20
-19
No files found.
common/djangoapps/heartbeat/tests/test_heartbeat.py
View file @
8c946f8b
"""
Test the heartbeat
"""
from
django.test.client
import
Client
from
django.core.urlresolvers
import
reverse
import
json
from
django.core.urlresolvers
import
reverse
from
django.db.utils
import
DatabaseError
import
mock
from
django.test.client
import
Client
from
django.test.testcases
import
TestCase
from
mock
import
patch
from
xmodule.exceptions
import
HeartbeatFailure
@patch
(
'heartbeat.views.modulestore'
)
class
HeartbeatTestCase
(
TestCase
):
"""
Test the heartbeat
...
...
@@ -19,22 +23,19 @@ class HeartbeatTestCase(TestCase):
self
.
heartbeat_url
=
reverse
(
'heartbeat'
)
return
super
(
HeartbeatTestCase
,
self
)
.
setUp
()
def
tearDown
(
self
):
return
super
(
HeartbeatTestCase
,
self
)
.
tearDown
()
def
test_success
(
self
):
def
test_success
(
self
,
mock_modulestore
):
# pylint: disable=unused-argument
response
=
self
.
client
.
get
(
self
.
heartbeat_url
)
self
.
assertEqual
(
response
.
status_code
,
200
)
def
test_sql_fail
(
self
):
with
mock
.
patch
(
'heartbeat.views.connection'
)
as
mock_connection
:
mock_connection
.
cursor
.
return_value
.
execute
.
side_effect
=
DatabaseError
response
=
self
.
client
.
get
(
self
.
heartbeat_url
)
self
.
assertEqual
(
response
.
status_code
,
503
)
response_dict
=
json
.
loads
(
response
.
content
)
self
.
assertIn
(
'SQL'
,
response_dict
)
def
test_mo
ngo_fail
(
self
):
with
mock
.
patch
(
'pymongo.MongoClient.alive'
,
return_value
=
False
):
response
=
self
.
client
.
get
(
self
.
heartbeat_url
)
self
.
assertEqual
(
response
.
status_code
,
503
)
@patch
(
'heartbeat.views.connection'
)
def
test_sql_fail
(
self
,
mock_connection
,
mock_modulestore
):
# pylint: disable=unused-argument
mock_connection
.
cursor
.
return_value
.
execute
.
side_effect
=
DatabaseError
response
=
self
.
client
.
get
(
self
.
heartbeat_url
)
self
.
assertEqual
(
response
.
status_code
,
503
)
response_dict
=
json
.
loads
(
response
.
content
)
self
.
assertIn
(
'SQL'
,
response_dict
)
def
test_mo
dulestore_fail
(
self
,
mock_modulestore
):
# pylint: disable=unused-argument
mock_modulestore
.
return_value
.
heartbeat
.
side_effect
=
HeartbeatFailure
(
'msg'
,
'service'
)
response
=
self
.
client
.
get
(
self
.
heartbeat_url
)
self
.
assertEqual
(
response
.
status_code
,
503
)
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