You've already forked httpie-cli
mirror of
https://github.com/httpie/cli.git
synced 2025-08-10 22:42:05 +02:00
Don't fail if config dir not writeable (close #738)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
from httpie import __version__
|
||||
from utils import MockEnvironment, http
|
||||
from utils import MockEnvironment, http, HTTP_OK
|
||||
from httpie.context import Environment
|
||||
|
||||
|
||||
@@ -11,6 +11,14 @@ def test_default_options(httpbin):
|
||||
assert r.json['form'] == {"foo": "bar"}
|
||||
|
||||
|
||||
def test_config_dir_not_writeable(httpbin):
|
||||
r = http(httpbin + '/get', env=MockEnvironment(
|
||||
config_dir='/',
|
||||
create_temp_config_dir=False,
|
||||
))
|
||||
assert HTTP_OK in r
|
||||
|
||||
|
||||
def test_default_options_overwrite(httpbin):
|
||||
env = MockEnvironment()
|
||||
env.config['default_options'] = ['--form']
|
||||
@@ -19,22 +27,6 @@ def test_default_options_overwrite(httpbin):
|
||||
assert r.json['json'] == {"foo": "bar"}
|
||||
|
||||
|
||||
def test_migrate_implicit_content_type():
|
||||
config = MockEnvironment().config
|
||||
|
||||
config['implicit_content_type'] = 'json'
|
||||
config.save()
|
||||
config.load()
|
||||
assert 'implicit_content_type' not in config
|
||||
assert not config['default_options']
|
||||
|
||||
config['implicit_content_type'] = 'form'
|
||||
config.save()
|
||||
config.load()
|
||||
assert 'implicit_content_type' not in config
|
||||
assert config['default_options'] == ['--form']
|
||||
|
||||
|
||||
def test_current_version():
|
||||
version = Environment().config['__meta__']['httpie']
|
||||
assert version == __version__
|
||||
|
@@ -39,7 +39,8 @@ class MockEnvironment(Environment):
|
||||
stdout_isatty = True
|
||||
is_windows = False
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
def __init__(self, create_temp_config_dir=True, **kwargs):
|
||||
self.create_temp_config_dir = create_temp_config_dir
|
||||
if 'stdout' not in kwargs:
|
||||
kwargs['stdout'] = tempfile.TemporaryFile(
|
||||
mode='w+b',
|
||||
@@ -55,7 +56,8 @@ class MockEnvironment(Environment):
|
||||
|
||||
@property
|
||||
def config(self):
|
||||
if not self.config_dir.startswith(tempfile.gettempdir()):
|
||||
if (self.create_temp_config_dir
|
||||
and not self.config_dir.startswith(tempfile.gettempdir())):
|
||||
self.config_dir = mk_config_dir()
|
||||
self._delete_config_dir = True
|
||||
return super(MockEnvironment, self).config
|
||||
|
Reference in New Issue
Block a user