|
@@ -234,16 +234,14 @@ def test_check_certificate_crontab(host):
|
|
|
assert "0 0 * * * nobody /usr/local/bin/check_certificate.sh -q expiration" in check_certificate_crontab.content_string
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('virtualenv_activate_path', [
|
|
|
'/var/lib/pipreqcheck/virtualenv/bin/activate',
|
|
|
'/var/lib/pipreqcheck/virtualenv-py3/bin/activate',
|
|
|
])
|
|
|
def test_pipreqcheck_virtualenv(host, virtualenv_activate_path):
|
|
|
def test_pipreqcheck_virtualenv(host):
|
|
|
"""
|
|
|
Tests creation of Python virtual environment used for performing pip
|
|
|
requirements upgrade checks.
|
|
|
"""
|
|
|
|
|
|
virtualenv_activate_path = '/var/lib/pipreqcheck/virtualenv/bin/activate'
|
|
|
|
|
|
with host.sudo():
|
|
|
virtualenv_activate = host.file(virtualenv_activate_path)
|
|
|
|
|
@@ -253,16 +251,14 @@ def test_pipreqcheck_virtualenv(host, virtualenv_activate_path):
|
|
|
assert virtualenv_activate.mode == 0o644
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('config_dir', [
|
|
|
'/etc/pip_check_requirements_upgrades',
|
|
|
'/etc/pip_check_requirements_upgrades-py3',
|
|
|
])
|
|
|
def test_pipreqcheck_directories(host, config_dir):
|
|
|
def test_pipreqcheck_directories(host):
|
|
|
"""
|
|
|
Tests creation of directories used for storing configuration used by script
|
|
|
that performs pip requirements upgrade checks.
|
|
|
"""
|
|
|
|
|
|
config_dir = '/etc/pip_check_requirements_upgrades'
|
|
|
|
|
|
with host.sudo():
|
|
|
pipreqcheck_config_directory = host.file(config_dir)
|
|
|
assert pipreqcheck_config_directory.is_directory
|
|
@@ -277,18 +273,15 @@ def test_pipreqcheck_directories(host, config_dir):
|
|
|
assert pipreqcheck_config_directory_pipreqcheck.mode == 0o750
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('requirements_in_path, requirements_txt_path', [
|
|
|
('/etc/pip_check_requirements_upgrades/pipreqcheck/requirements.in',
|
|
|
'/etc/pip_check_requirements_upgrades/pipreqcheck/requirements.txt'),
|
|
|
('/etc/pip_check_requirements_upgrades-py3/pipreqcheck/requirements.in',
|
|
|
'/etc/pip_check_requirements_upgrades-py3/pipreqcheck/requirements.txt'),
|
|
|
])
|
|
|
def test_pipreqcheck_requirements(host, requirements_in_path, requirements_txt_path):
|
|
|
def test_pipreqcheck_requirements(host):
|
|
|
"""
|
|
|
Tests deployment of requirements input and text file used for virtual
|
|
|
environment utilised by script that perform pip requirements upgrade checks.
|
|
|
"""
|
|
|
|
|
|
requirements_in_path = '/etc/pip_check_requirements_upgrades/pipreqcheck/requirements.in'
|
|
|
requirements_txt_path = '/etc/pip_check_requirements_upgrades/pipreqcheck/requirements.txt'
|
|
|
|
|
|
with host.sudo():
|
|
|
requirements_in = host.file(requirements_in_path)
|
|
|
assert requirements_in.is_file
|
|
@@ -303,15 +296,15 @@ def test_pipreqcheck_requirements(host, requirements_in_path, requirements_txt_p
|
|
|
assert requirements_txt.mode == 0o640
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize("pip_path, expected_packages", [
|
|
|
('/var/lib/pipreqcheck/virtualenv/bin/pip', [
|
|
|
"click==7.1.2",
|
|
|
"pip-tools==5.5.0",
|
|
|
"pip==20.3.4",
|
|
|
"setuptools==44.1.1",
|
|
|
"wheel==0.37.1",
|
|
|
]),
|
|
|
('/var/lib/pipreqcheck/virtualenv-py3/bin/pip', [
|
|
|
def test_pipreqcheck_virtualenv_packages(host):
|
|
|
"""
|
|
|
Tests if correct packages are installed in virtualenv used for pip
|
|
|
requirements checks..
|
|
|
"""
|
|
|
|
|
|
pip_path = '/var/lib/pipreqcheck/virtualenv/bin/pip'
|
|
|
|
|
|
expected_packages = [
|
|
|
"build==1.0.3",
|
|
|
"click==8.1.7",
|
|
|
"importlib-metadata==6.7.0",
|
|
@@ -324,13 +317,7 @@ def test_pipreqcheck_requirements(host, requirements_in_path, requirements_txt_p
|
|
|
"typing_extensions==4.7.1",
|
|
|
"wheel==0.41.3",
|
|
|
"zipp==3.15.0",
|
|
|
]),
|
|
|
])
|
|
|
def test_pipreqcheck_virtualenv_packages(host, pip_path, expected_packages):
|
|
|
"""
|
|
|
Tests if correct packages are installed in virtualenv used for pip
|
|
|
requirements checks..
|
|
|
"""
|
|
|
]
|
|
|
|
|
|
packages = host.run("sudo -u pipreqcheck %s freeze --all", pip_path)
|
|
|
|
|
@@ -362,16 +349,14 @@ def test_pipreqcheck_script(host):
|
|
|
assert pipreqcheck_script.mode == 0o755
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('crontab_path, virtualenv_path', [
|
|
|
('/etc/cron.d/check_pip_requirements', '/var/lib/pipreqcheck/virtualenv'),
|
|
|
('/etc/cron.d/check_pip_requirements-py3', '/var/lib/pipreqcheck/virtualenv-py3'),
|
|
|
])
|
|
|
def test_pipreqcheck_crontab(host, crontab_path, virtualenv_path):
|
|
|
def test_pipreqcheck_crontab(host):
|
|
|
"""
|
|
|
Tests if crontab entry is set-up correctly for running the pip requirements
|
|
|
upgrade checks.
|
|
|
"""
|
|
|
|
|
|
crontab_path = '/etc/cron.d/check_pip_requirements'
|
|
|
virtualenv_path = '/var/lib/pipreqcheck/virtualenv'
|
|
|
crontab = host.file(crontab_path)
|
|
|
|
|
|
assert crontab.is_file
|
|
@@ -382,16 +367,15 @@ def test_pipreqcheck_crontab(host, crontab_path, virtualenv_path):
|
|
|
assert virtualenv_path in crontab.content_string.split(" ")
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('python_path, expected_major_version', [
|
|
|
('/var/lib/pipreqcheck/virtualenv/bin/python', '2'),
|
|
|
('/var/lib/pipreqcheck/virtualenv-py3/bin/python', '3'),
|
|
|
])
|
|
|
def test_pipreqcheck_virtualenv_python_version(host, python_path, expected_major_version):
|
|
|
def test_pipreqcheck_virtualenv_python_version(host):
|
|
|
"""
|
|
|
Tests if Python virtual environment for pipreqcheck has been
|
|
|
set-up correctly.
|
|
|
"""
|
|
|
|
|
|
python_path = '/var/lib/pipreqcheck/virtualenv/bin/python'
|
|
|
expected_major_version = '3'
|
|
|
|
|
|
with host.sudo('pipreqcheck'):
|
|
|
major_version = host.run("%s -c %s", python_path, "import sys; print(sys.version_info.major)")
|
|
|
|
|
@@ -399,37 +383,21 @@ def test_pipreqcheck_virtualenv_python_version(host, python_path, expected_major
|
|
|
assert major_version.stdout.strip() == expected_major_version
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('wrong_python_path', [
|
|
|
'/var/lib/pipreqcheck/virtualenv/bin/python3',
|
|
|
'/var/lib/pipreqcheck/virtualenv-py3/bin/python2.7',
|
|
|
])
|
|
|
def test_pipreqcheck_virtualenv_wrong_python_version_not_present(host, wrong_python_path):
|
|
|
"""
|
|
|
Tests if wrong version of Python 2 is absent or not.
|
|
|
"""
|
|
|
|
|
|
with host.sudo():
|
|
|
wrong_python_path_file = host.file(wrong_python_path)
|
|
|
|
|
|
assert not wrong_python_path_file.exists
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('environment,config_directory', [
|
|
|
('/var/lib/pipreqcheck/virtualenv', '/tmp/pip_check_requirements_upgrades'),
|
|
|
('/var/lib/pipreqcheck/virtualenv-py3', '/tmp/pip_check_requirements_upgrades-py3'),
|
|
|
])
|
|
|
def test_pipreqcheck_script_output(host, environment, config_directory):
|
|
|
def test_pipreqcheck_script_output(host):
|
|
|
"""
|
|
|
Tests if the pip_check_requirements_upgrades.sh script properly
|
|
|
reports available updates or not.
|
|
|
"""
|
|
|
|
|
|
virtualenv = '/var/lib/pipreqcheck/virtualenv'
|
|
|
config_directory = '/tmp/pip_check_requirements_upgrades'
|
|
|
|
|
|
expected_line_count = 9
|
|
|
expected_warning_message = "[WARN] Upgrades available for: %s/with_updates/requirements.txt" % config_directory
|
|
|
expected_package_diff = "@@ -1 +1 @@\n-urllib3==1.24.2\n+urllib3==1.24.3"
|
|
|
|
|
|
with host.sudo("pipreqcheck"):
|
|
|
report = host.run("/usr/local/bin/pip_check_requirements_upgrades.sh -q -V %s %s", environment, config_directory)
|
|
|
report = host.run("/usr/local/bin/pip_check_requirements_upgrades.sh -q -V %s %s", virtualenv, config_directory)
|
|
|
|
|
|
# Clean-up the SSH warning from the beginning of stderr if
|
|
|
# present.
|