Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_cli_shortcuts(mock_run_add_shortcut):
"""
Tests that the CLI calls add shortcuts.
"""
file = "1.json"
shortcut = "most-recent"
directory = "tests/data/test_cli_detectors/detector"
cli = CLI(prog="cartography-detectdrift")
cli.main(["add-shortcut",
"--query-directory",
directory,
"--shortcut",
shortcut,
"--file",
file])
mock_run_add_shortcut.assert_called_once()
def test_bad_shortcut():
cli = CLI(prog="cartography-detectdrift")
directory = "tests/data/test_cli_detectors/bad_shortcut"
start_state = "1.json"
end_state = "invalid-shortcut"
with pytest.raises(FileNotFoundError):
cli.main([
"get-drift",
"--query-directory",
directory,
"--start-state",
start_state,
"--end-state",
end_state,
])
def test_configure():
"""
Tests that the configure method correctly parses args.
"""
cli = CLI(prog="cartography-detectdrift")
config = cli.configure([
"get-state",
"--neo4j-uri",
settings.get("NEO4J_URL"),
"--drift-detection-directory",
"tests/data/detectors"
])
assert config.drift_detection_directory == "tests/data/detectors"
assert config.neo4j_uri == settings.get("NEO4J_URL")
def test_cli_get_drift(mock_run_drift_detection):
"""
Tests that get_drift is called.
"""
start_state = "1.json"
end_state = "2.json"
directory = "tests/data/test_cli_detectors/detector"
cli = CLI(prog="cartography-detectdrift")
cli.main(["get-drift",
"--query-directory",
directory,
"--start-state",
start_state,
"--end-state",
end_state])
mock_run_drift_detection.assert_called_once()
def test_cli_main(mock_run):
"""
Tests that CLI runs update.
"""
cli = CLI(prog="cartography-detectdrift")
cli.main(["get-state",
"--neo4j-uri",
settings.get("NEO4J_URL"),
"--drift-detection-directory",
"tests/data/test_update_detectors"])
mock_run.assert_called_once()
def test_nonexistent_shortcuts():
cli = CLI(prog="cartography-detectdrift")
directory = "tests/data/test_cli_detectors/detector"
alias = "test_shortcut"
filename = "3.json"
shortcut_path = os.path.join(directory, "shortcut.json")
cli.main([
"add-shortcut",
"--query-directory",
directory,
"--shortcut",
alias,
"--file",
filename,
])
shortcut_data = FileSystem.load(shortcut_path)
shortcut = ShortcutSchema().load(shortcut_data)
with pytest.raises(KeyError):
def test_shortcut_fails_when_shortcut_exists():
"""
Tests add_shortcut fails when shortcuts exist.
"""
cli = CLI(prog="cartography-detectdrift")
directory = "tests/data/test_cli_detectors/detector"
alias = "2.json"
filename = "1.json"
cli.main([
"add-shortcut",
"--query-directory",
directory,
"--shortcut",
alias,
"--file",
filename,
])
shortcut_path = directory + '/shortcut.json'
shortcut_data = FileSystem.load(shortcut_path)
shortcut = ShortcutSchema().load(shortcut_data)
with pytest.raises(KeyError):
def test_use_shortcuts_for_shortcuts():
"""
Tests add_shortcut can parse shortcuts.
"""
cli = CLI(prog="cartography-detectdrift")
directory = "tests/data/test_cli_detectors/detector"
alias = "test_shortcut"
alias_2 = "test_shortcut_2"
filename = "1.json"
shortcut_path = directory + '/shortcut.json'
cli.main([
"add-shortcut",
"--query-directory",
directory,
"--shortcut",
alias,
"--file",
filename,
])
cli.main([
"add-shortcut",
def test_basic_add_shortcuts():
"""
Tests that the CLI can add shortcuts.
"""
cli = CLI(prog="cartography-detectdrift")
directory = "tests/data/test_cli_detectors/detector"
alias = "test_shortcut"
filename = "1.json"
shortcut_path = directory + '/shortcut.json'
cli.main([
"add-shortcut",
"--query-directory",
directory,
"--shortcut",
alias,
"--file",
filename,
])
shortcut_data = FileSystem.load(shortcut_path)
shortcut = ShortcutSchema().load(shortcut_data)
assert shortcut.shortcuts[alias] == filename
def main(argv=None):
logging.basicConfig(level=logging.INFO)
logging.getLogger('neo4j.bolt').setLevel(logging.WARNING)
argv = argv if argv is not None else sys.argv[1:]
return CLI(prog="cartography-detectdrift").main(argv)