CSV report generation with dates from future fixed
Fragle code fixed in time series generation. Change-Id: If39d3e36ef22712fb378f6526c87b8341005674f Closes-Bug: #1474407
This commit is contained in:
parent
ae9fa294be
commit
59fc0ac5d6
|
@ -198,12 +198,13 @@ class OswlStatsToCsv(object):
|
|||
"""
|
||||
app.logger.debug("Filling gaps in oswls started")
|
||||
horizon = {}
|
||||
last_date = oswls[0].created_date if oswls else None
|
||||
last_date = None
|
||||
|
||||
# Filling horizon of oswls on last date. Oswls are ordered by
|
||||
# created_date so, then last_date is changed we can assume horizon
|
||||
# of oswls is filled and can be shown
|
||||
for oswl in oswls:
|
||||
last_date = last_date or oswl.created_date
|
||||
if last_date != oswl.created_date:
|
||||
# Filling gaps in created_dates of oswls
|
||||
while last_date != oswl.created_date:
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
from datetime import datetime
|
||||
from datetime import timedelta
|
||||
import flask
|
||||
from flask import request
|
||||
import itertools
|
||||
import mock
|
||||
|
@ -213,6 +214,27 @@ class CsvExporterTest(OswlTest, DbTest):
|
|||
finally:
|
||||
shutil.rmtree(tmp_dir)
|
||||
|
||||
def test_save_all_reports_with_future_dates(self):
|
||||
oswls = []
|
||||
for resource_type in self.RESOURCE_TYPES:
|
||||
oswls.extend(self.get_saved_oswls(10, resource_type))
|
||||
self.get_saved_inst_structs(oswls)
|
||||
tmp_dir = tempfile.mkdtemp()
|
||||
try:
|
||||
to_date = datetime.utcnow() + timedelta(days=7)
|
||||
to_data_str = to_date.strftime('%Y-%m-%d')
|
||||
|
||||
with app.test_request_context(), mock.patch.object(
|
||||
flask.request, 'args', {'to_date': to_data_str}):
|
||||
save_all_reports(tmp_dir)
|
||||
|
||||
files = itertools.chain(('clusters', ), self.RESOURCE_TYPES)
|
||||
for f in files:
|
||||
path = os.path.join(tmp_dir, '{}.csv'.format(f))
|
||||
self.assertTrue(os.path.isfile(path), path)
|
||||
finally:
|
||||
shutil.rmtree(tmp_dir)
|
||||
|
||||
def test_archive_dir(self):
|
||||
oswls = []
|
||||
for resource_type in self.RESOURCE_TYPES:
|
||||
|
|
Loading…
Reference in New Issue