'Tests that an asset with invalid displayname can be overwritten if multiple assets have same displayname.
It Verifies that:
During import, if (\'/\') or (\'\') is present in displayname of an asset, it is replaced with underscores \'_\'.
Export does not fail when an asset has \'/\' in its displayname. If the converted display matches with
any other asset, then it will be replaced.
Asset name in XML: "/invalid\displayname/subs-esLhHcdKGWvKs.srt"'

def test_invalid_asset_overwrite(self):

    content_store = contentstore()
    expected_displayname = '_invalid_displayname_subs-esLhHcdKGWvKs.srt'
    import_course_from_xml(self.store, self.user.id, TEST_DATA_DIR, ['import_draft_order'], static_content_store=content_store, verbose=True, create_if_not_present=True)
    course = self.store.get_course(self.store.make_course_key('test_org', 'import_draft_order', 'import_draft_order'))
    self.assertIsNotNone(course)
    asset_key = course.id.make_asset_key('asset', 'sample_asset.srt')
    content = StaticContent(asset_key, expected_displayname, 'application/text', 'test')
    content_store.save(content)
    (assets, count) = content_store.get_all_content_for_course(course.id)
    self.assertEqual(count, 2)
    for asset in assets:
        self.assertEquals(asset['displayname'], expected_displayname)
    root_dir = path(mkdtemp_clean())
    print 'Exporting    to    tempdir    =    {0}'.format(root_dir)
    export_course_to_xml(self.store, content_store, course.id, root_dir, 'test_export')
    filesystem = OSFS((root_dir / 'test_export/static'))
    exported_static_files = filesystem.listdir()
    self.assertEqual(len(exported_static_files), 1)
    self.assertTrue(filesystem.exists(expected_displayname))
    self.assertEqual(exported_static_files[0], expected_displayname)
    shutil.rmtree(root_dir)
