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
437aadb2
Commit
437aadb2
authored
Mar 05, 2013
by
Will Daly
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cleaned up some tests; deleted skip tests
parent
faf5c3f0
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
1 additions
and
174 deletions
+1
-174
lms/djangoapps/courseware/tests/test_courses.py
+0
-63
lms/djangoapps/courseware/tests/test_module_render.py
+0
-87
lms/djangoapps/courseware/tests/test_views.py
+1
-24
No files found.
lms/djangoapps/courseware/tests/test_courses.py
deleted
100644 → 0
View file @
faf5c3f0
from
mock
import
MagicMock
,
patch
import
datetime
from
django.test
import
TestCase
from
django.contrib.auth.models
import
User
from
django.conf
import
settings
from
django.test.utils
import
override_settings
from
student.models
import
CourseEnrollment
import
courseware.courses
as
courses
from
xmodule.modulestore.xml
import
XMLModuleStore
from
xmodule.modulestore.django
import
modulestore
from
xmodule.modulestore
import
Location
def
xml_store_config
(
data_dir
):
return
{
'default'
:
{
'ENGINE'
:
'xmodule.modulestore.xml.XMLModuleStore'
,
'OPTIONS'
:
{
'data_dir'
:
data_dir
,
'default_class'
:
'xmodule.hidden_module.HiddenDescriptor'
,
}
}
}
TEST_DATA_DIR
=
settings
.
COMMON_TEST_DATA_ROOT
TEST_DATA_XML_MODULESTORE
=
xml_store_config
(
TEST_DATA_DIR
)
@override_settings
(
MODULESTORE
=
TEST_DATA_XML_MODULESTORE
)
class
CoursesTestCase
(
TestCase
):
def
setUp
(
self
):
## self.user = User.objects.create(username='dummy', password='123456',
## email='test@mit.edu')
## self.date = datetime.datetime(2013,1,22)
## self.enrollment = CourseEnrollment.objects.get_or_create(user = self.user,
## course_id = self.course_id,
## created = self.date)[0]
self
.
_MODULESTORES
=
{}
#self.course_id = 'edx/toy/2012_Fall'
self
.
toy_course
=
modulestore
()
.
get_course
(
'edX/toy/2012_Fall'
)
def
test_get_course_by_id
(
self
):
courses
.
get_course_by_id
(
"edX/toy/2012_Fall"
)
@override_settings
(
MODULESTORE
=
TEST_DATA_XML_MODULESTORE
)
class
CoursesTests
(
TestCase
):
# runs
def
setUp
(
self
):
self
.
_MODULESTORES
=
{}
#self.course_id = 'edX/toy/2012_Fall'
self
.
toy_course
=
modulestore
()
.
get_course
(
'edX/toy/2012_Fall'
)
## self.fake_user = User.objects.create(is_superuser=True)
'''
no test written for get_request_for_thread
'''
def
test_get_course_by_id
(
self
):
#self.test_course_id = "edX/toy/2012_Fall"
courses
.
get_course_by_id
(
"edX/toy/2012_Fall"
)
# print modulestore().get_instance(test_course_id, Location('i4x', 'edx', 'toy', 'course', '2012_Fall'))
#self.assertEqual(courses.get_course_by_id(self.test_course_id),modulestore().get_instance(self.test_course_id, Location('i4x', 'edX', 'toy', 'course', '2012_Fall'), None))
lms/djangoapps/courseware/tests/test_module_render.py
View file @
437aadb2
...
...
@@ -4,7 +4,6 @@ import json
import
factory
import
unittest
from
nose.tools
import
set_trace
from
nose.plugins.skip
import
SkipTest
from
django.http
import
Http404
,
HttpResponse
,
HttpRequest
from
django.conf
import
settings
...
...
@@ -74,62 +73,6 @@ class ModuleRenderTestCase(PageLoader):
self
.
assertIsNone
(
render
.
get_instance_module
(
'dummy'
,
mock_user_2
,
mock_module
,
'dummy'
))
def
test_get_shared_instance_module
(
self
):
raise
SkipTest
mock_user
=
MagicMock
(
User
)
mock_user
.
is_authenticated
.
return_value
=
False
self
.
assertIsNone
(
render
.
get_shared_instance_module
(
'dummy'
,
mock_user
,
'dummy'
,
'dummy'
))
mock_user_2
=
MagicMock
(
User
)
mock_user_2
.
is_authenticated
.
return_value
=
True
mock_module
=
MagicMock
(
shared_state_key
=
'key'
)
mock_module
.
location
=
Location
(
'i4x'
,
'edX'
,
'toy'
,
'chapter'
,
'Overview'
)
mock_module
.
get_shared_state
.
return_value
=
'{}'
mock_cache
=
MagicMock
()
mock_cache
.
lookup
.
return_value
=
False
#mock_cache._state = 'dummy'
#set_trace()
print
mock_module
.
get_shared_state
()
s
=
render
.
get_shared_instance_module
(
self
.
course_id
,
mock_user_2
,
mock_module
,
mock_cache
)
self
.
assertIsInstance
(
s
,
StudentModule
)
# Problem: can't get code to take branch that creates StudentModule?
# Can't finish testing modx_dispatch
def
test_xqueue_callback
(
self
):
mock_request
=
MagicMock
()
mock_request
.
POST
.
copy
.
return_value
=
{}
# 339
self
.
assertRaises
(
Http404
,
render
.
xqueue_callback
,
mock_request
,
'dummy'
,
'dummy'
,
'dummy'
,
'dummy'
)
mock_request_2
=
MagicMock
()
xpackage
=
{
'xqueue_header'
:
json
.
dumps
({}),
'xqueue_body'
:
'Message from grader'
}
mock_request_2
.
POST
.
copy
.
return_value
=
xpackage
# 342
self
.
assertRaises
(
Http404
,
render
.
xqueue_callback
,
mock_request_2
,
'dummy'
,
'dummy'
,
'dummy'
,
'dummy'
)
mock_request_3
=
MagicMock
()
xpackage_2
=
{
'xqueue_header'
:
json
.
dumps
({
'lms_key'
:
'secretkey'
}),
'xqueue_body'
:
'Message from grader'
}
mock_request_3
.
POST
.
copy
.
return_value
=
xpackage_2
# Roadblock: how to get user registered in class?
raise
SkipTest
#
# trying alternate way of creating account in hopes of getting valid id
# Problem: Can't activate user
self
.
student_name
=
'12'
self
.
password
=
'foo'
self
.
email
=
'test@mit.edu'
self
.
create_account
(
self
.
student_name
,
self
.
email
,
self
.
password
)
self
.
activate_user
(
self
.
email
)
request
=
RequestFactory
()
.
get
(
'stuff'
)
# This doesn't work to install user
render
.
xqueue_callback
(
mock_request_3
,
self
.
course_id
,
self
.
student_name
,
self
.
password
,
'dummy'
)
def
test_modx_dispatch
(
self
):
self
.
assertRaises
(
Http404
,
render
.
modx_dispatch
,
'dummy'
,
'dummy'
,
'invalid Location'
,
'dummy'
)
...
...
@@ -162,40 +105,10 @@ class ModuleRenderTestCase(PageLoader):
mock_request_3
,
'dummy'
,
self
.
location
,
'toy'
)
self
.
assertRaises
(
Http404
,
render
.
modx_dispatch
,
mock_request_3
,
'dummy'
,
self
.
location
,
self
.
course_id
)
## student_module_cache = StudentModuleCache.cache_for_descriptor_descendents(self.course_id,
## mock_request_3.user, modulestore().get_instance(self.course_id, self.location))
## get_shared_instance_module(course_id, request.user, instance, student_module_cache)
# 'goto_position' is the only dispatch that will work
mock_request_3
.
POST
.
copy
.
return_value
=
{
'position'
:
1
}
self
.
assertIsInstance
(
render
.
modx_dispatch
(
mock_request_3
,
'goto_position'
,
self
.
location
,
self
.
course_id
),
HttpResponse
)
# keep going
def
test_preview_chemcalc
(
self
):
mock_request
=
MagicMock
(
method
=
'notGET'
)
self
.
assertRaises
(
Http404
,
render
.
preview_chemcalc
,
mock_request
)
mock_request_2
=
MagicMock
(
method
=
'GET'
)
mock_request_2
.
GET
.
get
.
return_value
=
None
self
.
assertEquals
(
render
.
preview_chemcalc
(
mock_request_2
)
.
content
,
json
.
dumps
({
'preview'
:
''
,
'error'
:
'No formula specified.'
}))
mock_request_3
=
MagicMock
()
mock_request_3
.
method
=
'GET'
# Test fails because chemcalc.render_to_html always parses strings?
mock_request_3
.
GET
.
get
.
return_value
=
unicode
(
'
\x12
400'
,
errors
=
"strict"
)
## self.assertEquals(render.preview_chemcalc(mock_request_3).content,
## json.dumps({'preview':'',
## 'error':"Couldn't parse formula: formula"}))
##
mock_request_3
=
MagicMock
()
mock_request_3
.
method
=
'GET'
mock_request_3
.
GET
.
get
.
return_value
=
Stub
()
self
.
assertEquals
(
render
.
preview_chemcalc
(
mock_request_3
)
.
content
,
json
.
dumps
({
'preview'
:
''
,
'error'
:
"Error while rendering preview"
}))
def
test_get_score_bucket
(
self
):
self
.
assertEquals
(
render
.
get_score_bucket
(
0
,
10
),
'incorrect'
)
self
.
assertEquals
(
render
.
get_score_bucket
(
1
,
10
),
'partial'
)
...
...
lms/djangoapps/courseware/tests/test_views.py
View file @
437aadb2
...
...
@@ -19,8 +19,6 @@ from xmodule.modulestore.exceptions import InvalidLocationError,\
import
courseware.views
as
views
from
xmodule.modulestore
import
Location
#from override_settings import override_settings
class
Stub
():
pass
...
...
@@ -45,9 +43,6 @@ def xml_store_config(data_dir):
TEST_DATA_DIR
=
settings
.
COMMON_TEST_DATA_ROOT
TEST_DATA_XML_MODULESTORE
=
xml_store_config
(
TEST_DATA_DIR
)
#class ModulestoreTest(TestCase):
@override_settings
(
MODULESTORE
=
TEST_DATA_XML_MODULESTORE
)
class
TestJumpTo
(
TestCase
):
"""Check the jumpto link for a course"""
...
...
@@ -134,27 +129,9 @@ class ViewsTestCase(TestCase):
mock_course
.
id
=
self
.
course_id
self
.
assertTrue
(
views
.
registered_for_course
(
mock_course
,
self
.
user
))
def
test_jump_to
(
self
):
def
test_jump_to
_invalid
(
self
):
request
=
self
.
request_factory
.
get
(
self
.
chapter_url
)
self
.
assertRaisesRegexp
(
Http404
,
'Invalid location'
,
views
.
jump_to
,
request
,
'bar'
,
())
self
.
assertRaisesRegexp
(
Http404
,
'No data*'
,
views
.
jump_to
,
request
,
'dummy'
,
self
.
location
)
## print type(self.toy_course)
## print dir(self.toy_course)
## print self.toy_course.location
## print self.toy_course.__dict__
## valid = ['i4x', 'edX', 'toy', 'chapter', 'overview']
## L = Location('i4x', 'edX', 'toy', 'chapter', 'Overview', None)
##
## views.jump_to(request, 'dummy', L)
def
test_static_tab
(
self
):
request
=
self
.
request_factory
.
get
(
'foo'
)
request
.
user
=
self
.
user
self
.
assertRaises
(
Http404
,
views
.
static_tab
,
request
,
'edX/toy/2012_Fall'
,
'dummy'
)
# What are valid tab_slugs?
## request_2 = self.request_factory.get('foo')
## request_2.user = UserFactory()
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