Beispiel #1
0
def test_copy_default_config_to_local_does_not_exist(copyfile):
    random_name = ''.join(
        random.choice(string.ascii_uppercase + string.digits)
        for _ in range(25))
    filename = Path(tempfile.gettempdir()) / random_name

    with mock.patch('faraday.server.config.LOCAL_CONFIG_FILE', filename):
        assert copy_default_config_to_local() is None
        assert copyfile.called

    # the second call will re use the file just created.
    copyfile.reset_mock()
    assert copy_default_config_to_local() is None
    assert not copyfile.called
Beispiel #2
0
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 range(25)])
    app.config['SECRET_KEY'] = secret_key
    try:
        config.set('faraday_server', 'secret_key', secret_key)
    except NoSectionError:
        config.add_section('faraday_server')
        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('faraday.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