def save_new_secret_key(app): if not os.path.exists(LOCAL_CONFIG_FILE): copy_default_config_to_local() config = ConfigParser() config.read(LOCAL_CONFIG_FILE) rng = SystemRandom() secret_key = "".join([rng.choice(string.ascii_letters + string.digits) for _ in xrange(25)]) app.config['SECRET_KEY'] = secret_key config.set('faraday_server', 'secret_key', secret_key) with open(LOCAL_CONFIG_FILE, 'w') as configfile: config.write(configfile)
def test_copy_default_config_to_local_does_not_exist(copyfile, makedirs): random_name = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(25)) new_file = '/tmp/{0}'.format(random_name) with mock.patch('server.config.LOCAL_CONFIG_FILE', new_file): assert copy_default_config_to_local() is None assert makedirs.called assert copyfile.called # the second call will re use the file just created. makedirs.reset_mock() copyfile.reset_mock() assert copy_default_config_to_local() is None assert not makedirs.called assert not copyfile.called
def test_copy_default_config_to_local_does_not_exist(copyfile, makedirs): random_name = ''.join( random.choice(string.ascii_uppercase + string.digits) for _ in range(25)) new_file = '/tmp/{0}'.format(random_name) with mock.patch('server.config.LOCAL_CONFIG_FILE', new_file): assert copy_default_config_to_local() is None assert makedirs.called assert copyfile.called # the second call will re use the file just created. makedirs.reset_mock() copyfile.reset_mock() assert copy_default_config_to_local() is None assert not makedirs.called assert not copyfile.called