tests should cover most ofthe usecases now

This commit is contained in:
Bertrand Lanson 2023-03-16 22:57:55 +01:00
parent cc72967a75
commit 12eedf48e7
3 changed files with 37 additions and 12 deletions

View File

@ -15,8 +15,16 @@ def test_python_pip_packages_installed(host):
assert apt_package_python3.is_installed
assert apt_package_pip.is_installed
def test_pip_installed_latest(host):
"""Validate pip is installed and up-to-date"""
pip_packages_list = host.pip.get_packages(pip_path='pip')
pip_outdated_list = host.pip.get_outdated_packages(pip_path='pip')
assert 'pip' in pip_packages_list
assert 'pip' not in pip_outdated_list
def test_packages_not_installed(host):
"""Validate vim is installed"""
pip_packages_list = host.pip_package.get_packages(pip_path='pip')
print(pip_packages_list)
assert True == False
"""Validate docker, yamllint and vault-cli are not installed"""
pip_packages_list = host.pip.get_packages(pip_path='pip')
assert 'docker' not in pip_packages_list
assert 'yamllint' not in pip_packages_list
assert 'vault-cli' not in pip_packages_list

View File

@ -1,5 +1,6 @@
"""Role testing files using testinfra."""
import json
from packaging import version
def test_hosts_file(host):
"""Validate /etc/hosts file."""
@ -15,11 +16,22 @@ def test_python_pip_packages_installed(host):
assert apt_package_python3.is_installed
assert apt_package_pip.is_installed
def test_packages_not_installed(host):
"""Validate vim is installed"""
pip_packages_list = host.pip_package.get_packages(pip_path='pip')
assert pip_packages_list['pip']
assert pip_packages_list['docker']
assert pip_packages_list['zeubi']
print(pip_packages_list)
def test_pip_installed_latest(host):
"""Validate pip is installed and up-to-date"""
pip_packages_list = host.pip.get_packages(pip_path='pip')
pip_outdated_list = host.pip.get_outdated_packages(pip_path='pip')
assert 'pip' in pip_packages_list
assert 'pip' not in pip_outdated_list
def test_packages_installed(host):
"""Validate docker, yamllint and vault-cli are installed"""
pip_packages_list = host.pip.get_packages(pip_path='pip')
pip_outdated_list = host.pip.get_outdated_packages(pip_path='pip')
assert 'docker' in pip_packages_list
assert 'docker' not in pip_outdated_list
assert 'yamllint' in pip_packages_list
assert 'yamllint' in pip_outdated_list
assert version.parse(pip_packages_list['yamllint']['version']) == version.parse("1.24")
assert 'vault-cli' in pip_packages_list
assert 'vault-cli' in pip_outdated_list
assert version.parse(pip_packages_list['vault-cli']['version']) < version.parse("3.1.0")

View File

@ -11,3 +11,8 @@
- name: "{{ manage_pip_packages_pip3_package_name }}"
version: latest
state: present
- name: "Update pip to latest"
ansible.builtin.pip:
name: pip
extra_args: --upgrade