Changeset - 896fbddd5887
[Not reviewed]
0 1 0
Branko Majic (branko) - 6 years ago 2018-07-30 17:13:11
branko@majic.rs
MAR-131: Refactored pipreqcheck tests in common role to be parametrised, part of preparing for adding Python 3 support.
1 file changed with 31 insertions and 12 deletions:
0 comments (0 inline, 0 general)
roles/common/molecule/default/tests/test_default.py
Show inline comments
 
@@ -2,6 +2,8 @@ import os
 

	
 
import testinfra.utils.ansible_runner
 

	
 
import pytest
 

	
 

	
 
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
 
    os.environ['MOLECULE_INVENTORY_FILE']).get_hosts(['parameters-mandatory', 'parameters-optional'])
 
@@ -230,14 +232,17 @@ def test_check_certificate_crontab(host):
 
    assert "0 0 * * * nobody /usr/local/bin/check_certificate.sh expiration" in check_certificate_crontab.content
 

	
 

	
 
def test_pipreqcheck_virtualenv(host):
 
@pytest.mark.parametrize('virtualenv_activate_path', [
 
    '/var/lib/pipreqcheck/virtualenv/bin/activate',
 
])
 
def test_pipreqcheck_virtualenv(host, virtualenv_activate_path):
 
    """
 
    Tests creation of Python virtual environment used for performing pip
 
    requirements upgrade checks.
 
    """
 

	
 
    with host.sudo():
 
        virtualenv_activate = host.file('/var/lib/pipreqcheck/virtualenv/bin/activate')
 
        virtualenv_activate = host.file(virtualenv_activate_path)
 

	
 
        assert virtualenv_activate.is_file
 
        assert virtualenv_activate.user == 'pipreqcheck'
 
@@ -245,54 +250,64 @@ def test_pipreqcheck_virtualenv(host):
 
        assert virtualenv_activate.mode == 0o644
 

	
 

	
 
def test_pipreqcheck_directories(host):
 
@pytest.mark.parametrize('config_dir', [
 
    '/etc/pip_check_requirements_upgrades',
 
])
 
def test_pipreqcheck_directories(host, config_dir):
 
    """
 
    Tests creation of directories used for storing configuration used by script
 
    that performs pip requirements upgrade checks.
 
    """
 

	
 
    with host.sudo():
 
        pipreqcheck_config_directory = host.file('/etc/pip_check_requirements_upgrades')
 
        pipreqcheck_config_directory = host.file(config_dir)
 
        assert pipreqcheck_config_directory.is_directory
 
        assert pipreqcheck_config_directory.user == 'root'
 
        assert pipreqcheck_config_directory.group == 'pipreqcheck'
 
        assert pipreqcheck_config_directory.mode == 0o750
 

	
 
        pipreqcheck_config_directory_pipreqcheck = host.file('/etc/pip_check_requirements_upgrades/pipreqcheck')
 
        pipreqcheck_config_directory_pipreqcheck = host.file(os.path.join(config_dir, 'pipreqcheck'))
 
        assert pipreqcheck_config_directory_pipreqcheck.is_directory
 
        assert pipreqcheck_config_directory_pipreqcheck.user == 'root'
 
        assert pipreqcheck_config_directory_pipreqcheck.group == 'pipreqcheck'
 
        assert pipreqcheck_config_directory_pipreqcheck.mode == 0o750
 

	
 

	
 
def test_pipreqcheck_requirements(host):
 
@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'),
 
])
 
def test_pipreqcheck_requirements(host, requirements_in_path, requirements_txt_path):
 
    """
 
    Tests deployment of requirements input and text file used for virtual
 
    environment utilised by script that perform pip requirements upgrade checks.
 
    """
 

	
 
    with host.sudo():
 
        requirements_in = host.file('/etc/pip_check_requirements_upgrades/pipreqcheck/requirements.in')
 
        requirements_in = host.file(requirements_in_path)
 
        assert requirements_in.is_file
 
        assert requirements_in.user == 'root'
 
        assert requirements_in.group == 'pipreqcheck'
 
        assert requirements_in.mode == 0o640
 

	
 
        requirements_txt = host.file('/etc/pip_check_requirements_upgrades/pipreqcheck/requirements.txt')
 
        requirements_txt = host.file(requirements_txt_path)
 
        requirements_txt.is_file
 
        assert requirements_txt.user == 'root'
 
        assert requirements_txt.group == 'pipreqcheck'
 
        assert requirements_txt.mode == 0o640
 

	
 

	
 
def test_pipreqcheck_packages(host):
 
@pytest.mark.parametrize('pip_path', [
 
    '/var/lib/pipreqcheck/virtualenv/bin/pip',
 
])
 
def test_pipreqcheck_packages(host, pip_path):
 
    """
 
    Tests if Python virtual environment used for running the pip requirements
 
    upgrade checks has correct version of pip installed.
 
    """
 

	
 
    with host.sudo():
 
        packages = host.pip_package.get_packages(pip_path='/var/lib/pipreqcheck/virtualenv/bin/pip')
 
        packages = host.pip_package.get_packages(pip_path=pip_path)
 

	
 
        assert packages['pip']['version'].rsplit('.', 1)[0] == '9.0'
 
        assert 'pip-tools' in packages
 
@@ -311,16 +326,20 @@ def test_pipreqcheck_script(host):
 
    assert pipreqcheck_script.mode == 0o755
 

	
 

	
 
def test_pipreqcheck_crontab(host):
 
@pytest.mark.parametrize('crontab_path, virtualenv_path', [
 
    ('/etc/cron.d/check_pip_requirements', '/var/lib/pipreqcheck/virtualenv'),
 
])
 
def test_pipreqcheck_crontab(host, crontab_path, virtualenv_path):
 
    """
 
    Tests if crontab entry is set-up correctly for running the pip requirements
 
    upgrade checks.
 
    """
 

	
 
    crontab = host.file('/etc/cron.d/check_pip_requirements')
 
    crontab = host.file(crontab_path)
 

	
 
    assert crontab.is_file
 
    assert crontab.user == 'root'
 
    assert crontab.group == 'root'
 
    assert crontab.mode == 0o644
 
    assert "MAILTO=root" in crontab.content
 
    assert virtualenv_path in crontab.content
0 comments (0 inline, 0 general)