'Check that 2 modules of same type get unique block_ids. Also check that if creation provides
a definition id and new def data that it branches the definition in the db.
Actually, this tries to test all create_item features not tested above.'

def test_unique_naming(self):

    locator = BlockUsageLocator(CourseLocator(org='testx', course='GreekHero', run='run', branch=BRANCH_NAME_DRAFT), 'problem', block_id='problem1')
    original = modulestore().get_item(locator)
    locator = BlockUsageLocator(CourseLocator(org='guestx', course='contender', run='run', branch=BRANCH_NAME_DRAFT), 'course', 'head345679')
    category = 'problem'
    new_payload = '<problem>empty</problem>'
    new_module = modulestore().create_child('anotheruser', locator, category, fields={'display_name': 'problem    1', 'data': new_payload})
    another_payload = '<problem>not    empty</problem>'
    another_module = modulestore().create_child('anotheruser', locator, category, fields={'display_name': 'problem    2', 'data': another_payload}, definition_locator=original.definition_locator)
    parent = modulestore().get_item(locator)
    self.assertNotEqual(new_module.location.block_id, another_module.location.block_id)
    self.assertIn(new_module.location.version_agnostic(), version_agnostic(parent.children))
    self.assertIn(another_module.location.version_agnostic(), version_agnostic(parent.children))
    self.assertEqual(new_module.data, new_payload)
    self.assertEqual(another_module.data, another_payload)
    new_history = modulestore().get_definition_history_info(new_module.definition_locator)
    self.assertIsNone(new_history['previous_version'])
    self.assertEqual(new_history['original_version'], new_module.definition_locator.definition_id)
    self.assertEqual(new_history['edited_by'], 'anotheruser')
    another_history = modulestore().get_definition_history_info(another_module.definition_locator)
    self.assertEqual(another_history['previous_version'], original.definition_locator.definition_id)
