def test_save_deletes_cached_enrollment_status_hash(self): """ Verify the method deletes the cached enrollment status hash for the user. """ # There should be no cached value for a new user with no enrollments. self.assertIsNone(cache.get(CourseEnrollment.enrollment_status_hash_cache_key(self.user))) # Generating a status hash should cache the generated value. status_hash = CourseEnrollment.generate_enrollment_status_hash(self.user) self.assert_enrollment_status_hash_cached(self.user, status_hash) # Modifying enrollments should delete the cached value. CourseEnrollmentFactory.create(user=self.user) self.assertIsNone(cache.get(CourseEnrollment.enrollment_status_hash_cache_key(self.user)))
def assert_enrollment_status_hash_cached(self, user, expected_value): self.assertEqual( cache.get(CourseEnrollment.enrollment_status_hash_cache_key(user)), expected_value)
def test_enrollment_status_hash_cache_key(self): username = '******' user = UserFactory(username=username) expected = 'enrollment_status_hash_' + username self.assertEqual( CourseEnrollment.enrollment_status_hash_cache_key(user), expected)
def assert_enrollment_status_hash_cached(self, user, expected_value): self.assertEqual(cache.get(CourseEnrollment.enrollment_status_hash_cache_key(user)), expected_value)
def test_enrollment_status_hash_cache_key(self): username = '******' user = UserFactory(username=username) expected = 'enrollment_status_hash_' + username self.assertEqual(CourseEnrollment.enrollment_status_hash_cache_key(user), expected)