Changeset - ae2e1055026c
[Not reviewed]
0 1 0
Branko Majic (branko) - 7 years ago 2018-11-25 12:13:31
branko@majic.rs
MAR-140: Update the expected packages in tests for WSGI website role.
1 file changed with 1 insertions and 1 deletions:
0 comments (0 inline, 0 general)
roles/wsgi_website/tests/test_parameters_optional.py
Show inline comments
 
@@ -157,193 +157,193 @@ def test_mail_forwarding(Command, File, Sudo):
 

	
 
    # Sleep for a couple of seconds so the mail can get delivered.
 
    time.sleep(5)
 

	
 
    with Sudo():
 
        mail_log = File('/var/log/mail.log')
 

	
 
        # First extract message ID of forwarded mail.
 
        pattern = "%s: to=<web-parameters-optional_local@localhost>.*status=sent \(forwarded as ([^)]*)\)" % message_id
 
        message_id = re.search(pattern, mail_log.content).group(1)
 

	
 
        # Now try to determine where the forward ended-up at.
 
        pattern = "%s: to=<user@wsgi-website>, orig_to=<web-parameters-optional_local@localhost>.*status=sent" % message_id
 
        assert re.search(pattern, mail_log.content) is not None
 

	
 

	
 
def test_installed_packages(Package):
 
    """
 
    Tests if additional packages are installed.
 
    """
 

	
 
    assert Package('libmariadb-client-lgpl-dev-compat').is_installed
 
    assert Package('global').is_installed
 

	
 

	
 
def test_mariadb_compat_symlink(File):
 
    """
 
    Tests if compatibility symlink is set-up for mysql_config binary if
 
    libmariadb-client-lgpl-dev-compat is installed.
 
    """
 

	
 
    link = File('/usr/bin/mysql_config')
 
    assert link.is_symlink
 
    assert link.linked_to == "/usr/bin/mariadb_config"
 

	
 

	
 
def test_python_virtualenv_created(File, Sudo):
 
    """
 
    Tests if Python virtual environment has been created correctly.
 
    """
 

	
 
    with Sudo():
 

	
 
        virtualenv = File("/var/www/parameters-optional.local/virtualenv")
 
        assert virtualenv.is_directory
 
        assert virtualenv.user == 'admin-parameters-optional_local'
 
        assert virtualenv.group == 'web-parameters-optional_local'
 
        assert virtualenv.mode == 0o2750
 

	
 
        virtualenv_activate = File("/var/www/parameters-optional.local/virtualenv/bin/activate")
 
        assert virtualenv_activate.is_file
 
        assert virtualenv_activate.user == 'admin-parameters-optional_local'
 
        assert virtualenv_activate.group == 'web-parameters-optional_local'
 
        assert virtualenv_activate.mode == 0o644
 

	
 

	
 
def test_python_virtualenv_project_directory_config(File, Sudo):
 
    """
 
    Tests if project directory configuration within virtualenv is set-up
 
    correctly.
 
    """
 

	
 
    with Sudo():
 

	
 
        project = File("/var/www/parameters-optional.local/virtualenv/.project")
 

	
 
        assert project.is_file
 
        assert project.user == 'admin-parameters-optional_local'
 
        assert project.group == 'web-parameters-optional_local'
 
        assert project.mode == 0o640
 

	
 

	
 
def test_python_virtualenv_wrapper_script(Command, File, Sudo):
 
    """
 
    Tests if Python virtualenv wrapper script is functioning correctly.
 
    """
 

	
 
    with Sudo():
 

	
 
        wrapper = File("/var/www/parameters-optional.local/virtualenv/bin/exec")
 
        assert wrapper.is_file
 
        assert wrapper.user == 'admin-parameters-optional_local'
 
        assert wrapper.group == 'web-parameters-optional_local'
 
        assert wrapper.mode == 0o750
 

	
 
        command = Command("sudo -u admin-parameters-optional_local /var/www/parameters-optional.local/virtualenv/bin/exec python -c 'import gunicorn'")
 
        assert command.rc == 0
 

	
 

	
 
def test_virtualenv_packages(Command):
 
    """
 
    Tests if correct packages are installed in virtualenv.
 
    """
 

	
 
    packages = Command("sudo -u admin-parameters-optional_local /var/www/parameters-optional.local/virtualenv/bin/pip freeze")
 

	
 
    assert sorted(packages.stdout.lower().split("\n")) == sorted("""Pygments==2.2.0
 
    assert sorted(packages.stdout.lower().split("\n")) == sorted("""Pygments==2.3.0
 
argparse==1.2.1
 
dnspython==1.15.0
 
docopt==0.6.2
 
futures==3.1.0
 
gunicorn==19.7.0
 
jedi==0.13.1
 
parso==0.3.1
 
prompt-toolkit==1.0.15
 
ptpython==0.41
 
six==1.11.0
 
wcwidth==0.1.7
 
wsgiref==0.1.2""".lower().split("\n"))
 

	
 

	
 
def test_wsgi_requirements_upgrade_checks(File, Sudo):
 
    """
 
    Tests if Python requirements files for upgrade checks are set-up correctly.
 
    """
 

	
 
    with Sudo():
 
        directory = File('/etc/pip_check_requirements_upgrades/parameters-optional.local')
 
        assert not directory.exists
 

	
 

	
 
def test_systemd_socket_configuration_file(File):
 
    """
 
    Tests if systemd socket configuration file has been set-up correctly.
 
    """
 

	
 
    config = File("/etc/systemd/system/parameters-optional.local.socket")
 
    assert config.is_file
 
    assert config.user == 'root'
 
    assert config.group == 'root'
 
    assert config.mode == 0o644
 
    assert "Socket for website parameters-optional.local" in config.content
 
    assert "ListenStream=/run/wsgi/parameters-optional.local.sock" in config.content
 

	
 

	
 
def test_systemd_socket(File, Socket, Sudo):
 
    """
 
    Tests if systemd socket has correct permissions and is available.
 
    """
 

	
 
    with Sudo():
 

	
 
        socket_file = File("/run/wsgi/parameters-optional.local.sock")
 
        assert socket_file.is_socket
 
        assert socket_file.user == 'www-data'
 
        assert socket_file.group == 'www-data'
 
        assert socket_file.mode == 0o660
 

	
 
        socket = Socket("unix:///run/wsgi/parameters-optional.local.sock")
 
        assert socket.is_listening
 

	
 

	
 
def test_systemd_service_configuration_file(File):
 
    """
 
    Tests if systemd service configuration file has been set-up correctly.
 
    """
 

	
 
    config = File("/etc/systemd/system/parameters-optional.local.service")
 
    assert config.is_file
 
    assert config.user == 'root'
 
    assert config.group == 'root'
 
    assert config.mode == 0o644
 
    assert "parameters-optional.local" in config.content
 

	
 

	
 
def test_systemd_service(Service):
 
    """
 
    Tests if the systemd service is enabled at boot and running.
 
    """
 

	
 
    service = Service('parameters-optional.local')
 

	
 
    assert service.is_enabled
 
    assert service.is_running
 

	
 

	
 
def test_static_file_directory(File, Sudo):
 
    """
 
    Tests if directory for serving static files has been created correctly.
 
    """
 

	
 
    with Sudo():
 

	
 
        directory = File('/var/www/parameters-optional.local/htdocs')
 
        assert directory.is_directory
 
        assert directory.user == 'admin-parameters-optional_local'
 
        assert directory.group == 'web-parameters-optional_local'
 
        assert directory.mode == 0o2750
 

	
 

	
 
def test_nginx_tls_files(File, Sudo):
 
    """
 
    Tests if TLS private key and certificate have been deployed correctly.
0 comments (0 inline, 0 general)