Ejemplo n.º 1
0
def test_valid_script_mode():
    args = cli.args().parse_args(['--script', '/foo.py bar'])
    config = cli.config(args)

    assert cli.script_mode(config) == [
        "--host", "--port", "8080", "--bind-address", "0.0.0.0", "--script",
        "/foo.py bar", "--quiet"
    ]
Ejemplo n.º 2
0
def test_valid_script_mode():
    args = cli.args().parse_args(['--script', '/foo.py bar'])
    config = cli.config(args)

    assert cli.script_mode(config) == ["--host",
                                       "--port", "8080",
                                       "--bind-address", "0.0.0.0",
                                       "--script", "/foo.py bar",
                                       "--quiet"]
Ejemplo n.º 3
0
def test_valid_driver_mode():
    base_path = cli.base_path()
    storage_path = cli.storage_path()
    args = cli.args().parse_args(['--source-dir', '/foo/bar'])
    config = cli.config(args)

    assert cli.driver_mode(config) == ["--host",
                                       "--port", "8080",
                                       "--bind-address", "0.0.0.0",
                                       "--script", "{}/scripts/flasked.py /foo/bar {}".format(base_path, storage_path),
                                       "--quiet"]
Ejemplo n.º 4
0
def test_valid_simple_mode():
    base_path = cli.base_path()
    args = cli.args().parse_args(['--url', 'http://localhost',
                                  '--response-body', './foo.json'])
    config = cli.config(args)

    assert cli.simple_mode(config) == ["--host",
                                       "--port", "8080",
                                       "--bind-address", "0.0.0.0",
                                       "--script", "{}/scripts/simple.py http://localhost ./foo.json".format(base_path),
                                       "--quiet"]
Ejemplo n.º 5
0
def test_valid_driver_mode():
    base_path = cli.base_path()
    storage_path = cli.storage_path()
    args = cli.args().parse_args(['--source-dir', '/foo/bar'])
    config = cli.config(args)
    expected = [
        "--host", "--port", "8080", "--bind-address", "0.0.0.0", "--script",
        "{}/scripts/flasked.py".format(base_path) +
        " /foo/bar {} 0.0.0.0 8080".format(storage_path), "--quiet"
    ]

    assert cli.driver_mode(config) == expected
Ejemplo n.º 6
0
def test_valid_simple_mode():
    base_path = cli.base_path()
    args = cli.args().parse_args(
        ['--url', 'http://localhost', '--response-body', './foo.json'])
    config = cli.config(args)
    expected = [
        "--host", "--port", "8080", "--bind-address", "0.0.0.0", "--script",
        "{}/scripts/simple.py".format(base_path) +
        " http://localhost ./foo.json", "--quiet"
    ]

    assert cli.simple_mode(config) == expected
Ejemplo n.º 7
0
def test_valid_driver_mode_config_file():
    base_path = cli.base_path()
    storage_path = cli.storage_path()
    args = cli.args().parse_args(['--config', 'test/fixtures/simple.toml'])
    config = cli.config(args)
    expected = [
        "--host", "--port", "8080", "--bind-address", "0.0.0.0", "--script",
        "{}/scripts/flasked.py".format(base_path) +
        " ./test/records {} 0.0.0.0 8080".format(storage_path), "--quiet"
    ]

    assert cli.driver_mode(config) == expected
Ejemplo n.º 8
0
def test_config_file_defaults():
    args = cli.args().parse_args(['--config', 'test/fixtures/simple.toml'])
    expected = {
        "core": {"host": "0.0.0.0",
                 "port": 8080,
                 "source-dir": "./test/records",
                 "verbose": 2},
        "mitm": {},
        "os": {"proxy-settings": (sys.platform == "darwin")}
    }

    assert cli.config(args) == expected
Ejemplo n.º 9
0
def test_valid_driver_mode_config_file():
    base_path = cli.base_path()
    storage_path = cli.storage_path()
    args = cli.args().parse_args(['--config', 'test/fixtures/simple.toml'])
    config = cli.config(args)
    expected = [
        "--host",
        "--port", "8080",
        "--bind-address", "0.0.0.0",
        "--script", "{}/scripts/flasked.py".format(base_path) +
                    " ./test/records {} 0.0.0.0 8080".format(storage_path),
        "--quiet"]

    assert cli.driver_mode(config) == expected
Ejemplo n.º 10
0
def test_valid_config_file_with_overwrites():
    args = cli.args().parse_args(['--config', 'test/fixtures/simple.toml',
                                  '--source-dir', 'foo/bar',
                                  '-vvv',
                                  '--without-proxy-settings'])
    expected = {
        "core": {"host": "0.0.0.0",
                 "port": 8080,
                 "source-dir": "foo/bar",
                 "verbose": 3},
        "mitm": {},
        "os": {"proxy-settings": False}
    }

    assert cli.config(args) == expected
Ejemplo n.º 11
0
def test_config_file_defaults():
    args = cli.args().parse_args(['--config', 'test/fixtures/simple.toml'])
    expected = {
        "core": {
            "host": "0.0.0.0",
            "port": 8080,
            "source-dir": "./test/records",
            "verbose": 2
        },
        "mitm": {},
        "os": {
            "proxy-settings": (sys.platform == "darwin")
        }
    }

    assert cli.config(args) == expected
Ejemplo n.º 12
0
def test_valid_config_file_with_overwrites():
    args = cli.args().parse_args([
        '--config', 'test/fixtures/simple.toml', '--source-dir', 'foo/bar',
        '-vvv', '--without-proxy-settings'
    ])
    expected = {
        "core": {
            "host": "0.0.0.0",
            "port": 8080,
            "source-dir": "foo/bar",
            "verbose": 3
        },
        "mitm": {},
        "os": {
            "proxy-settings": False
        }
    }

    assert cli.config(args) == expected
Ejemplo n.º 13
0
def test_unexpected_flags_driver_mode():
    args = cli.args().parse_args(['--url', 'http://localhost'])
    config = cli.config(args)

    assert type(cli.driver_mode(config)) == Exception
Ejemplo n.º 14
0
def test_no_response_body_simple_mode():
    args = cli.args().parse_args(['--url', 'http://localhost'])
    config = cli.config(args)

    assert type(cli.simple_mode(config)) == Exception
Ejemplo n.º 15
0
def test_no_url_simple_mode():
    args = cli.args().parse_args(['--response-body', './foo.json'])
    config = cli.config(args)

    assert type(cli.simple_mode(config)) == Exception
Ejemplo n.º 16
0
def test_valid_missing_config_file():
    args = cli.args().parse_args(['--config', 'fixtures/simple.toml'])
    with pytest.raises(IOError):
        cli.config(args)
Ejemplo n.º 17
0
 def test_proxy_settings_not_osx():
     args = cli.args().parse_args(['--config',
                                   'test/fixtures/proxy-on.toml'])
     with pytest.raises(StandardError):
         cli.config(args)
Ejemplo n.º 18
0
def test_valid_missing_config_file():
    args = cli.args().parse_args(['--config', 'fixtures/simple.toml'])
    with pytest.raises(IOError):
        cli.config(args)
Ejemplo n.º 19
0
 def test_proxy_settings_not_osx():
     args = cli.args().parse_args(
         ['--config', 'test/fixtures/proxy-on.toml'])
     with pytest.raises(StandardError):
         cli.config(args)
Ejemplo n.º 20
0
def test_verbosity_2():
    args = cli.args().parse_args(['-vv'])
    config = cli.config(args)

    assert cli.verbosity_args(config) == ["--quiet"]
Ejemplo n.º 21
0
def test_no_url_simple_mode():
    args = cli.args().parse_args(['--response-body', './foo.json'])
    config = cli.config(args)

    assert type(cli.simple_mode(config)) == Exception
Ejemplo n.º 22
0
def test_no_response_body_simple_mode():
    args = cli.args().parse_args(['--url', 'http://localhost'])
    config = cli.config(args)

    assert type(cli.simple_mode(config)) == Exception
Ejemplo n.º 23
0
def test_unexpected_flags_driver_mode():
    args = cli.args().parse_args(['--url', 'http://localhost'])
    config = cli.config(args)

    assert type(cli.driver_mode(config)) == Exception
Ejemplo n.º 24
0
def test_verbosity_3():
    args = cli.args().parse_args(['-vvv'])
    config = cli.config(args)

    assert cli.verbosity_args(config) == ["--quiet"]
Ejemplo n.º 25
0
def test_verbosity_6():
    args = cli.args().parse_args(['-vvvvvv'])
    config = cli.config(args)

    assert cli.verbosity_args(config) == ["-v", "-v", "-v"]
Ejemplo n.º 26
0
def test_verbosity_out_of_bounds():
    args = cli.args().parse_args(['-vvvvvvv'])
    config = cli.config(args)

    assert cli.verbosity_args(config) == ["-v", "-v", "-v"]