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
b63c3c5a
Commit
b63c3c5a
authored
Feb 01, 2013
by
Jay Zoldak
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Change modulestore name and subclass TestCase
parent
95d39573
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
143 additions
and
4 deletions
+143
-4
cms/djangoapps/contentstore/tests/factories.py
+44
-2
cms/djangoapps/contentstore/tests/test_contentstore.py
+94
-0
cms/envs/test.py
+5
-2
No files found.
cms/djangoapps/contentstore/tests/factories.py
View file @
b63c3c5a
from
factory
import
Factory
from
xmodule.modulestore
import
Location
from
xmodule.modulestore.django
import
modulestore
from
datetime
import
datetime
from
time
import
gmtime
from
uuid
import
uuid4
from
student.models
import
(
User
,
UserProfile
,
Registration
,
CourseEnrollmentAllowed
)
from
django.contrib.auth.models
import
Group
from
xmodule.modulestore
import
Location
from
xmodule.modulestore.django
import
modulestore
from
xmodule.timeparse
import
stringify_time
class
UserProfileFactory
(
Factory
):
FACTORY_FOR
=
UserProfile
user
=
None
name
=
'Robot Studio'
courseware
=
'course.xml'
class
RegistrationFactory
(
Factory
):
FACTORY_FOR
=
Registration
user
=
None
activation_key
=
uuid4
()
.
hex
class
UserFactory
(
Factory
):
FACTORY_FOR
=
User
username
=
'robot'
email
=
'robot@edx.org'
password
=
'test'
first_name
=
'Robot'
last_name
=
'Tester'
is_staff
=
False
is_active
=
True
is_superuser
=
False
last_login
=
datetime
.
now
()
date_joined
=
datetime
.
now
()
class
GroupFactory
(
Factory
):
FACTORY_FOR
=
Group
name
=
'test_group'
class
CourseEnrollmentAllowedFactory
(
Factory
):
FACTORY_FOR
=
CourseEnrollmentAllowed
email
=
'test@edx.org'
course_id
=
'edX/test/2012_Fall'
def
XMODULE_COURSE_CREATION
(
class_to_create
,
**
kwargs
):
return
XModuleCourseFactory
.
_create
(
class_to_create
,
**
kwargs
)
...
...
cms/djangoapps/contentstore/tests/test_contentstore.py
0 → 100644
View file @
b63c3c5a
import
json
import
shutil
from
django.test
import
TestCase
from
django.test.client
import
Client
from
override_settings
import
override_settings
from
django.conf
import
settings
from
django.core.urlresolvers
import
reverse
from
path
import
path
import
json
from
fs.osfs
import
OSFS
import
copy
from
mock
import
Mock
import
xmodule.modulestore.django
from
factories
import
*
# Subclass TestCase and use to initialize the contentstore
class
CmsTestCase
(
TestCase
):
def
_pre_setup
(
self
):
super
(
CmsTestCase
,
self
)
.
_pre_setup
()
# Flush and initialize the module store
# It needs the templates because it creates new records
# by cloning from the template.
# Note that if your test module gets in some weird state
# (though it shouldn't), do this manually
# from the bash shell to drop it:
# $ mongo test_xmodule --eval "db.dropDatabase()"
xmodule
.
modulestore
.
django
.
_MODULESTORES
=
{}
xmodule
.
modulestore
.
django
.
modulestore
()
.
collection
.
drop
()
xmodule
.
templates
.
update_templates
()
def
_post_teardown
(
self
):
# Make sure you flush out the test modulestore after the end
# of the last test because otherwise on the next run
# cms/djangoapps/contentstore/__init__.py
# update_templates() will try to update the templates
# via upsert and it sometimes seems to be messing things up.
xmodule
.
modulestore
.
django
.
_MODULESTORES
=
{}
xmodule
.
modulestore
.
django
.
modulestore
()
.
collection
.
drop
()
super
(
CmsTestCase
,
self
)
.
_post_teardown
()
def
parse_json
(
response
):
"""Parse response, which is assumed to be json"""
return
json
.
loads
(
response
.
content
)
TEST_DATA_MODULESTORE
=
copy
.
deepcopy
(
settings
.
MODULESTORE
)
TEST_DATA_MODULESTORE
[
'default'
][
'OPTIONS'
][
'fs_root'
]
=
path
(
'common/test/data'
)
TEST_DATA_MODULESTORE
[
'direct'
][
'OPTIONS'
][
'fs_root'
]
=
path
(
'common/test/data'
)
@override_settings
(
MODULESTORE
=
TEST_DATA_MODULESTORE
)
class
NewContentStoreTest
(
CmsTestCase
):
def
setUp
(
self
):
# super(NewContentStoreTest, self).setUp()
uname
=
'testuser'
email
=
'test+courses@edx.org'
password
=
'foo'
# Create the use so we can log them in.
self
.
user
=
User
.
objects
.
create_user
(
uname
,
email
,
password
)
# Note that we do not actually need to do anything
# for registration if we directly mark them active.
self
.
user
.
is_active
=
True
# Staff has access to view all courses
self
.
user
.
is_staff
=
True
self
.
user
.
save
()
# user = UserFactory(username=uname, email=email, password=password,
# is_staff=True, is_active=True)
# user.is_authenticated= Mock(return_value=True)
self
.
client
=
Client
()
self
.
client
.
login
(
username
=
uname
,
password
=
password
)
self
.
course_data
=
{
'template'
:
'i4x://edx/templates/course/Empty'
,
'org'
:
'MITx'
,
'number'
:
'999'
,
'display_name'
:
'Robot Super Course'
,
}
def
tearDown
(
self
):
# super(NewContentStoreTest, self).tearDown()
pass
def
test_create_course
(
self
):
"""Test new course creation - happy path"""
resp
=
self
.
client
.
post
(
reverse
(
'create_new_course'
),
self
.
course_data
)
self
.
assertEqual
(
resp
.
status_code
,
200
)
data
=
parse_json
(
resp
)
self
.
assertEqual
(
data
[
'id'
],
'i4x://MITx/999/course/Robot_Super_Course'
)
cms/envs/test.py
View file @
b63c3c5a
...
...
@@ -10,7 +10,7 @@ sessions. Assumes structure:
from
.common
import
*
import
os
from
path
import
path
from
time
import
time
# Nose Test Runner
INSTALLED_APPS
+=
(
'django_nose'
,)
...
...
@@ -39,11 +39,14 @@ STATICFILES_DIRS += [
if
os
.
path
.
isdir
(
COMMON_TEST_DATA_ROOT
/
course_dir
)
]
# Use the current seconds since epoch to differentiate
# the mongo collections on jenkins.
sec_since_epoch
=
'
%
s'
%
int
(
time
()
*
100
)
modulestore_options
=
{
'default_class'
:
'xmodule.raw_module.RawDescriptor'
,
'host'
:
'localhost'
,
'db'
:
'test_xmodule'
,
'collection'
:
'modulestore
'
,
'collection'
:
'modulestore
_
%
s'
%
sec_since_epoch
,
'fs_root'
:
GITHUB_REPO_ROOT
,
'render_template'
:
'mitxmako.shortcuts.render_to_string'
,
}
...
...
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