Files
deb-python-dcos/integrations/cli/test_dcos.py
José Armando García Sancio 838da66e2f dcos-97 Implements installing a subcommand
There is quite a bit going on in this commit. Here is a high level
description of all of the changes:

* Improved the README to include information for running the
  integrations tests now that we have subcommand management support.
* Change the clean script to also delete the build directory.
* Removed requirement on the DCOS_PATH environment variable. We now
  assume the DCOS CLI installation directory based on the location of
  the dcos cli binary
* Adds support for installing subcommand from python wheels. The
  packages are install under the 'subcommands' directory.
* Extended the `dcos help` to look into the 'subcommands'
  directory for the excutables that extend the cli.
* Fix the root `dcos` executable to not use the DCOS_PATH environment
  variable to discover subcommand. It now discovers subcommand based
  on the location of the root (`dcos`) executable.
* Adds `dcos subcommand` for managing the installation, listing and
  the removal of subcommands.
* Adds dependencies on pkginfo and virtualenv. We need pkginfo to query
  information about the package. We need virtualenv to create
  virtual environment for each subcommand installed.
2015-03-11 17:05:41 -07:00

103 lines
3.3 KiB
Python

import os
from dcos.api import constants
from common import exec_command
def test_help():
returncode, stdout, stderr = exec_command(['dcos', '--help'])
assert returncode == 0
assert stdout == b"""Usage:
dcos [options] <command> [<args>...]
Options:
--help Show this screen
--version Show version
--log-level=<log-level> If set then print supplementary messages to
stderr at or above this level. The severity
levels in the order of severity are: debug,
info, warning, error, and critical. E.g.
Setting the option to warning will print
warning, error and critical messages to stderr.
Note: that this does not affect the output sent
to stdout by the command.
Environment Variables:
DCOS_LOG_LEVEL If set then it specifies that message should be
printed to stderr at or above this level. See
the --log-level option for details.
DCOS_CONFIG This environment variable points to the
location of the DCOS configuration file.
'dcos help --all' lists all available subcommands. See 'dcos <command> --help'
to read about a specific subcommand.
"""
assert stderr == b''
def test_version():
returncode, stdout, stderr = exec_command(['dcos', '--version'])
assert returncode == 0
assert stdout == b'dcos version 0.1.0\n'
assert stderr == b''
def test_missing_dcos_config():
env = {
constants.PATH_ENV: os.environ[constants.PATH_ENV],
}
returncode, stdout, stderr = exec_command(['dcos'], env=env)
assert returncode == 1
assert stdout == (b"Environment variable 'DCOS_CONFIG' must be set "
b"to the DCOS config file.\n")
assert stderr == b''
def test_dcos_config_not_a_file():
env = {
constants.PATH_ENV: os.environ[constants.PATH_ENV],
'DCOS_CONFIG': 'missing/file',
}
returncode, stdout, stderr = exec_command(['dcos'], env=env)
assert returncode == 1
assert stdout == (b"Environment variable 'DCOS_CONFIG' maps to "
b"'missing/file' and it is not a file.\n")
assert stderr == b''
def test_log_level_flag():
returncode, stdout, stderr = exec_command(
['dcos', '--log-level=info', 'config', 'info'])
assert returncode == 0
assert stdout == b"Get and set DCOS command line options\n"
assert stderr == b''
def test_capital_log_level_flag():
returncode, stdout, stderr = exec_command(
['dcos', '--log-level=INFO', 'config', 'info'])
assert returncode == 0
assert stdout == b"Get and set DCOS command line options\n"
assert stderr == b''
def test_invalid_log_level_flag():
returncode, stdout, stderr = exec_command(
['dcos', '--log-level=blah', 'config', 'info'])
assert returncode == 1
assert stdout == (b"Log level set to an unknown value 'blah'. Valid "
b"values are ['debug', 'info', 'warning', 'error', "
b"'critical']\n")
assert stderr == b''