-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix backfill_enrollment_data_for_course task
* Problem was that `update_enrollment_data_for_course` returns a list of tuples. Each tuple is `(object, created)`, where `object` is the EnrollmentData record and `created` tells if the record was created * Added logging to the backfill task * Updated tests
- Loading branch information
1 parent
21838ef
commit e3faba1
Showing
2 changed files
with
55 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,55 @@ | ||
"""Test Figures backfill Celery tasks | ||
""" | ||
from __future__ import absolute_import | ||
import logging | ||
import pytest | ||
|
||
from figures.tasks import backfill_enrollment_data_for_course | ||
|
||
from tests.factories import EnrollmentDataFactory | ||
|
||
|
||
def test_backfill_enrollment_data_for_course(transactional_db, monkeypatch): | ||
""" | ||
The Celery task is a simple wrapper around the pipeline function | ||
""" | ||
course_id = 'course-v1:SomeOrg+SomeNum+SomeRun' | ||
ed_recs = [EnrollmentDataFactory() for _ in range(2)] | ||
@pytest.mark.django_db | ||
class TestBackfillEnrollmentDataForCourse(object): | ||
|
||
func_path = 'figures.tasks.update_enrollment_data_for_course' | ||
monkeypatch.setattr(func_path, lambda course_id: ed_recs) | ||
ed_ids = backfill_enrollment_data_for_course(course_id) | ||
assert set(ed_ids) == set([obj.id for obj in ed_recs]) | ||
@pytest.fixture(autouse=True) | ||
def setup(self, db): | ||
self.expected_message_template = ( | ||
'figures.tasks.backfill_enrollment_data_for_course "{course_id}".' | ||
' Updated {edrec_count} enrollment data records.') | ||
|
||
def test_backfill_enrollment_data_for_course_no_update(self, transactional_db, | ||
monkeypatch, caplog): | ||
""" | ||
The Celery task is a simple wrapper around the pipeline function | ||
""" | ||
course_id = 'course-v1:SomeOrg+SomeNum+SomeRun' | ||
|
||
# The function returns a list of tuples with (object, created) | ||
# ed_recs = [(EnrollmentDataFactory(), False) for _ in range(2)] | ||
caplog.set_level(logging.INFO) | ||
func_path = 'figures.tasks.update_enrollment_data_for_course' | ||
monkeypatch.setattr(func_path, lambda course_id: []) | ||
backfill_enrollment_data_for_course(course_id) | ||
assert len(caplog.records) == 1 | ||
assert caplog.records[0].message == self.expected_message_template.format( | ||
course_id=course_id, | ||
edrec_count=0) | ||
|
||
def test_backfill_enrollment_data_for_course_with_updates(self, transactional_db, | ||
monkeypatch, caplog): | ||
""" | ||
The Celery task is a simple wrapper around the pipeline function | ||
""" | ||
course_id = 'course-v1:SomeOrg+SomeNum+SomeRun' | ||
|
||
# The function returns a list of tuples with (object, created) | ||
ed_recs = [(EnrollmentDataFactory(), False) for _ in range(2)] | ||
caplog.set_level(logging.INFO) | ||
func_path = 'figures.tasks.update_enrollment_data_for_course' | ||
monkeypatch.setattr(func_path, lambda course_id: ed_recs) | ||
backfill_enrollment_data_for_course(course_id) | ||
assert len(caplog.records) == 1 | ||
assert caplog.records[0].message == self.expected_message_template.format( | ||
course_id=course_id, | ||
edrec_count=len(ed_recs)) |