-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from ewjoachim/lib
Refactor the tool to be usable as a Python lib too
- Loading branch information
Showing
22 changed files
with
1,244 additions
and
419 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,7 @@ | |
__pycache__/ | ||
build | ||
dist | ||
.coverage | ||
htmlcov | ||
.tox | ||
*.pyc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Config file for automatic testing at travis-ci.org | ||
language: python | ||
|
||
services: | ||
- docker | ||
|
||
matrix: | ||
include: | ||
|
||
- python: 3.6 | ||
env: TOX_ENV=py36-unit-tests COVERAGE_FLAG=unit | ||
|
||
- python: 3.6 | ||
env: TOX_ENV=py36-integration-tests COVERAGE_FLAG=integration | ||
|
||
- python: 2.7 | ||
env: TOX_ENV=py27-unit-tests COVERAGE_FLAG=unit | ||
|
||
- python: 2.7 | ||
env: TOX_ENV=py27-integration-tests COVERAGE_FLAG=integration | ||
|
||
before_install: | ||
- "if [ $COVERAGE_FLAG = integration ]; then ./dev-env; fi" | ||
|
||
install: | ||
- pip install tox codecov | ||
|
||
script: | ||
- tox -e $TOX_ENV | ||
|
||
after_success: | ||
- bash <(curl -s https://codecov.io/bash) -c -F $COVERAGE_FLAG |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import pytest | ||
|
||
from vault_cli import settings | ||
|
||
|
||
@pytest.fixture | ||
def config(): | ||
old = settings.CONFIG | ||
settings.CONFIG = {} | ||
yield settings.CONFIG | ||
settings.CONFIG = old |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
from vault_cli.cli import cli | ||
from vault_cli import get_client | ||
from vault_cli import settings | ||
|
||
|
||
def call(cli_runner, *args): | ||
call = cli_runner.invoke(cli, *args, default_map=settings.CONFIG) | ||
assert call.exit_code == 0, call.output | ||
return call | ||
|
||
|
||
def test_integration_cli(cli_runner): | ||
call(cli_runner, ["set", "a", "b"]) | ||
|
||
assert call(cli_runner, ["get", "a", "--text"]).output == "b\n" | ||
|
||
assert call(cli_runner, ["list"]).output == "a\n" | ||
|
||
call(cli_runner, ["set", "c/d", "e"]) | ||
|
||
assert call(cli_runner, ["get", "c/d"]).output == "--- e\n...\n" | ||
|
||
assert call(cli_runner, ["list"]).output == "a\nc/\n" | ||
|
||
assert call(cli_runner, ["list", "c"]).output == "d\n" | ||
|
||
assert call(cli_runner, ["get-all", ""]).output == ("""--- | ||
a: b | ||
c: | ||
d: e | ||
""") | ||
|
||
call(cli_runner, ["delete", "a"]) | ||
|
||
assert call(cli_runner, ["list"]).output == "c/\n" | ||
|
||
call(cli_runner, ["delete", "c/d"]) | ||
|
||
|
||
def test_integration_lib(): | ||
|
||
client = get_client() | ||
|
||
client.set_secret("a", "b") | ||
|
||
assert client.get_secret("a") == "b" | ||
|
||
assert client.list_secrets("") == ["a"] | ||
|
||
client.set_secret("c/d", "e") | ||
|
||
assert client.get_secret("c/d") == "e" | ||
|
||
assert client.list_secrets("") == ["a", "c/"] | ||
|
||
assert client.list_secrets("c") == ["d"] | ||
|
||
assert client.get_all([""]) == {"a": "b", "c": {"d": "e"}} | ||
|
||
client.delete_secret("a") | ||
|
||
assert client.list_secrets("") == ["c/"] | ||
|
||
client.delete_secret("c/d") |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.