'Actual algorithm to compare courses.'

def _assertCoursesEqual(self, expected_items, actual_items, actual_course_key, expect_drafts=False):

    with self.bulk_assertions():
        self.assertEqual(len(expected_items), len(actual_items))
        def map_key(usage_key):
            return (usage_key.block_type, usage_key.block_id)
        actual_item_map = {map_key(item.location): item for item in actual_items}
        self.assertItemsEqual([map_key(item.location) for item in expected_items if (item.scope_ids.block_type != 'course')], [key for key in actual_item_map.keys() if (key[0] != 'course')])
        for expected_item in expected_items:
            actual_item_location = actual_course_key.make_usage_key(expected_item.category, expected_item.location.block_id)
            if (expected_item.location.category == 'course'):
                actual_item_location = actual_item_location.replace(name=actual_item_location.run)
            actual_item = actual_item_map.get(map_key(actual_item_location))
            if ((actual_item is None) and (expected_item.location.category == 'course')):
                actual_item_location = actual_item_location.replace(name='course')
                actual_item = actual_item_map.get(map_key(actual_item_location))
            self.assertIn(map_key(actual_item_location), actual_item_map.keys())
            if (actual_item is None):
                continue
            self.assertEqual(expected_item.fields, actual_item.fields)
            for (field_name, field) in expected_item.fields.iteritems():
                if ((expected_item.scope_ids.usage_id, field_name) in self.field_exclusions):
                    continue
                if ((None, field_name) in self.field_exclusions):
                    continue
                if (field_name == 'children'):
                    continue
                self.assertFieldEqual(field, expected_item, actual_item)
            self.assertEqual(expected_item.has_children, actual_item.has_children)
            if expected_item.has_children:
                expected_children = [(expected_item_child.location.block_type, expected_item_child.location.block_id) for expected_item_child in expected_item.get_children()]
                actual_children = [(item_child.location.block_type, item_child.location.block_id) for item_child in actual_item.get_children()]
                self.assertEqual(expected_children, actual_children)
