Files @ ff510f233909
Branch filter:

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

branko
MAR-132: Added support for Debian 9 (Stretch) to php_website role:

- Implemented the necessary changes related to differences between PHP
versions and related paths (PHP 5 vs PHP 7).
- Set the shell for application system account explicitly (workaround
for Debian bug 865762 in Stretch).
- Updated Molecule tests to cover Debian 9.
- Updated Molecule test preparation playbook to account for a number
of differences between Jessie and Stretch (mainly related to mailing
functionality).
- Use more specific host groups in tests.
- Renamed a couple of variables in test for sending out mails to make
it clearer what is being looked up as part of regex matching.
- Updated Molecule tests where certain paths depend on what Debian
release they are ran against.
- Split-up Jessie-specific tests into separate file.
import os

import testinfra.utils.ansible_runner


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


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

    with host.sudo():
        directory = host.file('/etc/pip_check_requirements_upgrades/parameters-paste-req')
        assert directory.is_directory
        assert directory.user == 'root'
        assert directory.group == 'pipreqcheck'
        assert directory.mode == 0o750

        config = host.file('/etc/pip_check_requirements_upgrades/parameters-paste-req/wsgi_requirements.in')
        assert config.is_file
        assert config.user == 'root'
        assert config.group == 'pipreqcheck'
        assert config.mode == 0o640
        assert config.content == "gunicorn\nfutures"

        config = host.file('/etc/pip_check_requirements_upgrades/parameters-paste-req/wsgi_requirements.txt')
        assert config.is_file
        assert config.user == 'root'
        assert config.group == 'pipreqcheck'
        assert config.mode == 0o640
        assert config.content == "futures==3.1.0\ngunicorn==19.7.0"


def test_gunicorn_requirements_installation_file(host):
    """
    Tests if requirements file for installing Gunicorn has been deployed
    correctly.
    """

    with host.sudo():

        requirements = host.file('/var/www/parameters-paste-req/.wsgi_requirements.txt')
        assert requirements.is_file
        assert requirements.user == 'admin-parameters-paste-req'
        assert requirements.group == 'web-parameters-paste-req'
        assert requirements.mode == 0o640
        assert requirements.content == "futures==3.1.0\ngunicorn==19.7.0"


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-paste-req/')

    assert page.rc == 0
    assert "This is the WSGI application at parameters-paste-req." in page.stdout
    assert "Requested URL was: https://parameters-paste-req/" 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-paste-req/static/static_file.txt')
    assert page.rc == 0
    assert "This is the WSGI application at parameters-paste-req." in page.stdout
    assert "Requested URL was: https://parameters-paste-req/static/static_file.txt" in page.stdout

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