Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
edx-platform-release
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hsin-Yu Chien
edx-platform-release
Commits
e79ffb3b
Unverified
Commit
e79ffb3b
authored
6 years ago
by
Michael Youngstrom
Committed by
GitHub
6 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #18831 from edx/youngstrom/celery-enrollment-task-tests
Switch where we create the mock in test_tasks
parents
7c19efbb
eadf3650
No related branches found
Branches containing commit
Tags
release-2018-02-14-11.33
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
common/djangoapps/entitlements/tests/test_tasks.py
+20
-10
20 additions, 10 deletions
common/djangoapps/entitlements/tests/test_tasks.py
with
20 additions
and
10 deletions
common/djangoapps/entitlements/tests/test_tasks.py
+
20
−
10
View file @
e79ffb3b
...
...
@@ -27,23 +27,26 @@ def boom():
@skip_unless_lms
@mock.patch
(
'
entitlements.models.CourseEntitlement.expired_at_datetime
'
,
new_callable
=
mock
.
PropertyMock
)
class
TestExpireOldEntitlementsTask
(
TestCase
):
"""
Tests for the
'
expire_old_entitlements
'
method.
"""
def
test_checks_expiration
(
self
,
mock_datetime
):
def
test_checks_expiration
(
self
):
"""
Test that we actually do check expiration on each entitlement (happy path)
"""
make_entitlement
()
make_entitlement
()
tasks
.
expire_old_entitlements
.
delay
(
1
,
3
).
get
()
with
mock
.
patch
(
'
entitlements.models.CourseEntitlement.expired_at_datetime
'
,
new_callable
=
mock
.
PropertyMock
)
as
mock_datetime
:
tasks
.
expire_old_entitlements
.
delay
(
1
,
3
).
get
()
self
.
assertEqual
(
mock_datetime
.
call_count
,
2
)
def
test_only_unexpired
(
self
,
mock_datetime
):
def
test_only_unexpired
(
self
):
"""
Verify that only unexpired entitlements are included
"""
...
...
@@ -51,21 +54,28 @@ class TestExpireOldEntitlementsTask(TestCase):
make_entitlement
(
expired
=
True
)
make_entitlement
()
# Run expiration
tasks
.
expire_old_entitlements
.
delay
(
1
,
3
).
get
()
with
mock
.
patch
(
'
entitlements.models.CourseEntitlement.expired_at_datetime
'
,
new_callable
=
mock
.
PropertyMock
)
as
mock_datetime
:
tasks
.
expire_old_entitlements
.
delay
(
1
,
3
).
get
()
# Make sure only the unexpired one gets used
self
.
assertEqual
(
mock_datetime
.
call_count
,
1
)
def
test_retry
(
self
,
mock_datetime
):
def
test_retry
(
self
):
"""
Test that we retry when an exception occurs while checking old
entitlements.
"""
mock_datetime
.
side_effect
=
boom
make_entitlement
()
task
=
tasks
.
expire_old_entitlements
.
delay
(
1
,
2
)
with
mock
.
patch
(
'
entitlements.models.CourseEntitlement.expired_at_datetime
'
,
new_callable
=
mock
.
PropertyMock
,
side_effect
=
boom
)
as
mock_datetime
:
task
=
tasks
.
expire_old_entitlements
.
delay
(
1
,
2
)
self
.
assertRaises
(
Exception
,
task
.
get
)
self
.
assertEqual
(
mock_datetime
.
call_count
,
tasks
.
MAX_RETRIES
+
1
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment