'Test the "removed" event emitted when we un-assign blocks previously assigned to a student.
We go from two blocks assigned, to one because the others have been deleted from the library.'

def test_removed_invalid(self):

    self.lc_block.get_child_descriptors()
    self.lc_block.max_count = 2
    del self.lc_block._xmodule._selected_set
    initial_blocks_assigned = self.lc_block.get_child_descriptors()
    self.assertEqual(len(initial_blocks_assigned), 2)
    self.publisher.reset_mock()
    keep_block_key = initial_blocks_assigned[0].location
    (keep_block_lib_usage_key, keep_block_lib_version) = self.store.get_block_original_usage(keep_block_key)
    self.assertIsNotNone(keep_block_lib_usage_key)
    deleted_block_key = initial_blocks_assigned[1].location
    self.library.children = [keep_block_lib_usage_key]
    self.store.update_item(self.library, self.user_id)
    self.lc_block.refresh_children()
    del self.lc_block._xmodule._selected_set
    children = self.lc_block.get_child_descriptors()
    self.assertEqual(len(children), 1)
    event_data = self._assert_event_was_published('removed')
    self.assertEqual(event_data['removed'], [{'usage_key': unicode(deleted_block_key), 'original_usage_key': None, 'original_usage_version': None, 'descendants': []}])
    self.assertEqual(event_data['result'], [{'usage_key': unicode(keep_block_key), 'original_usage_key': unicode(keep_block_lib_usage_key), 'original_usage_version': unicode(keep_block_lib_version), 'descendants': []}])
    self.assertEqual(event_data['reason'], 'invalid')
