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
35650233
Commit
35650233
authored
Jan 22, 2013
by
Deena Wang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
created test_courses.py
parent
6e773909
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
63 additions
and
5 deletions
+63
-5
lms/djangoapps/courseware/tests/test_courses.py
+21
-0
lms/djangoapps/courseware/tests/test_views.py
+42
-5
No files found.
lms/djangoapps/courseware/tests/test_courses.py
0 → 100644
View file @
35650233
from
mock
import
MagicMock
,
patch
import
datetime
from
django.test
import
TestCase
from
django.contrib.auth.models
import
User
from
student.models
import
CourseEnrollment
import
courseware.courses
as
courses
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
.
course_id
=
'edx/toy/Fall_2012'
self
.
enrollment
=
CourseEnrollment
.
objects
.
get_or_create
(
user
=
self
.
user
,
course_id
=
self
.
course_id
,
created
=
self
.
date
)[
0
]
def
test_get_course_by_id
(
self
):
courses
.
get_course_by_id
(
self
.
course_id
)
lms/djangoapps/courseware/tests/test_views.py
View file @
35650233
from
unittest
import
TestCase
import
logging
from
mock
import
MagicMock
,
patch
import
datetime
from
django.test
import
TestCase
from
django.http
import
Http404
from
django.conf
import
settings
from
django.test.utils
import
override_settings
from
django.contrib.auth.models
import
User
from
student.models
import
CourseEnrollment
import
courseware.views
as
views
from
xmodule.modulestore.django
import
modulestore
class
Stub
():
pass
class
ViewsTestCase
(
TestCase
):
def
setUp
(
self
):
pass
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
.
enrollment
=
CourseEnrollment
.
objects
.
get_or_create
(
user
=
self
.
user
,
course_id
=
self
.
course_id
,
created
=
self
.
date
)[
0
]
def
test_user_groups
(
self
):
# depreciated function?
mock_user
=
MagicMock
()
mock_user
.
is_authenticated
.
return_value
=
False
self
.
assertEquals
(
views
.
user_groups
(
mock_user
),[])
@override_settings
(
DEBUG
=
True
)
def
test_user_groups_debug
(
self
):
...
...
@@ -33,5 +46,29 @@ class ViewsTestCase(TestCase):
mock_xmodule
=
MagicMock
()
mock_xmodule
.
position
=
-
1
mock_xmodule
.
get_display_items
.
return_value
=
[
'one'
,
'two'
]
print
views
.
user_groups
(
mock_xmodule
)
self
.
assertEquals
(
views
.
user_groups
(
mock_xmodule
),
'one'
)
self
.
assertEquals
(
views
.
get_current_child
(
mock_xmodule
),
'one'
)
mock_xmodule_2
=
MagicMock
()
mock_xmodule_2
.
position
=
3
mock_xmodule_2
.
get_display_items
.
return_value
=
[]
self
.
assertIsNone
(
views
.
get_current_child
(
mock_xmodule_2
))
def
test_redirect_to_course_position
(
self
):
mock_module
=
MagicMock
()
mock_module
.
descriptor
.
id
=
'Underwater Basketweaving'
mock_module
.
position
=
3
mock_module
.
get_display_items
.
return_value
=
[]
self
.
assertRaises
(
Http404
,
views
.
redirect_to_course_position
,
mock_module
,
True
)
def
test_index
(
self
):
print
modulestore
()
assert
False
def
test_registered_for_course
(
self
):
self
.
assertFalse
(
views
.
registered_for_course
(
'Basketweaving'
,
None
))
mock_user
=
MagicMock
()
mock_user
.
is_authenticated
.
return_value
=
False
self
.
assertFalse
(
views
.
registered_for_course
(
'dummy'
,
mock_user
))
mock_course
=
MagicMock
()
mock_course
.
id
=
self
.
course_id
self
.
assertTrue
(
views
.
registered_for_course
(
mock_course
,
self
.
user
))
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