Browse Source

Merge pull request #5967 from maxkoryukov/fix/opt-hidden-conflict

Style fix for 'settings.py'
pull/6004/merge
Ruud Burger 9 years ago
parent
commit
51e5661cfd
  1. 4
      couchpotato/core/settings.py
  2. 54
      couchpotato/core/settings_test.py

4
couchpotato/core/settings.py

@ -331,7 +331,6 @@ class Settings(object):
return { return {
'success' : False, 'success' : False,
} }
else:
from couchpotato.environment import Env from couchpotato.environment import Env
soft_chroot = Env.get('softchroot') soft_chroot = Env.get('softchroot')
@ -361,9 +360,6 @@ class Settings(object):
'success': True 'success': True
} }
# unreachable code:
return None
def isSectionReadable(self, section): def isSectionReadable(self, section):
meta = 'section_hidden' + self.optionMetaSuffix() meta = 'section_hidden' + self.optionMetaSuffix()
try: try:

54
couchpotato/core/settings_test.py

@ -23,6 +23,11 @@ class DoNotUseMe:
# props: # props:
s.log = Mock() s.log = Mock()
# subobjects
s.p = Mock()
s.p.getboolean = Mock(return_value=True)
s.p.has_option = Mock
class SettingsSaveWritableNonWritable(TestCase): class SettingsSaveWritableNonWritable(TestCase):
def setUp(self): def setUp(self):
self.s = Settings() self.s = Settings()
@ -94,3 +99,52 @@ class SettingsSaveWritableNonWritable(TestCase):
# lets check, that 'set'-method was not called: # lets check, that 'set'-method was not called:
self.assertFalse(mock_set.called, 'Method `set` was called') self.assertFalse(mock_set.called, 'Method `set` was called')
mock_is_w.assert_called_with(section, option) mock_is_w.assert_called_with(section, option)
class OptionMetaSuite(TestCase):
""" tests for ro rw hidden options """
def setUp(self):
self.s = Settings()
self.meta = self.s.optionMetaSuffix()
# hide real config-parser:
self.s.p = Mock()
def test_no_meta_option(self):
s = self.s
section = 'core'
option = 'url'
option_meta = option + self.meta
# setup mock
s.p.getboolean = Mock(return_value=True)
# there is no META-record for our option:
s.p.has_option = Mock(side_effect=lambda s,o: not (s==section and o==option_meta) )
# by default all options are writable and readable
self.assertTrue ( s.isOptionWritable(section, option) )
self.assertTrue ( s.isOptionReadable(section, option) )
def test_non_writable(self):
s = self.s
section = 'core'
option = 'url'
def mock_get_meta_ro (s,o):
if (s==section and o==option_meta):
return 'ro'
return 11
option_meta = option + self.meta
# setup mock
s.p.has_option = Mock( return_value = True )
s.p.get = Mock( side_effect = mock_get_meta_ro)
# by default all options are writable and readable
self.assertFalse ( s.isOptionWritable(section, option) )
self.assertTrue ( s.isOptionReadable(section, option) )

Loading…
Cancel
Save