def test_dump_to_csv_dumps_with_top_level(self): if os.path.exists( os.path.dirname(os.path.abspath(__file__)) + '/data/output.csv'): os.remove( os.path.dirname(os.path.abspath(__file__)) + '/data/output.csv') field_list = [ 'id_str', 'coordinates.coordinates.0', 'coordinates.coordinates.1', 'user.id_str', 'user.lang', 'lang', 'text', 'user.screen_name', 'user.location', 'user.description', 'created_at', 'user.friends_count', 'user.followers_count', 'retweet_count', 'entities.urls.0.expanded_url', 'entities.urls.1.expanded_url', 'entities.urls.2.expanded_url', 'entities.urls.3.expanded_url', 'entities.urls.4.expanded_url', 'entities.hashtags.0.text', 'entities.hashtags.1.text' ] output_path = os.path.dirname( os.path.realpath(__file__)) + '/' + 'data/output.csv' collection = CsvCollection( os.path.dirname(os.path.realpath(__file__)) + '/' + config['csv']['valid']) collection.dump_to_csv(output_path, field_list, top_level=True) self.assertTrue(os.path.getsize(output_path) > 0) if os.path.exists( os.path.dirname(os.path.abspath(__file__)) + '/data/output.csv'): os.remove( os.path.dirname(os.path.abspath(__file__)) + '/data/output.csv')
def test_dump_to_csv_dumps_right_stuff_with_top_level(self): if os.path.exists( os.path.dirname(os.path.abspath(__file__)) + '/data/output.csv'): os.remove( os.path.dirname(os.path.abspath(__file__)) + '/data/output.csv') field_list = [ 'id_str', 'entities.hashtags.0', 'entities.hashtags.1', 'source', 'user.id', 'timestamp.$date', 'text', 'coordinates.coordinates.0', 'coordinates.coordinates.1', 'user.id_str', 'user.lang', 'lang', 'user.screen_name', 'user.location', 'user.description', 'created_at', 'user.friends_count', 'user.followers_count', 'retweet_count', 'entities.urls.0.expanded_url', 'entities.urls.1.expanded_url', 'entities.urls.2.expanded_url', 'entities.urls.3.expanded_url', 'entities.urls.4.expanded_url', 'entities.hashtags.0.text', 'entities.hashtags.1.text' ] output_path = os.path.dirname( os.path.realpath(__file__)) + '/' + 'data/output.csv' collection = CsvCollection( os.path.dirname(os.path.realpath(__file__)) + '/' + config['csv']['valid']) collection.dump_to_csv(output_path, field_list, top_level=True) with open( os.path.dirname(os.path.abspath(__file__)) + '/data/output.csv', 'r') as filehandle: count = 0 for line in csv.reader(filehandle): if count != 0: val_count = 0 for csv_row_value in line: everything_in_order = True if val_count == 0: self.assertEqual(csv_row_value, '661275583813431296') elif val_count == 1: if csv_row_value != 'jadehelm': everything_in_order = False elif val_count == 2: if csv_row_value != 'newworldorder': everything_in_order = False elif val_count == 3: self.assertEqual( csv_row_value, '<a href="https://twitter.com/Col_Connaughton" rel="nofollow">Colin\'s Autotweeterpro5.3</a>' ) elif val_count == 4: self.assertEqual(csv_row_value, '379851447') elif val_count == 5: self.assertEqual(csv_row_value, '1446495359000') elif val_count == 6: self.assertEqual( csv_row_value, 'Susan Lindauer, Rtd US Army LTC Potter: Jade Helm https://t.co/VA4bQRudLt #jadehelm #newworldorder #usa #tyranny #threat' ) if everything_in_order: self.assertTrue(True) val_count += 1 else: count += 1 if os.path.exists( os.path.dirname(os.path.abspath(__file__)) + '/data/output.csv'): os.remove( os.path.dirname(os.path.abspath(__file__)) + '/data/output.csv')