-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
User: Extend cli for 'exists' with recursive flag in order to loop ov…
…er schemas TYPE: Feature LINK: None
- Loading branch information
1 parent
d4483da
commit a0a7962
Showing
2 changed files
with
97 additions
and
6 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
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 |
---|---|---|
|
@@ -26,6 +26,7 @@ def test_cli(postgres_dsn, session_manager, temporary_directory, redis_url): | |
} | ||
|
||
session_manager.ensure_schema_exists('foo-bar') | ||
# session_manager.ensure_schema_exists('foo-zar') | ||
|
||
cfg_path = os.path.join(temporary_directory, 'onegov.yml') | ||
|
||
|
@@ -374,3 +375,85 @@ def login(username, yubikey=None): | |
user = session.query(User).filter_by(username=username).one() | ||
assert user.realname == 'Jane Doe' | ||
assert user.phone_number == '0411234567' | ||
|
||
|
||
def test_cli_exists_recursive(postgres_dsn, session_manager, | ||
temporary_directory, redis_url): | ||
|
||
cfg = { | ||
'applications': [ | ||
{ | ||
'path': '/foo/*', | ||
'application': 'onegov.core.Framework', | ||
'namespace': 'foo', | ||
'configuration': { | ||
'dsn': postgres_dsn, | ||
'redis_url': redis_url | ||
} | ||
} | ||
] | ||
} | ||
|
||
session_manager.ensure_schema_exists('foo-bar') | ||
session_manager.ensure_schema_exists('foo-zar') | ||
|
||
cfg_path = os.path.join(temporary_directory, 'onegov.yml') | ||
|
||
with open(cfg_path, 'w') as f: | ||
f.write(yaml.dump(cfg)) | ||
|
||
# Add user to bar | ||
runner = CliRunner() | ||
result = runner.invoke(cli, [ | ||
'--config', cfg_path, | ||
'--select', '/foo/bar', | ||
'add', 'admin', '[email protected]', | ||
'--password', 'hunterb', | ||
'--no-prompt', | ||
]) | ||
assert result.exit_code == 0 | ||
assert 'Adding [email protected] to foo/bar' in result.output | ||
assert '[email protected] was added' in result.output | ||
|
||
# add user to zar | ||
runner = CliRunner() | ||
result = runner.invoke(cli, [ | ||
'--config', cfg_path, | ||
'--select', '/foo/zar', | ||
'add', 'admin', '[email protected]', | ||
'--password', 'hunterz', | ||
'--no-prompt', | ||
]) | ||
assert result.exit_code == 0 | ||
assert 'Adding [email protected] to foo/zar' in result.output | ||
assert '[email protected] was added' in result.output | ||
|
||
# use exits to check if user exists in bar | ||
result = runner.invoke(cli, [ | ||
'--config', cfg_path, | ||
'--select', '/foo/bar', | ||
'exists', '[email protected]' | ||
]) | ||
assert result.exit_code == 0 | ||
assert 'foo-bar [email protected] exists' in result.output | ||
assert 'foo-zar admin@zar exists' not in result.output | ||
|
||
# use exits to check if user exists in zar | ||
result = runner.invoke(cli, [ | ||
'--config', cfg_path, | ||
'--select', '/foo/zar', | ||
'exists', '[email protected]' | ||
]) | ||
assert result.exit_code == 0 | ||
assert 'foo-zar [email protected] exists' in result.output | ||
assert 'foo-bar admin@bar exists' not in result.output | ||
|
||
# use recursive exists | ||
result = runner.invoke(cli, [ | ||
'--config', cfg_path, | ||
'--select', '/foo/*', | ||
'exists', '[email protected]', '-r' | ||
]) | ||
assert result.exit_code == 0 | ||
assert 'foo-bar [email protected] exists' in result.output | ||
assert 'foo-zar [email protected] does not exist' in result.output |