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
61e12f57
Commit
61e12f57
authored
Jan 24, 2013
by
Deena Wang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
experimenting with creating a course
parent
ca185c03
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
164 additions
and
16 deletions
+164
-16
lms/djangoapps/courseware/tests/test_course_creation.py
+61
-0
lms/djangoapps/courseware/tests/test_module_render.py
+5
-8
lms/djangoapps/courseware/tests/test_views.py
+98
-8
No files found.
lms/djangoapps/courseware/tests/test_course_creation.py
0 → 100644
View file @
61e12f57
import
logging
from
mock
import
MagicMock
,
patch
import
factory
import
copy
from
path
import
path
from
django.test
import
TestCase
from
django.test.client
import
Client
from
django.core.urlresolvers
import
reverse
from
django.conf
import
settings
from
override_settings
import
override_settings
from
xmodule.modulestore.xml_importer
import
import_from_xml
import
xmodule.modulestore.django
TEST_DATA_MODULESTORE
=
copy
.
deepcopy
(
settings
.
MODULESTORE
)
TEST_DATA_MODULESTORE
[
'default'
][
'OPTIONS'
][
'fs_root'
]
=
path
(
'common/test/data'
)
@override_settings
(
MODULESTORE
=
TEST_DATA_MODULESTORE
)
class
CreateTest
(
TestCase
):
def
setUp
(
self
):
xmodule
.
modulestore
.
django
.
_MODULESTORES
=
{}
xmodule
.
modulestore
.
django
.
modulestore
()
.
collection
.
drop
()
import_from_xml
(
modulestore
(),
'common/test/data/'
,
[
test_course_name
])
def
check_edit_item
(
self
,
test_course_name
):
import_from_xml
(
modulestore
(),
'common/test/data/'
,
[
test_course_name
])
for
descriptor
in
modulestore
()
.
get_items
(
Location
(
None
,
None
,
None
,
None
,
None
)):
print
"Checking "
,
descriptor
.
location
.
url
()
print
descriptor
.
__class__
,
descriptor
.
location
resp
=
self
.
client
.
get
(
reverse
(
'edit_item'
),
{
'id'
:
descriptor
.
location
.
url
()})
self
.
assertEqual
(
resp
.
status_code
,
200
)
def
test_edit_item_toy
(
self
):
self
.
check_edit_item
(
'toy'
)
## def setUp(self):
## self.client = Client()
## self.username = 'username'
## self.email = 'test@foo.com'
## self.pw = 'password'
##
## def create_account(self, username, email, pw):
## resp = self.client.post('/create_account', {
## 'username': username,
## 'email': email,
## 'password': pw,
## 'location': 'home',
## 'language': 'Franglish',
## 'name': 'Fred Weasley',
## 'terms_of_service': 'true',
## 'honor_code': 'true',
## })
## return resp
##
## def registration(self, email):
## '''look up registration object by email'''
## return Registration.objects.get(user__email=email)
##
## def activate_user(self, email):
## activation_key = self.registration(email).activation_key
lms/djangoapps/courseware/tests/test_module_render.py
View file @
61e12f57
from
unittest
import
TestCase
import
logging
from
mock
import
MagicMock
,
patch
import
json
import
factory
import
unittest
from
django.http
import
Http404
,
HttpResponse
,
HttpRequest
from
django.conf
import
settings
from
django.contrib.auth.models
import
User
from
django.test.client
import
Client
from
django.conf
import
settings
from
django.test
import
TestCase
from
django.test.client
import
RequestFactory
from
courseware.models
import
StudentModule
from
xmodule.modulestore.exceptions
import
ItemNotFoundError
from
xmodule.modulestore
import
Location
import
courseware.module_render
as
render
import
unittest
from
django.test
import
TestCase
from
django.test.client
import
RequestFactory
from
override_settings
import
override_settings
from
xmodule.modulestore.django
import
modulestore
,
_MODULESTORES
...
...
@@ -202,7 +198,8 @@ class TestTOC(TestCase):
# Toy courses should be loaded
self
.
course_name
=
'edX/toy/2012_Fall'
self
.
toy_course
=
modulestore
()
.
get_course
(
self
.
course_name
)
print
type
(
self
.
toy_course
)
assert
False
self
.
portal_user
=
UserFactory
()
def
test_toc_toy_from_chapter
(
self
):
...
...
lms/djangoapps/courseware/tests/test_views.py
View file @
61e12f57
import
logging
from
mock
import
MagicMock
,
patch
import
datetime
import
factory
from
django.test
import
TestCase
from
django.http
import
Http404
from
django.http
import
Http404
,
HttpResponse
from
django.conf
import
settings
from
django.test.utils
import
override_settings
from
django.contrib.auth.models
import
User
from
django.test.client
import
RequestFactory
from
student.models
import
CourseEnrollment
import
courseware.views
as
views
from
xmodule.modulestore.django
import
modulestore
from
xmodule.modulestore.exceptions
import
InvalidLocationError
,
\
ItemNotFoundError
,
NoPathToItem
ItemNotFoundError
,
NoPathToItem
import
courseware.views
as
views
from
xmodule.modulestore
import
Location
#import mitx.common.djangoapps.mitxmako as mako
class
Stub
():
pass
def
render_to_response
(
template_name
,
dictionary
,
context_instance
=
None
,
namespace
=
'main'
,
**
kwargs
):
# The original returns HttpResponse
print
dir
()
print
template_name
print
dictionary
return
HttpResponse
(
'foo'
)
class
UserFactory
(
factory
.
Factory
):
first_name
=
'Test'
last_name
=
'Robot'
is_staff
=
True
is_active
=
True
# This part is required for modulestore() to work properly
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
)
class
ModulestoreTest
(
TestCase
):
def
setUp
(
self
):
self
.
_MODULESTORES
=
{}
# Toy courses should be loaded
self
.
course_name
=
'edX/toy/2012_Fall'
self
.
toy_course
=
modulestore
()
.
get_course
(
'edX/toy/2012_Fall'
)
def
test
(
self
):
self
.
assertEquals
(
1
,
2
)
class
ViewsTestCase
(
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
.
course_id
=
'edx/toy/
Fall_2012
'
self
.
course_id
=
'edx/toy/
2012_Fall
'
self
.
enrollment
=
CourseEnrollment
.
objects
.
get_or_create
(
user
=
self
.
user
,
course_id
=
self
.
course_id
,
created
=
self
.
date
)[
0
]
self
.
location
=
[
'tag'
,
'org'
,
'course'
,
'category'
,
'name'
]
self
.
_MODULESTORES
=
{}
# This is a CourseDescriptor object
self
.
toy_course
=
modulestore
()
.
get_course
(
'edX/toy/2012_Fall'
)
self
.
request_factory
=
RequestFactory
()
# Many functions call upon render_to_response
# Problem is that we don't know what templates there are?
views
.
render_to_response
=
render_to_response
#m = mako.MakoMiddleware()
def
test_user_groups
(
self
):
# depreciated function?
...
...
@@ -77,8 +129,46 @@ class ViewsTestCase(TestCase):
self
.
assertTrue
(
views
.
registered_for_course
(
mock_course
,
self
.
user
))
def
test_jump_to
(
self
):
mock_request
=
MagicMock
()
self
.
assertRaises
(
Http404
,
views
.
jump_to
,
mock_request
,
'bar'
,
())
chapter
=
'Overview'
chapter_url
=
'
%
s/
%
s/
%
s'
%
(
'/courses'
,
self
.
course_id
,
chapter
)
request
=
self
.
request_factory
.
get
(
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
)
self
.
assertRaises
(
ItemNotFoundError
,
views
.
jump_to
,
mock_request
,
'dummy'
,
self
.
location
)
def
test_static_tab
(
self
):
mock_request
=
MagicMock
()
mock_request
.
user
=
self
.
user
# What is tab_slug?
#views.static_tab(mock_request, self.course_id, 'dummy')
def
test_university_profile
(
self
):
chapter
=
'Overview'
chapter_url
=
'
%
s/
%
s/
%
s'
%
(
'/courses'
,
self
.
course_id
,
chapter
)
request
=
self
.
request_factory
.
get
(
chapter_url
)
request
.
user
=
UserFactory
()
self
.
assertRaisesRegexp
(
Http404
,
'University Profile*'
,
views
.
university_profile
,
request
,
'Harvard'
)
# Mocked out function render_to_response
self
.
assertIsInstance
(
views
.
university_profile
(
request
,
'edX'
),
HttpResponse
)
def
test_syllabus
(
self
):
chapter
=
'Overview'
chapter_url
=
'
%
s/
%
s/
%
s'
%
(
'/courses'
,
self
.
course_id
,
chapter
)
request
=
self
.
request_factory
.
get
(
chapter_url
)
request
.
user
=
UserFactory
()
# course not found
views
.
syllabus
(
request
,
self
.
course_id
)
def
test_render_notifications
(
self
):
request
=
self
.
request_factory
.
get
(
'foo'
)
views
.
render_notifications
(
request
,
self
.
course_id
,
'dummy'
)
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