'Test that the xblocks data is persisted correctly.'

@ddt.data(('course', 47), ('other_course', 34))
@ddt.unpack
def test_update_xblocks_cache(self, course_attr, expected_sql_queries):

    course = getattr(self, course_attr)
    with self.assertNumQueries(expected_sql_queries):
        _update_xblocks_cache(course.id)
    expected_cache_data = getattr(self, (course_attr + '_expected_cache_data'))
    for (usage_key, __) in expected_cache_data.items():
        xblock_cache = XBlockCache.objects.get(usage_key=usage_key)
        for (path_index, path) in enumerate(xblock_cache.paths):
            for (path_item_index, path_item) in enumerate(path):
                self.assertEqual(path_item.usage_key, expected_cache_data[usage_key][path_index][(path_item_index + 1)])
    with self.assertNumQueries(3):
        _update_xblocks_cache(course.id)
