Working on the TestProcessConfig testcase

This commit is contained in:
jai.s 2020-09-29 20:19:50 +05:30
parent 3b5e92be76
commit c8eaa28f0f
No known key found for this signature in database
GPG Key ID: 360CFA25EFC67D12
3 changed files with 29 additions and 4 deletions

View File

@ -44,7 +44,7 @@ try:
import helper_startup import helper_startup
import state import state
except ModuleNotFoundError: except ModuleNotFoundError:
from pybitmessage import helper_startup, state from pybitmessage import helper_startup
from pybitmessage import state from pybitmessage import state
helper_startup.loadConfig() helper_startup.loadConfig()

View File

@ -34,9 +34,11 @@ StoreConfigFilesInSameDirectoryAsProgramByDefault = False
def loadConfig(): def loadConfig():
"""Load the config""" """Load the config"""
print('1111111111111111111111111111111111111111')
config = BMConfigParser() config = BMConfigParser()
if state.appdata: if state.appdata:
print('if loadConfig state.appdata111 -{}'.format(state.appdata))
config.read(state.appdata + 'keys.dat') config.read(state.appdata + 'keys.dat')
# state.appdata must have been specified as a startup option. # state.appdata must have been specified as a startup option.
needToCreateKeysFile = config.safeGet( needToCreateKeysFile = config.safeGet(
@ -46,19 +48,31 @@ def loadConfig():
'Loading config files from directory specified' 'Loading config files from directory specified'
' on startup: %s', state.appdata) ' on startup: %s', state.appdata)
else: else:
print('else loadConfig state.appdata2222 -{}'.format(
state.appdata))
config.read(paths.lookupExeFolder() + 'keys.dat') config.read(paths.lookupExeFolder() + 'keys.dat')
try: try:
config.get('bitmessagesettings', 'settingsversion') config.get('bitmessagesettings', 'settingsversion')
print('try bitmessagesettings', 'settingsversion -{}'.format(
config.get('bitmessagesettings', 'settingsversion')))
logger.info('Loading config files from same directory as program.') logger.info('Loading config files from same directory as program.')
needToCreateKeysFile = False needToCreateKeysFile = False
state.appdata = paths.lookupExeFolder() state.appdata = paths.lookupExeFolder()
except: except:
print('load the config except except')
# Could not load the keys.dat file in the program directory. # Could not load the keys.dat file in the program directory.
# Perhaps it is in the appdata directory. # Perhaps it is in the appdata directory.
state.appdata = paths.lookupAppdataFolder() state.appdata = paths.lookupAppdataFolder()
config.read(state.appdata + 'keys.dat') config.read(state.appdata + 'keys.dat')
needToCreateKeysFile = config.safeGet( needToCreateKeysFile = config.safeGet(
'bitmessagesettings', 'settingsversion') is None 'bitmessagesettings', 'settingsversion') is None
print('needToCreateKeysFile -{}'.format(
needToCreateKeysFile))
if not needToCreateKeysFile:
print(
'needToCreateKeysFile is false means settingversion is not empty')
print(config.get(
'bitmessagesettings','settingsversion'))
if not needToCreateKeysFile: if not needToCreateKeysFile:
logger.info( logger.info(
'Loading existing config files from %s', state.appdata) 'Loading existing config files from %s', state.appdata)
@ -125,6 +139,10 @@ def loadConfig():
if not sys.platform.startswith('win'): if not sys.platform.startswith('win'):
os.umask(0o077) os.umask(0o077)
config.save() config.save()
print('7777777777777777777777777777777')
print('printing the bitmessage settings -{}'.format(config.get(
'bitmessagesettings','settingsversion')))
print('7777777777777777777777777777777')
else: else:
updateConfig() updateConfig()
@ -132,6 +150,7 @@ def loadConfig():
def updateConfig(): def updateConfig():
"""Save the config""" """Save the config"""
config = BMConfigParser() config = BMConfigParser()
print('222222222222222222222222222222222222222')
# Used python2.7 # Used python2.7
# settingsversion = int(BMConfigParser().get('bitmessagesettings', 'settingsversion') \ # settingsversion = int(BMConfigParser().get('bitmessagesettings', 'settingsversion') \
settingsversion = BMConfigParser().safeGetInt('bitmessagesettings', 'settingsvesion') settingsversion = BMConfigParser().safeGetInt('bitmessagesettings', 'settingsvesion')
@ -277,8 +296,15 @@ def updateConfig():
# whatever the user selects. # whatever the user selects.
if not config.has_option('bitmessagesettings', 'ttl'): if not config.has_option('bitmessagesettings', 'ttl'):
config.set('bitmessagesettings', 'ttl', '367200') config.set('bitmessagesettings', 'ttl', '367200')
print(
'updateConfig111 congfig.get(bitmessagesettings, settingsversion) -{}'.format(
config.get('bitmessagesettings','settingsversion')
))
config.set('bitmessagesettings', 'settingsversion', str(settingsversion)) config.set('bitmessagesettings', 'settingsversion', str(settingsversion))
print(
'updateConfig222 congfig.get(bitmessagesettings, settingsversion) -{}'.format(
config.get('bitmessagesettings','settingsversion')
))
config.save() config.save()

View File

@ -9,8 +9,6 @@ import tempfile
import time import time
import unittest import unittest
from pybitmessage.debug import logger
try: try:
import psutil import psutil
except ModuleNotFoundError: except ModuleNotFoundError:
@ -37,6 +35,7 @@ class TestProcessProto(unittest.TestCase):
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
"""Setup environment and start pybitmessage""" """Setup environment and start pybitmessage"""
cls.home = os.environ['BITMESSAGE_HOME'] = tempfile.gettempdir() cls.home = os.environ['BITMESSAGE_HOME'] = tempfile.gettempdir()
put_signal_file(cls.home, 'unittest.lock') put_signal_file(cls.home, 'unittest.lock')
subprocess.call(cls._process_cmd) # nosec subprocess.call(cls._process_cmd) # nosec