Skip to content

Commit

Permalink
Merge pull request #326 from nephila/hotfix/timezone
Browse files Browse the repository at this point in the history
Improve timezone detection
  • Loading branch information
yakky committed Jun 3, 2018
2 parents 5b84af3 + f481d77 commit 43e5fc1
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 9 deletions.
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ env:
- TEST='isort'
- TEST='docs'

before_script:
- echo "Europe/Rome" | sudo tee /etc/timezone
- sudo dpkg-reconfigure --frontend noninteractive tzdata

before_install:
- pip install codecov

Expand Down
6 changes: 5 additions & 1 deletion djangocms_installer/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import warnings
from distutils.version import LooseVersion

import pytz
import six
from tzlocal import get_localzone

from . import data, ini
from .. import compat, utils
Expand All @@ -21,8 +21,12 @@ def parse(args):
"""
Define the available arguments
"""
from tzlocal import get_localzone

try:
timezone = get_localzone()
if isinstance(timezone, pytz.BaseTzInfo):
timezone = timezone.zone
except Exception: # pragma: no cover
timezone = 'UTC'
if timezone == 'local':
Expand Down
4 changes: 1 addition & 3 deletions djangocms_installer/config/ini.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@ def dump_config_file(filename, args, parser=None):
option_name = keyp.lstrip('-')
option_value = getattr(args, action.dest)
if any([i for i in keys_empty_values_not_pass if i in action.option_strings]):
if action.dest == 'timezone':
config.set(SECTION, option_name, option_value.zone)
elif action.dest == 'languages':
if action.dest == 'languages':
if len(option_value) == 1 and option_value[0] == 'en':
config.set(SECTION, option_name, '')
else:
Expand Down
21 changes: 16 additions & 5 deletions tests/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@
import sys
from argparse import Namespace

import six
from mock import patch
from six import StringIO, text_type
from tzlocal import get_localzone
import six

from djangocms_installer import config
from djangocms_installer.config.data import CMS_VERSION_MATRIX, DJANGO_VERSION_MATRIX, DJANGO_DEFAULT, DJANGOCMS_DEFAULT
from djangocms_installer.config.data import CMS_VERSION_MATRIX, DJANGO_VERSION_MATRIX
from djangocms_installer.install import check_install
from djangocms_installer.utils import less_than_version, supported_versions

from .base import BaseTestClass, unittest


Expand Down Expand Up @@ -636,8 +635,20 @@ def test_utc(self):
'example_prj'])
self.assertEqual(conf_data.timezone, 'UTC')

def test_templates(self):
@patch('tzlocal.get_localzone')
def test_timezone(self, mock_get_localzone):
"""
Verify handling problem with detecting timezone
"""
mock_get_localzone.return_value = 'local'
conf_data = config.parse([
'-q',
'-p'+self.project_dir,
'example_prj'])
self.assertEqual(text_type(conf_data.timezone), 'UTC')

def test_templates(self):
"""-
Verify handling of valid (existing) and invalid (non-existing) templates directory parameter
"""
conf_data = config.parse([
Expand Down Expand Up @@ -758,7 +769,7 @@ class TestBaseConfig(unittest.TestCase):
'starting_page': False,
'template': None,
'templates': False,
'timezone': get_localzone(),
'timezone': get_localzone().zone,
'use_timezone': 'yes',
'utc': False,
'no_plugins': False,
Expand Down

0 comments on commit 43e5fc1

Please sign in to comment.