From 122039ac58c97814a5116e7d41439dca44c258cb Mon Sep 17 00:00:00 2001 From: Calen Pennington Date: Wed, 20 May 2015 15:06:17 -0400 Subject: [PATCH] Add __len__ to FieldDataCache --- lms/djangoapps/courseware/model_data.py | 3 +++ lms/djangoapps/courseware/tests/test_model_data.py | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lms/djangoapps/courseware/model_data.py b/lms/djangoapps/courseware/model_data.py index 7e2c508bad..c47ee65b41 100644 --- a/lms/djangoapps/courseware/model_data.py +++ b/lms/djangoapps/courseware/model_data.py @@ -951,3 +951,6 @@ class FieldDataCache(object): return None return self.cache[key.scope].last_modified(key) + + def __len__(self): + return sum(len(cache) for cache in self.cache.values()) diff --git a/lms/djangoapps/courseware/tests/test_model_data.py b/lms/djangoapps/courseware/tests/test_model_data.py index df04376065..0f87c49de3 100644 --- a/lms/djangoapps/courseware/tests/test_model_data.py +++ b/lms/djangoapps/courseware/tests/test_model_data.py @@ -242,7 +242,7 @@ class TestMissingStudentModule(TestCase): def test_set_field_in_missing_student_module(self): "Test that setting a field in a missing StudentModule creates the student module" - self.assertEquals(0, sum(len(cache) for cache in self.field_data_cache.cache.values())) + self.assertEquals(0, len(self.field_data_cache)) self.assertEquals(0, StudentModule.objects.all().count()) # We are updating a problem, so we write to courseware_studentmodulehistory