Merge "Adjust stringified dates to the local timezone"
This commit is contained in:
commit
605e93cefb
@ -19,7 +19,9 @@ except ImportError:
|
||||
import bs4
|
||||
import string
|
||||
|
||||
import iso8601
|
||||
from muranodashboard.dynamic_ui import yaql_expression
|
||||
import pytz
|
||||
import six
|
||||
import yaql
|
||||
|
||||
@ -47,6 +49,12 @@ def ensure_python_obj(obj):
|
||||
return mappings.get(obj, obj)
|
||||
|
||||
|
||||
def adjust_datestr(request, datestr):
|
||||
tz = pytz.timezone(request.session.get('django_timezone'))
|
||||
dt = iso8601.parse_date(datestr).astimezone(tz)
|
||||
return dt.strftime('%Y-%m-%d %H:%M:%S')
|
||||
|
||||
|
||||
class Bunch(object):
|
||||
"""Bunch dict/object-like container.
|
||||
|
||||
|
@ -13,7 +13,6 @@
|
||||
# under the License.
|
||||
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from oslo_log import log as logging
|
||||
import six
|
||||
|
||||
@ -41,7 +40,7 @@ def get_status_messages_for_service(request, service_id, environment_id):
|
||||
environment_id, deployment.id, service_id)
|
||||
|
||||
for report in reports:
|
||||
result += report.created.replace('T', ' ') + ' - ' + \
|
||||
result += utils.adjust_datestr(request, report.created) + ' - ' + \
|
||||
report.text + '\n'
|
||||
return result
|
||||
|
||||
@ -416,7 +415,7 @@ def get_deployment_start(request, environment_id, deployment_id):
|
||||
LOG.debug('Get deployment start time')
|
||||
for deployment in deployments:
|
||||
if deployment.id == deployment_id:
|
||||
return deployment.started.replace('T', ' ')
|
||||
return utils.adjust_datestr(request, deployment.started)
|
||||
return None
|
||||
|
||||
|
||||
|
@ -25,6 +25,7 @@ from openstack_dashboard.api import nova as nova_api
|
||||
from openstack_dashboard import policy
|
||||
|
||||
from muranoclient.common import exceptions as exc
|
||||
from muranodashboard.common import utils
|
||||
from muranodashboard.environments import api
|
||||
from muranodashboard.environments import consts
|
||||
from muranodashboard.environments import tables
|
||||
@ -151,7 +152,7 @@ class EnvLogsTab(tabs.Tab):
|
||||
def get_context_data(self, request):
|
||||
reports = self.tab_group.kwargs['logs']
|
||||
for report in reports:
|
||||
report.created = report.created.replace('T', ' ')
|
||||
report.created = utils.adjust_datestr(request, report.created)
|
||||
return {"reports": reports}
|
||||
|
||||
|
||||
|
@ -28,6 +28,7 @@ class TestEnvironmentsAPI(helpers.APITestCase):
|
||||
|
||||
self.mock_client = mock.Mock(spec=client)
|
||||
self.mock_request = mock.MagicMock()
|
||||
self.mock_request.session = {'django_timezone': 'UTC'}
|
||||
self.env_id = 'foo_env_id'
|
||||
self.session_id = 'foo_session_id'
|
||||
self.service_id = 'foo_service_id'
|
||||
@ -43,12 +44,14 @@ class TestEnvironmentsAPI(helpers.APITestCase):
|
||||
mock.Mock(id='foo_deployment_id'),
|
||||
mock.Mock(id='bar_deployment_id')
|
||||
]
|
||||
|
||||
mock_client.deployments.reports.side_effect = [
|
||||
[mock.Mock(text='foo_text', created='T01:23')],
|
||||
[mock.Mock(text='bar_text', created='T03:45')],
|
||||
[mock.Mock(text='foo_text', created='1970-01-01T12:23:00')],
|
||||
[mock.Mock(text='bar_text', created='1970-01-01T15:45:00')],
|
||||
]
|
||||
|
||||
expected_result = '\n 01:23 - foo_text\n 03:45 - bar_text\n'
|
||||
expected_result = '\n1970-01-01 12:23:00 - foo_text\n' \
|
||||
'1970-01-01 15:45:00 - bar_text\n'
|
||||
expected_reports_mock_calls = [
|
||||
mock.call('foo_env_id', 'bar_deployment_id', 'foo_service_id'),
|
||||
mock.call('foo_env_id', 'foo_deployment_id', 'foo_service_id')
|
||||
@ -188,11 +191,11 @@ class TestEnvironmentsAPI(helpers.APITestCase):
|
||||
self.assertIsNone(result)
|
||||
|
||||
mock_client.deployments.list.return_value = [
|
||||
mock.Mock(id='foo_deployment_id', started='T12:34')
|
||||
mock.Mock(id='foo_deployment_id', started='1970-01-01T12:34:00')
|
||||
]
|
||||
result = env_api.get_deployment_start(self.mock_request, self.env_id,
|
||||
self.deployment_id)
|
||||
self.assertEqual(' 12:34', result)
|
||||
self.assertEqual('1970-01-01 12:34:00', result)
|
||||
mock_client.deployments.list.assert_has_calls([
|
||||
mock.call('foo_env_id'), mock.call('foo_env_id')
|
||||
])
|
||||
|
@ -65,6 +65,7 @@ class TestOverviewTab(testtools.TestCase):
|
||||
)
|
||||
]
|
||||
mock_request = mock.Mock()
|
||||
mock_request.session = {'django_timezone': 'UTC'}
|
||||
|
||||
expected_service = {
|
||||
'service': collections.OrderedDict([
|
||||
@ -265,29 +266,33 @@ class TestEnvLogsTab(testtools.TestCase):
|
||||
self.assertFalse(self.env_logs_tab.preload)
|
||||
|
||||
def test_get_context_data(self):
|
||||
mock_report = mock.Mock(created='T12:34')
|
||||
mock_report = mock.Mock(created='1970-01-01T12:34:00')
|
||||
self.env_logs_tab.tab_group = mock.Mock()
|
||||
self.env_logs_tab.tab_group.kwargs = {
|
||||
'logs': [mock_report]
|
||||
}
|
||||
mock_request = mock.MagicMock()
|
||||
mock_request.session = {'django_timezone': 'UTC'}
|
||||
|
||||
reports = self.env_logs_tab.get_context_data(None)
|
||||
reports = self.env_logs_tab.get_context_data(mock_request)
|
||||
|
||||
mock_report.created = ' 12:34'
|
||||
mock_report.created = '1970-01-01 12:34:00'
|
||||
self.assertEqual({'reports': [mock_report]}, reports)
|
||||
|
||||
|
||||
class TestLatestLogTab(testtools.TestCase):
|
||||
|
||||
def test_allowed(self):
|
||||
latest_logs_tab = tabs.LatestLogsTab(None)
|
||||
latest_logs_tab.tab_group = mock.Mock()
|
||||
mock_report = mock.Mock(created='T12:34')
|
||||
latest_logs_tab.tab_group.kwargs = {'logs': [mock_report]}
|
||||
mock_request = mock.MagicMock()
|
||||
mock_request.session = {'django_timezone': 'UTC'}
|
||||
mock_report = mock.Mock(created='1970-01-01T12:34:00')
|
||||
tab_group = mock.Mock()
|
||||
tab_group.kwargs = {'logs': [mock_report]}
|
||||
latest_logs_tab = tabs.LatestLogsTab(tab_group, request=mock_request)
|
||||
|
||||
self.assertEqual(_('Latest Deployment Log'), latest_logs_tab.name)
|
||||
mock_report.created = ' 12:34'
|
||||
self.assertEqual([mock_report], latest_logs_tab.allowed(None))
|
||||
mock_report.created = '1970-01-01 12:34:00'
|
||||
self.assertEqual([mock_report], latest_logs_tab.allowed(mock_request))
|
||||
|
||||
|
||||
class TestEnvConfigTab(testtools.TestCase):
|
||||
@ -514,8 +519,11 @@ class TestEnvironmentDetailsTabs(testtools.TestCase):
|
||||
'{"environment": {"status": "foo_status"}}'
|
||||
|
||||
mock_request = mock.Mock(GET={})
|
||||
mock_request.session = {'django_timezone': 'UTC'}
|
||||
mock_logs = mock.Mock(created='1970-01-01T12:34:00')
|
||||
mock_logs.created = '1970-01-01 12:34:00'
|
||||
env_details_tabs = tabs.EnvironmentDetailsTabs(
|
||||
mock_request, environment_id='foo_env_id', logs=[mock.Mock()])
|
||||
mock_request, environment_id='foo_env_id', logs=[mock_logs])
|
||||
|
||||
self.assertEqual('environment_details', env_details_tabs.slug)
|
||||
self.assertEqual(
|
||||
|
@ -6,8 +6,10 @@ pbr!=2.1.0,>=2.0.0 # Apache-2.0
|
||||
beautifulsoup4 # MIT
|
||||
Django<1.11,>=1.8 # BSD
|
||||
django-formtools # BSD
|
||||
iso8601>=0.1.11 # MIT
|
||||
six>=1.9.0 # MIT
|
||||
python-muranoclient>=0.8.2 # Apache-2.0
|
||||
pytz>=2013.6 # MIT
|
||||
PyYAML>=3.10.0 # MIT
|
||||
yaql>=1.1.0 # Apache 2.0 License
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user