On unicode data CSV exporter fails

Python CSV module is not supports unicode. Encoding added into CSV exporter.
Fixed config files definitions in manage_analytics.py

Closes-Bug: #1415026
Change-Id: I40ebc48e239c403f09ba7c18ba777e6216adf7cc
This commit is contained in:
Alexander Kislitsky 2015-01-27 15:49:44 +03:00
parent 2f4eb79233
commit 429a87a388
3 changed files with 24 additions and 3 deletions

View File

@ -128,7 +128,10 @@ class StatsToCsv(object):
return data
for d in flatten_data:
writer.writerow(d)
app.logger.debug("Writing row %s", d)
encoded_d = [s.encode("utf-8") if isinstance(s, unicode) else s
for s in d]
writer.writerow(encoded_d)
yield read_and_flush()
app.logger.debug("Saving flatten data as CSV is finished")

View File

@ -1,3 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2015 Mirantis, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
@ -204,6 +206,22 @@ class StatsToCsvExportTest(ElasticTest):
for _ in reader:
pass
def test_unicode_as_csv(self):
installations_num = 10
self.generate_data(installations_num=installations_num)
es_client = ElasticSearchClient()
structures = es_client.get_structures()
exporter = StatsToCsv()
structure_paths, cluster_paths, csv_paths = \
exporter.get_cluster_keys_paths()
flatten_clusters = exporter.get_flatten_clusters(structure_paths,
cluster_paths,
structures)
flatten_clusters = list(flatten_clusters)
flatten_clusters[1][0] = u'эюя'
list(exporter.flatten_data_as_csv(csv_paths, flatten_clusters))
def test_export_clusters(self):
installations_num = 100
self.generate_data(installations_num=installations_num)

View File

@ -22,8 +22,8 @@ from fuel_analytics.api.app import app
def configure_app(mode=None):
mode_map = {
'test': 'analytics.api.config.Testing',
'prod': 'analytics.api.config.Production'
'test': 'fuel_analytics.api.config.Testing',
'prod': 'fuel_analytics.api.config.Production'
}
app.config.from_object(mode_map.get(mode))
app.config.from_envvar('ANALYTICS_SETTINGS', silent=True)