Files @ 38c3569bdc6a
Branch filter:

Location: majic-ansible-roles/roles/wsgi_website/molecule/default/tests/test_parameters_mandatory.py

branko
MAR-151: Added support for Debian 10 Buster to wsgi_website role:

- Updated role reference documentaiton.
- Updated role meta information.
- Updated tests.
- Replace the installation of libmariadbclient-dev-compat library with
atftp - the actual package is differently named under Debian Stretch
and Debian Buster (which would complicate the test without any
benefits).
- Drop the fix for root mail alias in Vagrant image - seems it's no
longer a problem.
- Split-up the test for web application user since it's not possible
to keep it all under one parametrised test due to differences in
assigned system UID numbers for Debian Stretch and Debian Buster.
- Make the test for web application user less dependant on what the
actual UID number is in case of default value. By default user
should be created as system user, which means its UID number should
be less than 1000.
import os

import testinfra.utils.ansible_runner


testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
    os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('parameters-mandatory')


def test_index_page(host):
    """
    Tests if index page is served correctly. This covers:

    - Basic WSGI application operation.
    - Handling of environment variables.
    - Handling of proxy headers.
    """

    page = host.run('curl -H "Accept-Encoding: plain" https://parameters-mandatory/')

    assert page.rc == 0
    assert "This is the WSGI application at parameters-mandatory." in page.stdout
    assert "Requested URL was: https://parameters-mandatory/" in page.stdout
    assert "MY_ENV_VAR: None" in page.stdout
    assert "Accept-Encoding: plain" in page.stdout
    assert "Python version: 2." in page.stdout


def test_static_file_serving(host):
    """
    Tests serving of static files.
    """

    page = host.run('curl https://parameters-mandatory/static/static_file.txt')
    assert page.rc == 0
    assert "This is the WSGI application at parameters-mandatory." in page.stdout
    assert "Requested URL was: https://parameters-mandatory/static/static_file.txt" in page.stdout

    page = host.run('curl https://parameters-mandatory/media/media_file.txt')
    assert page.rc == 0
    assert "This is the WSGI application at parameters-mandatory." in page.stdout
    assert "Requested URL was: https://parameters-mandatory/media/media_file.txt" in page.stdout


def test_website_application_user(host):
    """
    Tests if website application user has been created correctly.
    """

    app_user = "web-parameters-mandatory"

    expected_group = "web-parameters-mandatory"
    expected_home = "/var/www/parameters-mandatory"

    user = host.user(app_user)

    assert user.exists
    assert user.uid < 1000
    assert user.group == expected_group
    assert user.groups == [expected_group]
    assert user.shell == '/bin/sh'
    assert user.home == expected_home

    with host.sudo():
        umask = host.run("su -l " + app_user + " -c 'bash -c umask'")
        assert umask.stdout == '0007\n'