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
85e4274a
Commit
85e4274a
authored
Aug 02, 2017
by
Clinton Blackburn
Committed by
Clinton Blackburn
Aug 05, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactored tests for date summary blocks
parent
1e7f7df7
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
203 additions
and
157 deletions
+203
-157
lms/djangoapps/courseware/tests/test_date_summary.py
+203
-157
No files found.
lms/djangoapps/courseware/tests/test_date_summary.py
View file @
85e4274a
...
@@ -38,146 +38,158 @@ class CourseDateSummaryTest(SharedModuleStoreTestCase):
...
@@ -38,146 +38,158 @@ class CourseDateSummaryTest(SharedModuleStoreTestCase):
"""Tests for course date summary blocks."""
"""Tests for course date summary blocks."""
def
setUp
(
self
):
def
setUp
(
self
):
SelfPacedConfiguration
(
enable_course_home_improvements
=
True
)
.
save
()
super
(
CourseDateSummaryTest
,
self
)
.
setUp
()
super
(
CourseDateSummaryTest
,
self
)
.
setUp
()
SelfPacedConfiguration
.
objects
.
create
(
enable_course_home_improvements
=
True
)
def
setup_course_and_user
(
def
create_course_run
(
self
,
days_till_start
=
1
,
days_till_end
=
14
,
days_till_upgrade_deadline
=
4
,
self
,
days_till_verification_deadline
=
14
):
days_till_start
=
1
,
""" Create a new course run and course modes.
days_till_end
=
14
,
days_till_upgrade_deadline
=
4
,
enroll_user
=
True
,
enrollment_mode
=
CourseMode
.
VERIFIED
,
user_enrollment_mode
=
None
,
course_min_price
=
100
,
days_till_verification_deadline
=
14
,
verification_status
=
None
,
sku
=
None
,
create_user
=
True
):
"""Set up the course and user for this test."""
now
=
datetime
.
now
(
utc
)
# pylint: disable=attribute-defined-outside-init
All date-related arguments are relative to the current date-time (now) unless otherwise specified.
if
create_user
:
self
.
user
=
UserFactory
()
self
.
course
=
CourseFactory
.
create
(
start
=
now
+
timedelta
(
days
=
days_till_start
))
Both audit and verified `CourseMode` objects will be created for the course run.
Arguments:
days_till_end (int): Number of days until the course ends.
days_till_start (int): Number of days until the course starts.
days_till_upgrade_deadline (int): Number of days until the course run's upgrade deadline.
days_till_verification_deadline (int): Number of days until the course run's verification deadline. If this
value is set to `None` no deadline will be verification deadline will be created.
"""
now
=
datetime
.
now
(
utc
)
course
=
CourseFactory
.
create
(
start
=
now
+
timedelta
(
days
=
days_till_start
))
course
.
end
=
None
if
days_till_end
is
not
None
:
if
days_till_end
is
not
None
:
self
.
course
.
end
=
now
+
timedelta
(
days
=
days_till_end
)
course
.
end
=
now
+
timedelta
(
days
=
days_till_end
)
else
:
self
.
course
.
end
=
None
if
enrollment_mode
is
not
None
and
days_till_upgrade_deadline
is
not
None
:
CourseModeFactory
.
create
(
course_id
=
self
.
course
.
id
,
mode_slug
=
enrollment_mode
,
expiration_datetime
=
now
+
timedelta
(
days
=
days_till_upgrade_deadline
),
min_price
=
course_min_price
,
sku
=
sku
)
if
enroll_user
:
CourseModeFactory
(
course_id
=
course
.
id
,
mode_slug
=
CourseMode
.
AUDIT
)
if
user_enrollment_mode
:
CourseModeFactory
(
CourseEnrollmentFactory
.
create
(
course_id
=
self
.
course
.
id
,
user
=
self
.
user
,
mode
=
user_enrollment_mode
)
course_id
=
course
.
id
,
else
:
mode_slug
=
CourseMode
.
VERIFIED
,
enrollment_mode
=
enrollment_mode
or
CourseMode
.
DEFAULT_MODE_SLUG
expiration_datetime
=
now
+
timedelta
(
days
=
days_till_upgrade_deadline
)
CourseEnrollmentFactory
.
create
(
course_id
=
self
.
course
.
id
,
user
=
self
.
user
,
mode
=
enrollment_mode
)
)
if
days_till_verification_deadline
is
not
None
:
if
days_till_verification_deadline
is
not
None
:
VerificationDeadline
.
objects
.
create
(
VerificationDeadline
.
objects
.
create
(
course_key
=
self
.
course
.
id
,
course_key
=
course
.
id
,
deadline
=
now
+
timedelta
(
days
=
days_till_verification_deadline
)
deadline
=
now
+
timedelta
(
days
=
days_till_verification_deadline
)
)
)
return
course
def
create_user
(
self
,
verification_status
=
None
):
""" Create a new User instance.
Arguments:
verification_status (str): User's verification status. If this value is set an instance of
SoftwareSecurePhotoVerification will be created for the user with the specified status.
"""
user
=
UserFactory
()
if
verification_status
is
not
None
:
if
verification_status
is
not
None
:
SoftwareSecurePhotoVerificationFactory
.
create
(
user
=
self
.
user
,
status
=
verification_status
)
SoftwareSecurePhotoVerificationFactory
.
create
(
user
=
user
,
status
=
verification_status
)
return
user
def
test_course_info_feature_flag
(
self
):
def
test_course_info_feature_flag
(
self
):
SelfPacedConfiguration
(
enable_course_home_improvements
=
False
)
.
save
()
SelfPacedConfiguration
(
enable_course_home_improvements
=
False
)
.
save
()
self
.
setup_course_and_user
()
course
=
self
.
create_course_run
()
self
.
client
.
login
(
username
=
self
.
user
.
username
,
password
=
TEST_PASSWORD
)
user
=
self
.
create_user
()
url
=
reverse
(
'info'
,
args
=
(
self
.
course
.
id
,))
CourseEnrollmentFactory
(
course_id
=
course
.
id
,
user
=
user
,
mode
=
CourseMode
.
VERIFIED
)
self
.
client
.
login
(
username
=
user
.
username
,
password
=
TEST_PASSWORD
)
url
=
reverse
(
'info'
,
args
=
(
course
.
id
,))
response
=
self
.
client
.
get
(
url
)
response
=
self
.
client
.
get
(
url
)
self
.
assertNotIn
(
'date-summary'
,
response
.
content
)
self
.
assertNotIn
(
'date-summary'
,
response
.
content
)
def
test_course_info_logged_out
(
self
):
def
test_course_info_logged_out
(
self
):
self
.
setup_course_and_user
()
course
=
self
.
create_course_run
()
url
=
reverse
(
'info'
,
args
=
(
self
.
course
.
id
,))
url
=
reverse
(
'info'
,
args
=
(
course
.
id
,))
response
=
self
.
client
.
get
(
url
)
response
=
self
.
client
.
get
(
url
)
self
.
assertEqual
(
200
,
response
.
status_code
)
self
.
assertEqual
(
200
,
response
.
status_code
)
# Tests for which blocks are enabled
# Tests for which blocks are enabled
def
assert_block_types
(
self
,
expected_blocks
):
def
assert_block_types
(
self
,
course
,
user
,
expected_blocks
):
"""Assert that the enabled block types for this course are as expected."""
"""Assert that the enabled block types for this course are as expected."""
blocks
=
get_course_date_blocks
(
self
.
course
,
self
.
user
)
blocks
=
get_course_date_blocks
(
course
,
user
)
self
.
assertEqual
(
len
(
blocks
),
len
(
expected_blocks
))
self
.
assertEqual
(
len
(
blocks
),
len
(
expected_blocks
))
self
.
assertEqual
(
set
(
type
(
b
)
for
b
in
blocks
),
set
(
expected_blocks
))
self
.
assertEqual
(
set
(
type
(
b
)
for
b
in
blocks
),
set
(
expected_blocks
))
@ddt.data
(
@ddt.data
(
# Verified enrollment with no photo-verification before course start
# Verified enrollment with no photo-verification before course start
({},
(
CourseEndDate
,
CourseStartDate
,
TodaysDate
,
VerificationDeadlineDate
)),
({},
{},
(
CourseEndDate
,
CourseStartDate
,
TodaysDate
,
VerificationDeadlineDate
)),
# Verified enrollment with `approved` photo-verification after course end
# Verified enrollment with `approved` photo-verification after course end
({
'days_till_start'
:
-
10
,
({
'days_till_start'
:
-
10
,
'days_till_end'
:
-
5
,
'days_till_end'
:
-
5
,
'days_till_upgrade_deadline'
:
-
6
,
'days_till_upgrade_deadline'
:
-
6
,
'days_till_verification_deadline'
:
-
5
,
'days_till_verification_deadline'
:
-
5
,
'verification_status'
:
'approved'
},
},
{
'verification_status'
:
'approved'
},
(
TodaysDate
,
CourseEndDate
)),
(
TodaysDate
,
CourseEndDate
)),
# Verified enrollment with `expired` photo-verification during course run
# Verified enrollment with `expired` photo-verification during course run
({
'days_till_start'
:
-
10
,
({
'days_till_start'
:
-
10
}
,
'verification_status'
:
'expired'
},
{
'verification_status'
:
'expired'
},
(
TodaysDate
,
CourseEndDate
,
VerificationDeadlineDate
)),
(
TodaysDate
,
CourseEndDate
,
VerificationDeadlineDate
)),
# Verified enrollment with `approved` photo-verification during course run
# Verified enrollment with `approved` photo-verification during course run
({
'days_till_start'
:
-
10
,
({
'days_till_start'
:
-
10
,
},
'verification_status'
:
'approved'
},
{
'verification_status'
:
'approved'
},
(
TodaysDate
,
CourseEndDate
)),
# Audit enrollment and non-upsell course.
({
'days_till_start'
:
-
10
,
'days_till_upgrade_deadline'
:
None
,
'days_till_verification_deadline'
:
None
,
'course_min_price'
:
0
,
'enrollment_mode'
:
CourseMode
.
AUDIT
},
(
TodaysDate
,
CourseEndDate
)),
(
TodaysDate
,
CourseEndDate
)),
# Verified enrollment with *NO* course end date
# Verified enrollment with *NO* course end date
({
'days_till_end'
:
None
},
({
'days_till_end'
:
None
},
{},
(
CourseStartDate
,
TodaysDate
,
VerificationDeadlineDate
)),
(
CourseStartDate
,
TodaysDate
,
VerificationDeadlineDate
)),
# Verified enrollment with no photo-verification during course run
# Verified enrollment with no photo-verification during course run
({
'days_till_start'
:
-
1
},
({
'days_till_start'
:
-
1
},
{},
(
TodaysDate
,
CourseEndDate
,
VerificationDeadlineDate
)),
(
TodaysDate
,
CourseEndDate
,
VerificationDeadlineDate
)),
# Verification approved
# Verification approved
({
'days_till_start'
:
-
10
,
({
'days_till_start'
:
-
10
,
'days_till_upgrade_deadline'
:
-
1
,
'days_till_upgrade_deadline'
:
-
1
,
'days_till_verification_deadline'
:
1
,
'days_till_verification_deadline'
:
1
,
'verification_status'
:
'approved'
},
},
{
'verification_status'
:
'approved'
},
(
TodaysDate
,
CourseEndDate
)),
(
TodaysDate
,
CourseEndDate
)),
# After upgrade deadline
# After upgrade deadline
({
'days_till_start'
:
-
10
,
({
'days_till_start'
:
-
10
,
'days_till_upgrade_deadline'
:
-
1
},
'days_till_upgrade_deadline'
:
-
1
},
{},
(
TodaysDate
,
CourseEndDate
,
VerificationDeadlineDate
)),
(
TodaysDate
,
CourseEndDate
,
VerificationDeadlineDate
)),
# After verification deadline
# After verification deadline
({
'days_till_start'
:
-
10
,
({
'days_till_start'
:
-
10
,
'days_till_upgrade_deadline'
:
-
2
,
'days_till_upgrade_deadline'
:
-
2
,
'days_till_verification_deadline'
:
-
1
},
'days_till_verification_deadline'
:
-
1
},
{},
(
TodaysDate
,
CourseEndDate
,
VerificationDeadlineDate
)),
(
TodaysDate
,
CourseEndDate
,
VerificationDeadlineDate
)),
# Un-enrolled user before course start
)
({
'enroll_user'
:
False
},
@ddt.unpack
(
CourseStartDate
,
TodaysDate
,
CourseEndDate
,
VerifiedUpgradeDeadlineDate
)),
def
test_enabled_block_types
(
self
,
course_kwargs
,
user_kwargs
,
expected_blocks
):
# Un-enrolled user during course run
course
=
self
.
create_course_run
(
**
course_kwargs
)
({
'days_till_start'
:
-
1
,
user
=
self
.
create_user
(
**
user_kwargs
)
'enroll_user'
:
False
},
CourseEnrollmentFactory
(
course_id
=
course
.
id
,
user
=
user
,
mode
=
CourseMode
.
VERIFIED
)
(
TodaysDate
,
CourseEndDate
,
VerifiedUpgradeDeadlineDate
)),
self
.
assert_block_types
(
course
,
user
,
expected_blocks
)
# Un-enrolled user after course end.
({
'enroll_user'
:
False
,
@ddt.data
(
'days_till_start'
:
-
10
,
# Course not started
'days_till_end'
:
-
5
},
({},
(
CourseStartDate
,
TodaysDate
,
CourseEndDate
,
VerifiedUpgradeDeadlineDate
)),
# Course active
({
'days_till_start'
:
-
1
},
(
TodaysDate
,
CourseEndDate
,
VerifiedUpgradeDeadlineDate
)),
# Course ended
({
'days_till_start'
:
-
10
,
'days_till_end'
:
-
5
},
(
TodaysDate
,
CourseEndDate
,
VerifiedUpgradeDeadlineDate
)),
(
TodaysDate
,
CourseEndDate
,
VerifiedUpgradeDeadlineDate
)),
)
)
@ddt.unpack
@ddt.unpack
def
test_enabled_block_types
(
self
,
course_options
,
expected_blocks
):
def
test_enabled_block_types_without_enrollment
(
self
,
course_kwargs
,
expected_blocks
):
self
.
setup_course_and_user
(
**
course_options
)
course
=
self
.
create_course_run
(
**
course_kwargs
)
self
.
assert_block_types
(
expected_blocks
)
user
=
self
.
create_user
()
self
.
assert_block_types
(
course
,
user
,
expected_blocks
)
def
test_enabled_block_types_with_non_upgradeable_course_run
(
self
):
course
=
self
.
create_course_run
(
days_till_start
=-
10
,
days_till_verification_deadline
=
None
)
user
=
self
.
create_user
()
CourseMode
.
objects
.
get
(
course_id
=
course
.
id
,
mode_slug
=
CourseMode
.
VERIFIED
)
.
delete
()
CourseEnrollmentFactory
(
course_id
=
course
.
id
,
user
=
user
,
mode
=
CourseMode
.
AUDIT
)
self
.
assert_block_types
(
course
,
user
,
(
TodaysDate
,
CourseEndDate
))
def
test_todays_date_block
(
self
):
def
test_todays_date_block
(
self
):
"""
"""
...
@@ -185,8 +197,9 @@ class CourseDateSummaryTest(SharedModuleStoreTestCase):
...
@@ -185,8 +197,9 @@ class CourseDateSummaryTest(SharedModuleStoreTestCase):
and displays the correct time, accounting for daylight savings
and displays the correct time, accounting for daylight savings
"""
"""
with
freeze_time
(
'2015-01-02'
):
with
freeze_time
(
'2015-01-02'
):
self
.
setup_course_and_user
()
course
=
self
.
create_course_run
()
block
=
TodaysDate
(
self
.
course
,
self
.
user
)
user
=
self
.
create_user
()
block
=
TodaysDate
(
course
,
user
)
self
.
assertTrue
(
block
.
is_enabled
)
self
.
assertTrue
(
block
.
is_enabled
)
self
.
assertEqual
(
block
.
date
,
datetime
.
now
(
utc
))
self
.
assertEqual
(
block
.
date
,
datetime
.
now
(
utc
))
self
.
assertEqual
(
block
.
title
,
'current_datetime'
)
self
.
assertEqual
(
block
.
title
,
'current_datetime'
)
...
@@ -198,8 +211,9 @@ class CourseDateSummaryTest(SharedModuleStoreTestCase):
...
@@ -198,8 +211,9 @@ class CourseDateSummaryTest(SharedModuleStoreTestCase):
@override_waffle_flag
(
UNIFIED_COURSE_TAB_FLAG
,
active
=
True
)
@override_waffle_flag
(
UNIFIED_COURSE_TAB_FLAG
,
active
=
True
)
def
test_todays_date_no_timezone
(
self
,
url_name
):
def
test_todays_date_no_timezone
(
self
,
url_name
):
with
freeze_time
(
'2015-01-02'
):
with
freeze_time
(
'2015-01-02'
):
self
.
setup_course_and_user
()
course
=
self
.
create_course_run
()
self
.
client
.
login
(
username
=
self
.
user
.
username
,
password
=
TEST_PASSWORD
)
user
=
self
.
create_user
()
self
.
client
.
login
(
username
=
user
.
username
,
password
=
TEST_PASSWORD
)
html_elements
=
[
html_elements
=
[
'<h3 class="hd hd-6 handouts-header">Important Course Dates</h3>'
,
'<h3 class="hd hd-6 handouts-header">Important Course Dates</h3>'
,
...
@@ -210,7 +224,7 @@ class CourseDateSummaryTest(SharedModuleStoreTestCase):
...
@@ -210,7 +224,7 @@ class CourseDateSummaryTest(SharedModuleStoreTestCase):
'data-string="Today is {date}"'
,
'data-string="Today is {date}"'
,
'data-timezone="None"'
'data-timezone="None"'
]
]
url
=
reverse
(
url_name
,
args
=
(
self
.
course
.
id
,))
url
=
reverse
(
url_name
,
args
=
(
course
.
id
,))
response
=
self
.
client
.
get
(
url
,
follow
=
True
)
response
=
self
.
client
.
get
(
url
,
follow
=
True
)
for
html
in
html_elements
:
for
html
in
html_elements
:
self
.
assertContains
(
response
,
html
)
self
.
assertContains
(
response
,
html
)
...
@@ -222,10 +236,11 @@ class CourseDateSummaryTest(SharedModuleStoreTestCase):
...
@@ -222,10 +236,11 @@ class CourseDateSummaryTest(SharedModuleStoreTestCase):
@override_waffle_flag
(
UNIFIED_COURSE_TAB_FLAG
,
active
=
True
)
@override_waffle_flag
(
UNIFIED_COURSE_TAB_FLAG
,
active
=
True
)
def
test_todays_date_timezone
(
self
,
url_name
):
def
test_todays_date_timezone
(
self
,
url_name
):
with
freeze_time
(
'2015-01-02'
):
with
freeze_time
(
'2015-01-02'
):
self
.
setup_course_and_user
()
course
=
self
.
create_course_run
()
self
.
client
.
login
(
username
=
self
.
user
.
username
,
password
=
TEST_PASSWORD
)
user
=
self
.
create_user
()
set_user_preference
(
self
.
user
,
"time_zone"
,
"America/Los_Angeles"
)
self
.
client
.
login
(
username
=
user
.
username
,
password
=
TEST_PASSWORD
)
url
=
reverse
(
url_name
,
args
=
(
self
.
course
.
id
,))
set_user_preference
(
user
,
'time_zone'
,
'America/Los_Angeles'
)
url
=
reverse
(
url_name
,
args
=
(
course
.
id
,))
response
=
self
.
client
.
get
(
url
,
follow
=
True
)
response
=
self
.
client
.
get
(
url
,
follow
=
True
)
html_elements
=
[
html_elements
=
[
...
@@ -242,9 +257,10 @@ class CourseDateSummaryTest(SharedModuleStoreTestCase):
...
@@ -242,9 +257,10 @@ class CourseDateSummaryTest(SharedModuleStoreTestCase):
## Tests Course Start Date
## Tests Course Start Date
def
test_course_start_date
(
self
):
def
test_course_start_date
(
self
):
self
.
setup_course_and_user
()
course
=
self
.
create_course_run
()
block
=
CourseStartDate
(
self
.
course
,
self
.
user
)
user
=
self
.
create_user
()
self
.
assertEqual
(
block
.
date
,
self
.
course
.
start
)
block
=
CourseStartDate
(
course
,
user
)
self
.
assertEqual
(
block
.
date
,
course
.
start
)
@ddt.data
(
@ddt.data
(
'info'
,
'info'
,
...
@@ -253,9 +269,10 @@ class CourseDateSummaryTest(SharedModuleStoreTestCase):
...
@@ -253,9 +269,10 @@ class CourseDateSummaryTest(SharedModuleStoreTestCase):
@override_waffle_flag
(
UNIFIED_COURSE_TAB_FLAG
,
active
=
True
)
@override_waffle_flag
(
UNIFIED_COURSE_TAB_FLAG
,
active
=
True
)
def
test_start_date_render
(
self
,
url_name
):
def
test_start_date_render
(
self
,
url_name
):
with
freeze_time
(
'2015-01-02'
):
with
freeze_time
(
'2015-01-02'
):
self
.
setup_course_and_user
()
course
=
self
.
create_course_run
()
self
.
client
.
login
(
username
=
self
.
user
.
username
,
password
=
TEST_PASSWORD
)
user
=
self
.
create_user
()
url
=
reverse
(
url_name
,
args
=
(
self
.
course
.
id
,))
self
.
client
.
login
(
username
=
user
.
username
,
password
=
TEST_PASSWORD
)
url
=
reverse
(
url_name
,
args
=
(
course
.
id
,))
response
=
self
.
client
.
get
(
url
,
follow
=
True
)
response
=
self
.
client
.
get
(
url
,
follow
=
True
)
html_elements
=
[
html_elements
=
[
'data-string="in 1 day - {date}"'
,
'data-string="in 1 day - {date}"'
,
...
@@ -271,10 +288,11 @@ class CourseDateSummaryTest(SharedModuleStoreTestCase):
...
@@ -271,10 +288,11 @@ class CourseDateSummaryTest(SharedModuleStoreTestCase):
@override_waffle_flag
(
UNIFIED_COURSE_TAB_FLAG
,
active
=
True
)
@override_waffle_flag
(
UNIFIED_COURSE_TAB_FLAG
,
active
=
True
)
def
test_start_date_render_time_zone
(
self
,
url_name
):
def
test_start_date_render_time_zone
(
self
,
url_name
):
with
freeze_time
(
'2015-01-02'
):
with
freeze_time
(
'2015-01-02'
):
self
.
setup_course_and_user
()
course
=
self
.
create_course_run
()
self
.
client
.
login
(
username
=
self
.
user
.
username
,
password
=
TEST_PASSWORD
)
user
=
self
.
create_user
()
set_user_preference
(
self
.
user
,
"time_zone"
,
"America/Los_Angeles"
)
self
.
client
.
login
(
username
=
user
.
username
,
password
=
TEST_PASSWORD
)
url
=
reverse
(
url_name
,
args
=
(
self
.
course
.
id
,))
set_user_preference
(
user
,
'time_zone'
,
'America/Los_Angeles'
)
url
=
reverse
(
url_name
,
args
=
(
course
.
id
,))
response
=
self
.
client
.
get
(
url
,
follow
=
True
)
response
=
self
.
client
.
get
(
url
,
follow
=
True
)
html_elements
=
[
html_elements
=
[
'data-string="in 1 day - {date}"'
,
'data-string="in 1 day - {date}"'
,
...
@@ -286,16 +304,20 @@ class CourseDateSummaryTest(SharedModuleStoreTestCase):
...
@@ -286,16 +304,20 @@ class CourseDateSummaryTest(SharedModuleStoreTestCase):
## Tests Course End Date Block
## Tests Course End Date Block
def
test_course_end_date_for_certificate_eligible_mode
(
self
):
def
test_course_end_date_for_certificate_eligible_mode
(
self
):
self
.
setup_course_and_user
(
days_till_start
=-
1
)
course
=
self
.
create_course_run
(
days_till_start
=-
1
)
block
=
CourseEndDate
(
self
.
course
,
self
.
user
)
user
=
self
.
create_user
()
CourseEnrollmentFactory
(
course_id
=
course
.
id
,
user
=
user
,
mode
=
CourseMode
.
VERIFIED
)
block
=
CourseEndDate
(
course
,
user
)
self
.
assertEqual
(
self
.
assertEqual
(
block
.
description
,
block
.
description
,
'To earn a certificate, you must complete all requirements before this date.'
'To earn a certificate, you must complete all requirements before this date.'
)
)
def
test_course_end_date_for_non_certificate_eligible_mode
(
self
):
def
test_course_end_date_for_non_certificate_eligible_mode
(
self
):
self
.
setup_course_and_user
(
days_till_start
=-
1
,
enrollment_mode
=
CourseMode
.
AUDIT
)
course
=
self
.
create_course_run
(
days_till_start
=-
1
)
block
=
CourseEndDate
(
self
.
course
,
self
.
user
)
user
=
self
.
create_user
()
CourseEnrollmentFactory
(
course_id
=
course
.
id
,
user
=
user
,
mode
=
CourseMode
.
AUDIT
)
block
=
CourseEndDate
(
course
,
user
)
self
.
assertEqual
(
self
.
assertEqual
(
block
.
description
,
block
.
description
,
'After this date, course content will be archived.'
'After this date, course content will be archived.'
...
@@ -303,8 +325,10 @@ class CourseDateSummaryTest(SharedModuleStoreTestCase):
...
@@ -303,8 +325,10 @@ class CourseDateSummaryTest(SharedModuleStoreTestCase):
self
.
assertEqual
(
block
.
title
,
'Course End'
)
self
.
assertEqual
(
block
.
title
,
'Course End'
)
def
test_course_end_date_after_course
(
self
):
def
test_course_end_date_after_course
(
self
):
self
.
setup_course_and_user
(
days_till_start
=-
2
,
days_till_end
=-
1
)
course
=
self
.
create_course_run
(
days_till_start
=-
2
,
days_till_end
=-
1
)
block
=
CourseEndDate
(
self
.
course
,
self
.
user
)
user
=
self
.
create_user
()
CourseEnrollmentFactory
(
course_id
=
course
.
id
,
user
=
user
,
mode
=
CourseMode
.
VERIFIED
)
block
=
CourseEndDate
(
course
,
user
)
self
.
assertEqual
(
self
.
assertEqual
(
block
.
description
,
block
.
description
,
'This course is archived, which means you can review course content but it is no longer active.'
'This course is archived, which means you can review course content but it is no longer active.'
...
@@ -315,25 +339,38 @@ class CourseDateSummaryTest(SharedModuleStoreTestCase):
...
@@ -315,25 +339,38 @@ class CourseDateSummaryTest(SharedModuleStoreTestCase):
"""Verify the block link redirects to ecommerce checkout if it's enabled."""
"""Verify the block link redirects to ecommerce checkout if it's enabled."""
sku
=
'TESTSKU'
sku
=
'TESTSKU'
configuration
=
CommerceConfiguration
.
objects
.
create
(
checkout_on_ecommerce_service
=
True
)
configuration
=
CommerceConfiguration
.
objects
.
create
(
checkout_on_ecommerce_service
=
True
)
self
.
setup_course_and_user
(
sku
=
sku
)
course
=
self
.
create_course_run
()
block
=
VerifiedUpgradeDeadlineDate
(
self
.
course
,
self
.
user
)
user
=
self
.
create_user
()
course_mode
=
CourseMode
.
objects
.
get
(
course_id
=
course
.
id
,
mode_slug
=
CourseMode
.
VERIFIED
)
course_mode
.
sku
=
sku
course_mode
.
save
()
CourseEnrollmentFactory
(
course_id
=
course
.
id
,
user
=
user
,
mode
=
CourseMode
.
VERIFIED
)
block
=
VerifiedUpgradeDeadlineDate
(
course
,
user
)
self
.
assertEqual
(
block
.
link
,
'{}?sku={}'
.
format
(
configuration
.
MULTIPLE_ITEMS_BASKET_PAGE_URL
,
sku
))
self
.
assertEqual
(
block
.
link
,
'{}?sku={}'
.
format
(
configuration
.
MULTIPLE_ITEMS_BASKET_PAGE_URL
,
sku
))
## VerificationDeadlineDate
## VerificationDeadlineDate
def
test_no_verification_deadline
(
self
):
def
test_no_verification_deadline
(
self
):
self
.
setup_course_and_user
(
days_till_start
=-
1
,
days_till_verification_deadline
=
None
)
course
=
self
.
create_course_run
(
days_till_start
=-
1
,
days_till_verification_deadline
=
None
)
block
=
VerificationDeadlineDate
(
self
.
course
,
self
.
user
)
user
=
self
.
create_user
()
CourseEnrollmentFactory
(
course_id
=
course
.
id
,
user
=
user
,
mode
=
CourseMode
.
VERIFIED
)
block
=
VerificationDeadlineDate
(
course
,
user
)
self
.
assertFalse
(
block
.
is_enabled
)
self
.
assertFalse
(
block
.
is_enabled
)
def
test_no_verified_enrollment
(
self
):
def
test_no_verified_enrollment
(
self
):
self
.
setup_course_and_user
(
days_till_start
=-
1
,
enrollment_mode
=
CourseMode
.
AUDIT
)
course
=
self
.
create_course_run
(
days_till_start
=-
1
)
block
=
VerificationDeadlineDate
(
self
.
course
,
self
.
user
)
user
=
self
.
create_user
()
CourseEnrollmentFactory
(
course_id
=
course
.
id
,
user
=
user
,
mode
=
CourseMode
.
AUDIT
)
block
=
VerificationDeadlineDate
(
course
,
user
)
self
.
assertFalse
(
block
.
is_enabled
)
self
.
assertFalse
(
block
.
is_enabled
)
def
test_verification_deadline_date_upcoming
(
self
):
def
test_verification_deadline_date_upcoming
(
self
):
with
freeze_time
(
'2015-01-02'
):
with
freeze_time
(
'2015-01-02'
):
self
.
setup_course_and_user
(
days_till_start
=-
1
)
course
=
self
.
create_course_run
(
days_till_start
=-
1
)
block
=
VerificationDeadlineDate
(
self
.
course
,
self
.
user
)
user
=
self
.
create_user
()
CourseEnrollmentFactory
(
course_id
=
course
.
id
,
user
=
user
,
mode
=
CourseMode
.
VERIFIED
)
block
=
VerificationDeadlineDate
(
course
,
user
)
self
.
assertEqual
(
block
.
css_class
,
'verification-deadline-upcoming'
)
self
.
assertEqual
(
block
.
css_class
,
'verification-deadline-upcoming'
)
self
.
assertEqual
(
block
.
title
,
'Verification Deadline'
)
self
.
assertEqual
(
block
.
title
,
'Verification Deadline'
)
self
.
assertEqual
(
block
.
date
,
datetime
.
now
(
utc
)
+
timedelta
(
days
=
14
))
self
.
assertEqual
(
block
.
date
,
datetime
.
now
(
utc
)
+
timedelta
(
days
=
14
))
...
@@ -342,12 +379,15 @@ class CourseDateSummaryTest(SharedModuleStoreTestCase):
...
@@ -342,12 +379,15 @@ class CourseDateSummaryTest(SharedModuleStoreTestCase):
'You must successfully complete verification before this date to qualify for a Verified Certificate.'
'You must successfully complete verification before this date to qualify for a Verified Certificate.'
)
)
self
.
assertEqual
(
block
.
link_text
,
'Verify My Identity'
)
self
.
assertEqual
(
block
.
link_text
,
'Verify My Identity'
)
self
.
assertEqual
(
block
.
link
,
reverse
(
'verify_student_verify_now'
,
args
=
(
self
.
course
.
id
,)))
self
.
assertEqual
(
block
.
link
,
reverse
(
'verify_student_verify_now'
,
args
=
(
course
.
id
,)))
def
test_verification_deadline_date_retry
(
self
):
def
test_verification_deadline_date_retry
(
self
):
with
freeze_time
(
'2015-01-02'
):
with
freeze_time
(
'2015-01-02'
):
self
.
setup_course_and_user
(
days_till_start
=-
1
,
verification_status
=
'denied'
)
course
=
self
.
create_course_run
(
days_till_start
=-
1
)
block
=
VerificationDeadlineDate
(
self
.
course
,
self
.
user
)
user
=
self
.
create_user
(
verification_status
=
'denied'
)
CourseEnrollmentFactory
(
course_id
=
course
.
id
,
user
=
user
,
mode
=
CourseMode
.
VERIFIED
)
block
=
VerificationDeadlineDate
(
course
,
user
)
self
.
assertEqual
(
block
.
css_class
,
'verification-deadline-retry'
)
self
.
assertEqual
(
block
.
css_class
,
'verification-deadline-retry'
)
self
.
assertEqual
(
block
.
title
,
'Verification Deadline'
)
self
.
assertEqual
(
block
.
title
,
'Verification Deadline'
)
self
.
assertEqual
(
block
.
date
,
datetime
.
now
(
utc
)
+
timedelta
(
days
=
14
))
self
.
assertEqual
(
block
.
date
,
datetime
.
now
(
utc
)
+
timedelta
(
days
=
14
))
...
@@ -360,12 +400,11 @@ class CourseDateSummaryTest(SharedModuleStoreTestCase):
...
@@ -360,12 +400,11 @@ class CourseDateSummaryTest(SharedModuleStoreTestCase):
def
test_verification_deadline_date_denied
(
self
):
def
test_verification_deadline_date_denied
(
self
):
with
freeze_time
(
'2015-01-02'
):
with
freeze_time
(
'2015-01-02'
):
self
.
setup_course_and_user
(
course
=
self
.
create_course_run
(
days_till_start
=-
10
,
days_till_verification_deadline
=-
1
)
days_till_start
=-
10
,
user
=
self
.
create_user
(
verification_status
=
'denied'
)
verification_status
=
'denied'
,
CourseEnrollmentFactory
(
course_id
=
course
.
id
,
user
=
user
,
mode
=
CourseMode
.
VERIFIED
)
days_till_verification_deadline
=-
1
,
)
block
=
VerificationDeadlineDate
(
course
,
user
)
block
=
VerificationDeadlineDate
(
self
.
course
,
self
.
user
)
self
.
assertEqual
(
block
.
css_class
,
'verification-deadline-passed'
)
self
.
assertEqual
(
block
.
css_class
,
'verification-deadline-passed'
)
self
.
assertEqual
(
block
.
title
,
'Missed Verification Deadline'
)
self
.
assertEqual
(
block
.
title
,
'Missed Verification Deadline'
)
self
.
assertEqual
(
block
.
date
,
datetime
.
now
(
utc
)
+
timedelta
(
days
=-
1
))
self
.
assertEqual
(
block
.
date
,
datetime
.
now
(
utc
)
+
timedelta
(
days
=-
1
))
...
@@ -383,69 +422,76 @@ class CourseDateSummaryTest(SharedModuleStoreTestCase):
...
@@ -383,69 +422,76 @@ class CourseDateSummaryTest(SharedModuleStoreTestCase):
@ddt.unpack
@ddt.unpack
def
test_render_date_string_past
(
self
,
delta
,
expected_date_string
):
def
test_render_date_string_past
(
self
,
delta
,
expected_date_string
):
with
freeze_time
(
'2015-01-02'
):
with
freeze_time
(
'2015-01-02'
):
self
.
setup_course_and_user
(
course
=
self
.
create_course_run
(
days_till_start
=-
10
,
days_till_verification_deadline
=
delta
)
days_till_start
=-
10
,
user
=
self
.
create_user
(
verification_status
=
'denied'
)
verification_status
=
'denied'
,
CourseEnrollmentFactory
(
course_id
=
course
.
id
,
user
=
user
,
mode
=
CourseMode
.
VERIFIED
)
days_till_verification_deadline
=
delta
,
)
block
=
VerificationDeadlineDate
(
course
,
user
)
block
=
VerificationDeadlineDate
(
self
.
course
,
self
.
user
)
self
.
assertEqual
(
block
.
relative_datestring
,
expected_date_string
)
self
.
assertEqual
(
block
.
relative_datestring
,
expected_date_string
)
def
create_self_paced_course_run
(
self
,
**
kwargs
):
def
create_self_paced_course_run
(
self
,
**
kwargs
):
defaults
=
{
defaults
=
{
'enroll_user'
:
False
,
'days_till_upgrade_deadline'
:
100
,
'days_till_upgrade_deadline'
:
100
,
}
}
defaults
.
update
(
kwargs
)
defaults
.
update
(
kwargs
)
self
.
setup_course_and_user
(
**
defaults
)
self
.
course
.
self_paced
=
True
course
=
self
.
create_course_run
(
**
defaults
)
self
.
store
.
update_item
(
self
.
course
,
self
.
user
.
id
)
course
.
self_paced
=
True
overview
=
CourseOverview
.
get_from_id
(
self
.
course
.
id
)
self
.
store
.
update_item
(
course
,
None
)
overview
=
CourseOverview
.
get_from_id
(
course
.
id
)
self
.
assertTrue
(
overview
.
self_paced
)
self
.
assertTrue
(
overview
.
self_paced
)
def
test_date_with_self_paced
(
self
):
return
course
""" The date returned for self-paced course runs should be dependent on the learner's enrollment date. """
global_config
=
DynamicUpgradeDeadlineConfiguration
.
objects
.
create
(
enabled
=
True
)
# Enrollments made before the course start should use the course start date as the content availability date
def
assert_upgrade_deadline
(
self
,
course
,
expected
):
self
.
create_self_paced_course_run
(
days_till_start
=
3
)
""" Asserts the VerifiedUpgradeDeadlineDate block's date matches the expected value. """
CourseEnrollmentFactory
.
create
(
course_id
=
self
.
course
.
id
,
user
=
self
.
user
,
mode
=
CourseMode
.
AUDIT
)
enrollment
=
CourseEnrollmentFactory
(
course_id
=
course
.
id
,
mode
=
CourseMode
.
AUDIT
)
block
=
VerifiedUpgradeDeadlineDate
(
self
.
course
,
self
.
user
)
block
=
VerifiedUpgradeDeadlineDate
(
course
,
enrollment
.
user
)
overview
=
CourseOverview
.
get_from_id
(
self
.
course
.
id
)
expected
=
overview
.
start
+
timedelta
(
days
=
global_config
.
deadline_days
)
self
.
assertEqual
(
block
.
date
,
expected
)
self
.
assertEqual
(
block
.
date
,
expected
)
# Enrollments made after the course start should use the enrollment date as the content availability date
def
test_date_with_self_paced_with_enrollment_before_course_start
(
self
):
self
.
create_self_paced_course_run
(
days_till_start
=-
1
)
""" Enrolling before a course begins should result in the upgrade deadline being set relative to the
enrollment
=
CourseEnrollmentFactory
.
create
(
course_id
=
self
.
course
.
id
,
user
=
self
.
user
,
mode
=
CourseMode
.
AUDIT
)
course start date. """
block
=
VerifiedUpgradeDeadlineDate
(
self
.
course
,
self
.
user
)
global_config
=
DynamicUpgradeDeadlineConfiguration
.
objects
.
create
(
enabled
=
True
)
course
=
self
.
create_self_paced_course_run
(
days_till_start
=
3
)
overview
=
CourseOverview
.
get_from_id
(
course
.
id
)
expected
=
overview
.
start
+
timedelta
(
days
=
global_config
.
deadline_days
)
self
.
assert_upgrade_deadline
(
course
,
expected
)
def
test_date_with_self_paced_with_enrollment_after_course_start
(
self
):
""" Enrolling after a course begins should result in the upgrade deadline being set relative to the
enrollment date. """
global_config
=
DynamicUpgradeDeadlineConfiguration
.
objects
.
create
(
enabled
=
True
)
course
=
self
.
create_self_paced_course_run
(
days_till_start
=-
1
)
enrollment
=
CourseEnrollmentFactory
(
course_id
=
course
.
id
,
mode
=
CourseMode
.
AUDIT
)
block
=
VerifiedUpgradeDeadlineDate
(
course
,
enrollment
.
user
)
expected
=
enrollment
.
created
+
timedelta
(
days
=
global_config
.
deadline_days
)
expected
=
enrollment
.
created
+
timedelta
(
days
=
global_config
.
deadline_days
)
self
.
assertEqual
(
block
.
date
,
expected
)
self
.
assertEqual
(
block
.
date
,
expected
)
# Courses should be able to override the deadline
# Courses should be able to override the deadline
course_config
=
CourseDynamicUpgradeDeadlineConfiguration
.
objects
.
create
(
course_config
=
CourseDynamicUpgradeDeadlineConfiguration
.
objects
.
create
(
enabled
=
True
,
course_id
=
self
.
course
.
id
,
opt_out
=
False
,
deadline_days
=
3
enabled
=
True
,
course_id
=
course
.
id
,
opt_out
=
False
,
deadline_days
=
3
)
)
block
=
VerifiedUpgradeDeadlineDate
(
self
.
course
,
self
.
user
)
enrollment
=
CourseEnrollmentFactory
(
course_id
=
course
.
id
,
mode
=
CourseMode
.
AUDIT
)
block
=
VerifiedUpgradeDeadlineDate
(
course
,
enrollment
.
user
)
expected
=
enrollment
.
created
+
timedelta
(
days
=
course_config
.
deadline_days
)
expected
=
enrollment
.
created
+
timedelta
(
days
=
course_config
.
deadline_days
)
self
.
assertEqual
(
block
.
date
,
expected
)
self
.
assertEqual
(
block
.
date
,
expected
)
# Disabling the functionality should result in the verified mode's expiration date being returned.
def
test_date_with_self_paced_without_dynamic_upgrade_deadline
(
self
):
global_config
.
enabled
=
False
""" Disabling the dynamic upgrade deadline functionality should result in the verified mode's
global_config
.
save
()
expiration date being returned. """
block
=
VerifiedUpgradeDeadlineDate
(
self
.
course
,
self
.
user
)
DynamicUpgradeDeadlineConfiguration
.
objects
.
create
(
enabled
=
False
)
expected
=
CourseMode
.
objects
.
get
(
course_id
=
self
.
course
.
id
,
mode_slug
=
CourseMode
.
VERIFIED
)
.
expiration_datetime
course
=
self
.
create_self_paced_course_run
()
self
.
assertEqual
(
block
.
date
,
expected
)
expected
=
CourseMode
.
objects
.
get
(
course_id
=
course
.
id
,
mode_slug
=
CourseMode
.
VERIFIED
)
.
expiration_datetime
self
.
assert_upgrade_deadline
(
course
,
expected
)
def
test_date_with_self_paced_with_course_opt_out
(
self
):
def
test_date_with_self_paced_with_course_opt_out
(
self
):
""" If the course run has opted out of the dynamic deadline, the course mode's deadline should be used. """
""" If the course run has opted out of the dynamic deadline, the course mode's deadline should be used. """
self
.
create_self_paced_course_run
(
days_till_start
=-
1
)
course
=
self
.
create_self_paced_course_run
(
days_till_start
=-
1
)
DynamicUpgradeDeadlineConfiguration
.
objects
.
create
(
enabled
=
True
)
DynamicUpgradeDeadlineConfiguration
.
objects
.
create
(
enabled
=
True
)
CourseEnrollmentFactory
.
create
(
course_id
=
self
.
course
.
id
,
user
=
self
.
user
,
mode
=
CourseMode
.
AUDIT
)
CourseDynamicUpgradeDeadlineConfiguration
.
objects
.
create
(
enabled
=
True
,
course_id
=
course
.
id
,
opt_out
=
True
)
enrollment
=
CourseEnrollmentFactory
(
course_id
=
course
.
id
,
mode
=
CourseMode
.
AUDIT
)
# Opt the course out of the dynamic upgrade deadline
CourseDynamicUpgradeDeadlineConfiguration
.
objects
.
create
(
enabled
=
True
,
course_id
=
self
.
course
.
id
,
opt_out
=
True
)
block
=
VerifiedUpgradeDeadlineDate
(
self
.
course
,
self
.
user
)
block
=
VerifiedUpgradeDeadlineDate
(
course
,
enrollment
.
user
)
expected
=
CourseMode
.
objects
.
get
(
course_id
=
self
.
course
.
id
,
mode_slug
=
CourseMode
.
VERIFIED
)
.
expiration_datetime
expected
=
CourseMode
.
objects
.
get
(
course_id
=
course
.
id
,
mode_slug
=
CourseMode
.
VERIFIED
)
.
expiration_datetime
self
.
assertEqual
(
block
.
date
,
expected
)
self
.
assertEqual
(
block
.
date
,
expected
)
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