'This test validates that redundant Mac metadata files (\'._example.txt\', \'.DS_Store\') are
cleaned up on import'

def test_export_all_courses(self):

    import_course_from_xml(self.module_store, '**replace_user**', TEST_DATA_DIR, ['dot-underscore'], static_content_store=self.content_store, do_import_static=True, verbose=True)
    course = self.module_store.get_course(CourseKey.from_string('/'.join(['edX', 'dot-underscore', '2014_Fall'])))
    self.assertIsNotNone(course)
    (all_assets, count) = self.content_store.get_all_content_for_course(course.id)
    self.assertEqual(count, 2)
    self.assertEqual(set([asset['_id']['name'] for asset in all_assets]), set([u'.example.txt', u'example.txt']))
    course_filter = course.id.make_asset_key('asset', None)
    query = location_to_query(course_filter, wildcard=True, tag=XASSET_LOCATION_TAG)
    query['_id.name'] = all_assets[0]['_id']['name']
    asset_doc = self.content_store.fs_files.find_one(query)
    asset_doc['_id']['name'] = u'._example_test.txt'
    self.content_store.fs_files.insert(asset_doc)
    asset_doc['_id']['name'] = u'.DS_Store'
    self.content_store.fs_files.insert(asset_doc)
    (all_assets, count) = self.content_store.get_all_content_for_course(course.id)
    self.assertEqual(count, 4)
    self.assertEqual(set([asset['_id']['name'] for asset in all_assets]), set([u'.example.txt', u'example.txt', u'._example_test.txt', u'.DS_Store']))
    call_command('cleanup_assets')
    (all_assets, count) = self.content_store.get_all_content_for_course(course.id)
    self.assertEqual(count, 2)
    self.assertEqual(set([asset['_id']['name'] for asset in all_assets]), set([u'.example.txt', u'example.txt']))
