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
abf08118
Commit
abf08118
authored
Nov 29, 2017
by
Albert St. Aubin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
first test round
parent
dc280977
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
48 deletions
+45
-48
common/djangoapps/entitlements/api/v1/tests/test_views.py
+45
-48
No files found.
common/djangoapps/entitlements/api/v1/tests/test_views.py
View file @
abf08118
...
@@ -202,7 +202,7 @@ class EntitlementViewSetTest(ModuleStoreTestCase):
...
@@ -202,7 +202,7 @@ class EntitlementViewSetTest(ModuleStoreTestCase):
@unittest.skipUnless
(
settings
.
ROOT_URLCONF
==
'lms.urls'
,
'Test only valid in lms'
)
@unittest.skipUnless
(
settings
.
ROOT_URLCONF
==
'lms.urls'
,
'Test only valid in lms'
)
@patch
(
"openedx.core.djangoapps.catalog.utils.get_course_runs_for_course"
)
#
@patch("openedx.core.djangoapps.catalog.utils.get_course_runs_for_course")
class
EntitlementEnrollmentViewSetTest
(
ModuleStoreTestCase
):
class
EntitlementEnrollmentViewSetTest
(
ModuleStoreTestCase
):
ENTITLEMENTS_ENROLLMENT_NAMESPACE
=
'entitlements_api:v1:enrollments'
ENTITLEMENTS_ENROLLMENT_NAMESPACE
=
'entitlements_api:v1:enrollments'
...
@@ -212,36 +212,17 @@ class EntitlementEnrollmentViewSetTest(ModuleStoreTestCase):
...
@@ -212,36 +212,17 @@ class EntitlementEnrollmentViewSetTest(ModuleStoreTestCase):
self
.
client
.
login
(
username
=
self
.
user
.
username
,
password
=
TEST_PASSWORD
)
self
.
client
.
login
(
username
=
self
.
user
.
username
,
password
=
TEST_PASSWORD
)
self
.
course
=
CourseFactory
.
create
(
org
=
'edX'
,
number
=
'DemoX'
,
display_name
=
'Demo_Course'
)
self
.
course
=
CourseFactory
.
create
(
org
=
'edX'
,
number
=
'DemoX'
,
display_name
=
'Demo_Course'
)
self
.
course2
=
CourseFactory
.
create
(
org
=
'edX'
,
number
=
'DemoX2'
,
display_name
=
'Demo_Course 2'
)
self
.
course2
=
CourseFactory
.
create
(
org
=
'edX'
,
number
=
'DemoX2'
,
display_name
=
'Demo_Course 2'
)
self
.
patcher
=
patch
(
"openedx.core.djangoapps.catalog.utils.get_course_runs_for_course"
)
def
test_user_can_enroll
(
self
,
mock_get_course_runs
):
self
.
mock_get_course_runs
=
self
.
patcher
.
start
()
course_entitlement
=
CourseEntitlementFactory
(
self
.
mock_get_course_runs
.
return_value
=
[
user
=
self
.
user
{
'key'
:
str
(
self
.
course
.
id
)},
)
{
'key'
:
str
(
self
.
course2
.
id
)}
url
=
reverse
(
self
.
ENTITLEMENTS_ENROLLMENT_NAMESPACE
,
args
=
[
str
(
course_entitlement
.
uuid
)]
)
assert
course_entitlement
.
enrollment_course_run
is
None
mock_get_course_runs
.
method
.
return_value
=
[
{
'key'
:
str
(
self
.
course
.
id
)}
]
]
data
=
{
def
tearDown
(
self
):
'course_run_id'
:
str
(
self
.
course
.
id
)
self
.
patcher
.
stop
()
}
response
=
self
.
client
.
post
(
url
,
data
=
json
.
dumps
(
data
),
content_type
=
'application/json'
,
)
course_entitlement
.
refresh_from_db
()
assert
response
.
status_code
==
201
def
test_user_can_enroll
(
self
):
assert
CourseEnrollment
.
is_enrolled
(
self
.
user
,
self
.
course
.
id
)
assert
course_entitlement
.
enrollment_course_run
is
not
None
def
test_user_can_unenroll
(
self
,
mock_get_course_runs
):
course_entitlement
=
CourseEntitlementFactory
(
course_entitlement
=
CourseEntitlementFactory
(
user
=
self
.
user
user
=
self
.
user
)
)
...
@@ -251,10 +232,6 @@ class EntitlementEnrollmentViewSetTest(ModuleStoreTestCase):
...
@@ -251,10 +232,6 @@ class EntitlementEnrollmentViewSetTest(ModuleStoreTestCase):
)
)
assert
course_entitlement
.
enrollment_course_run
is
None
assert
course_entitlement
.
enrollment_course_run
is
None
mock_get_course_runs
.
return_value
=
[
{
'key'
:
str
(
self
.
course
.
id
)}
]
data
=
{
data
=
{
'course_run_id'
:
str
(
self
.
course
.
id
)
'course_run_id'
:
str
(
self
.
course
.
id
)
}
}
...
@@ -267,18 +244,43 @@ class EntitlementEnrollmentViewSetTest(ModuleStoreTestCase):
...
@@ -267,18 +244,43 @@ class EntitlementEnrollmentViewSetTest(ModuleStoreTestCase):
assert
response
.
status_code
==
201
assert
response
.
status_code
==
201
assert
CourseEnrollment
.
is_enrolled
(
self
.
user
,
self
.
course
.
id
)
assert
CourseEnrollment
.
is_enrolled
(
self
.
user
,
self
.
course
.
id
)
assert
course_entitlement
.
enrollment_course_run
is
not
None
response
=
self
.
client
.
delete
(
def
test_user_can_unenroll
(
self
):
url
,
course_entitlement
=
CourseEntitlementFactory
(
content_type
=
'application/json'
,
user
=
self
.
user
)
)
assert
response
.
status_code
==
204
url
=
reverse
(
self
.
ENTITLEMENTS_ENROLLMENT_NAMESPACE
,
course_entitlement
.
refresh_from_db
()
args
=
[
str
(
course_entitlement
.
uuid
)]
assert
not
CourseEnrollment
.
is_enrolled
(
self
.
user
,
self
.
course
.
id
)
)
assert
course_entitlement
.
enrollment_course_run
is
None
assert
course_entitlement
.
enrollment_course_run
is
None
data
=
{
'course_run_id'
:
str
(
self
.
course
.
id
)
}
response
=
self
.
client
.
post
(
url
,
data
=
json
.
dumps
(
data
),
content_type
=
'application/json'
,
)
course_entitlement
.
refresh_from_db
()
assert
response
.
status_code
==
201
assert
CourseEnrollment
.
is_enrolled
(
self
.
user
,
self
.
course
.
id
)
response
=
self
.
client
.
delete
(
url
,
content_type
=
'application/json'
,
)
assert
response
.
status_code
==
204
course_entitlement
.
refresh_from_db
()
assert
not
CourseEnrollment
.
is_enrolled
(
self
.
user
,
self
.
course
.
id
)
assert
course_entitlement
.
enrollment_course_run
is
None
def
test_user_can_switch
(
self
):
def
test_user_can_switch
(
self
,
mock_get_course_runs
):
course_entitlement
=
CourseEntitlementFactory
(
course_entitlement
=
CourseEntitlementFactory
(
user
=
self
.
user
user
=
self
.
user
)
)
...
@@ -288,11 +290,6 @@ class EntitlementEnrollmentViewSetTest(ModuleStoreTestCase):
...
@@ -288,11 +290,6 @@ class EntitlementEnrollmentViewSetTest(ModuleStoreTestCase):
)
)
assert
course_entitlement
.
enrollment_course_run
is
None
assert
course_entitlement
.
enrollment_course_run
is
None
mock_get_course_runs
.
return_value
=
[
{
'key'
:
str
(
self
.
course
.
id
)},
{
'key'
:
str
(
self
.
course2
.
id
)}
]
data
=
{
data
=
{
'course_run_id'
:
str
(
self
.
course
.
id
)
'course_run_id'
:
str
(
self
.
course
.
id
)
}
}
...
@@ -319,4 +316,4 @@ class EntitlementEnrollmentViewSetTest(ModuleStoreTestCase):
...
@@ -319,4 +316,4 @@ class EntitlementEnrollmentViewSetTest(ModuleStoreTestCase):
course_entitlement
.
refresh_from_db
()
course_entitlement
.
refresh_from_db
()
assert
CourseEnrollment
.
is_enrolled
(
self
.
user
,
self
.
course2
.
id
)
assert
CourseEnrollment
.
is_enrolled
(
self
.
user
,
self
.
course2
.
id
)
assert
course_entitlement
.
enrollment_course_run
is
not
None
assert
course_entitlement
.
enrollment_course_run
is
not
None
print
course_entitlement
.
enrollment_course_run
.
course_id
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