Skip to content

Commit

Permalink
Improve test
Browse files Browse the repository at this point in the history
* Use a dedicated separate test
* Check the autofill is not already set before the CLI call
  • Loading branch information
sphuber committed Oct 31, 2022
1 parent 006e476 commit 4ba9766
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions tests/cmdline/commands/test_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,34 @@ def test_quicksetup_from_config_file(self):
handle.flush()
self.cli_runner(cmd_setup.quicksetup, ['--config', os.path.realpath(handle.name)])

def test_quicksetup_autofill_on_early_exit(self):
"""Test `verdi quicksetup` stores user information even if command fails."""
config = configuration.get_config()
assert config.get_option('autofill.user.email', scope=None) is None
assert config.get_option('autofill.user.first_name', scope=None) is None
assert config.get_option('autofill.user.last_name', scope=None) is None
assert config.get_option('autofill.user.institution', scope=None) is None

user_email = 'some@email.com'
user_first_name = 'John'
user_last_name = 'Smith'
user_institution = 'ECMA'

# The incorrect port will cause the command to fail, but the user information should have been stored on the
# configuration such that the user won't have to retype it but can use the pre-stored defaults.
options = [
'--non-interactive', '--profile', 'testing', '--email', user_email, '--first-name', user_first_name,
'--last-name', user_last_name, '--institution', user_institution, '--db-port',
self.pg_test.dsn['port'] + 100
]

self.cli_runner(cmd_setup.quicksetup, options, raises=True)

assert config.get_option('autofill.user.email', scope=None) == user_email
assert config.get_option('autofill.user.first_name', scope=None) == user_first_name
assert config.get_option('autofill.user.last_name', scope=None) == user_last_name
assert config.get_option('autofill.user.institution', scope=None) == user_institution

def test_quicksetup_wrong_port(self):
"""Test `verdi quicksetup` exits if port is wrong."""
profile_name = 'testing'
Expand All @@ -115,10 +143,6 @@ def test_quicksetup_wrong_port(self):

self.cli_runner(cmd_setup.quicksetup, options, raises=True)

# test
config = configuration.get_config()
assert config.get_option('autofill.user.email', scope=None) == user_email

def test_setup(self):
"""Test `verdi setup` (non-interactive)."""
postgres = Postgres(interactive=False, quiet=True, dbinfo=self.pg_test.dsn)
Expand Down

0 comments on commit 4ba9766

Please sign in to comment.