diff --git a/roles/common/molecule/default/tests/test_default.py b/roles/common/molecule/default/tests/test_default.py index e23f5d53bc568d4d7b0009afea35c30593583893..6cc70df8d3f9b2a5c84c76a7402027c78b42a13e 100644 --- a/roles/common/molecule/default/tests/test_default.py +++ b/roles/common/molecule/default/tests/test_default.py @@ -305,21 +305,41 @@ def test_pipreqcheck_requirements(host, requirements_in_path, requirements_txt_p assert requirements_txt.mode == 0o640 -@pytest.mark.parametrize('pip_path', [ - '/var/lib/pipreqcheck/virtualenv/bin/pip', - '/var/lib/pipreqcheck/virtualenv-py3/bin/pip', +@pytest.mark.parametrize("pip_path, expected_packages", [ + ('/var/lib/pipreqcheck/virtualenv/bin/pip', [ + "Click==7.0", + "pip==18.1", + "pip-tools==3.1.0", + "setuptools==40.6.2", + "six==1.11.0", + "wheel==0.32.3" + ]), + ('/var/lib/pipreqcheck/virtualenv-py3/bin/pip', [ + "Click==7.0", + "pip==18.1", + "pip-tools==3.1.0", + "setuptools==40.6.2", + "six==1.11.0", + "wheel==0.32.3", + ]), ]) -def test_pipreqcheck_packages(host, pip_path): +def test_pipreqcheck_virtualenv_packages(host, pip_path, expected_packages): """ - Tests if Python virtual environment used for running the pip requirements - upgrade checks has correct version of pip installed. + Tests if correct packages are installed in virtualenv used for pip + requirements checks.. """ - with host.sudo(): - packages = host.pip_package.get_packages(pip_path=pip_path) + packages = host.run("sudo -u %s %s freeze --all" % ('pipreqcheck', pip_path)) + + # Normalise package names and order. + expected_packages = sorted([unicode(p.lower()) for p in expected_packages]) + actual_packages = sorted(packages.stdout.lower().split("\n")) + + # This is a dummy distro-provided package ignored by the pip-tools. + if "pkg-resources==0.0.0" in actual_packages: + actual_packages.remove("pkg-resources==0.0.0") - assert packages['pip']['version'].rsplit('.', 1)[0] == '18' - assert 'pip-tools' in packages + assert actual_packages == expected_packages def test_pipreqcheck_script(host):