'Verifies that discard changes operation brings moved component back to source location and removes the component
from target location.
Arguments:
store_type (ModuleStoreEnum.Type): Type of modulestore to create test course in.'

@ddt.data(ModuleStoreEnum.Type.mongo, ModuleStoreEnum.Type.split)
def test_move_and_discard_changes(self, store_type):

    self.setup_course(default_store=store_type)
    old_parent_loc = self.store.get_parent_location(self.html_usage_key)
    self.assertFalse(self.store.has_item(old_parent_loc, revision=ModuleStoreEnum.RevisionOption.published_only))
    self.client.ajax_post(reverse_usage_url('xblock_handler', old_parent_loc), data={'publish': 'make_public'})
    self.assertTrue(self.store.has_item(old_parent_loc, revision=ModuleStoreEnum.RevisionOption.published_only))
    self.assertFalse(self.store.has_changes(self.store.get_item(old_parent_loc)))
    self.assert_move_item(self.html_usage_key, self.vert2_usage_key)
    self.assertTrue(self.store.has_changes(self.store.get_item(old_parent_loc)))
    self.client.ajax_post(reverse_usage_url('xblock_handler', old_parent_loc), data={'publish': 'discard_changes'})
    self.assertTrue(self.store.has_item(old_parent_loc, revision=ModuleStoreEnum.RevisionOption.published_only))
    self.assertFalse(self.store.has_changes(self.store.get_item(old_parent_loc)))
    source_item = self.get_item_from_modulestore(self.html_usage_key)
    self.assertEqual(source_item.parent, old_parent_loc)
    self.assertEqual(self.store.get_parent_location(self.html_usage_key), source_item.parent)
    target_parent = self.get_item_from_modulestore(self.vert2_usage_key)
    source_parent = self.get_item_from_modulestore(old_parent_loc)
    self.assertIn(self.html_usage_key, source_parent.children)
    self.assertNotIn(self.html_usage_key, target_parent.children)
