Esempio n. 1
0
def test_homepage_mapping_skip_ci():
    """Special tests for homepage functions."""
    try:
        user = os.getlogin()
    except OSError:
        # See msg383161 in https://bugs.python.org/issue40821
        reason = "Needs access to ~/ directory. " \
               + "CI sandboxed workspace doesn't provide it."
        pytest.skip(reason)
    uws_directory = uws_directory_of_user(user)
    uws_url = uws_url_of_user(user)
    uws_scid = home_page_url2scid(uws_url)

    # Check test's precondition:
    if os.path.exists(uws_directory):
        # Don't blindly remove a pre-existing directory. Just skip the test.
        reason = "UWS directory {} exists already.".format(uws_directory)
        pytest.skip(reason)

    # AC: Return scid if UWS directory exists:
    try:
        os.mkdir(uws_directory)
    except Exception:
        reason = "Needs access to ~/ directory. " \
               + "CI sandboxed workspace doesn't provide it."
        pytest.skip(reason)
    assert _home_page_scid2url(uws_scid) == uws_url

    # AC: Return None if it doesn't:
    os.rmdir(uws_directory)
    assert _home_page_scid2url(uws_scid) is None
Esempio n. 2
0
def test_uws_namings():
    """Test name solvers for user, url and directory of UWS."""

    assert '/home/usr/public_html' == uws_directory_of_user('usr')
    assert '/~usr/' == uws_url_of_user('usr')

    f = user_of_uws_directory
    assert f('/home/usr/lacks/the/UWS/directory') is None
    assert 'usr' == f('/home/usr/public_html/is/a/normal/UWS/file')
    assert 'usr' == f('/home/usr/public_html/is/a/normal/UWS/path/')
    assert '€.;#@|' == f('/home/€.;#@|/public_html/is/stange/but/valid/')

    f = user_of_uws_url
    assert f('/usr/is/not/a/valid/UWS/url/due/to/missing/tilde') is None
    assert 'usr' == f('whatever/~usr/is/considered/a/valid/UWS/path')
    assert 'usr' == f('~usr')
    assert 'usr' == f('~usr/')
    assert 'usr' == f('/~usr/')

    assert '/home/usr/public_html' == uws_directory_of_url('~usr/any/file')
    assert '/~usr/' == uws_url_of_directory('/home/usr/public_html/any/file')
Esempio n. 3
0
def _home_page_scid2url(shortcut_id):
    """Returns the url for the given home page shortcut ID."""
    if shortcut_id is None:
        url = None
    elif shortcut_id == 'plinth':
        url = '/plinth/'
    elif shortcut_id == 'apache-default':
        url = '/index.html'
    elif shortcut_id.startswith('uws-'):
        user = shortcut_id[4:]
        if user in get_users_with_website():
            url = uws_url_of_user(user)
        else:
            url = None
    else:
        shortcuts = frontpage.Shortcut.list()
        aux = [
            shortcut.url for shortcut in shortcuts
            if shortcut_id == shortcut.component_id
        ]
        url = aux[0] if 1 == len(aux) else None

    return url
Esempio n. 4
0
def test_homepage_field():
    """Test homepage changes.

    Test Cases:
        1) FreedomBox Homepage (default),
        2) Apache default,
        3) A user's website of an...
        3.1) unexisting user
        3.2) existing user without a page
        3.3) existing user page.
        4) A FreedomBox App.
        4.1) unknown app
        4.2) uninstalled app
        4.3) disabled app
        4.4) enabled app

    Note: If run on a pristine unconfigured FreedomBox, this test will leave
          the homepage default-configured. (Imperfect cleanup in such case).

    Note: We take fbx as website user because of our testing container.

    Pending: - Specific test cases to distinguish 4.1,2,3.
               Currently they share the same test case.
             - Search for another valid user apart from fbx.
    """
    user = '******'
    uws_directory = uws_directory_of_user(user)
    uws_url = uws_url_of_user(user)
    uws_scid = home_page_url2scid(uws_url)

    default_home_page = 'plinth'
    original_home_page = get_home_page() or default_home_page

    # Check test's preconditions:
    if original_home_page not in (default_home_page, None):
        reason = "Unexpected home page {}.".format(original_home_page)
        pytest.skip(reason)

    if os.path.exists(uws_directory):
        # Don't blindly remove a pre-existing directory. Just skip the test.
        reason = "UWS directory {} exists already.".format(uws_directory)
        pytest.skip(reason)

    # AC: invalid changes fall back to default:
    for scid in ('uws-unexisting', uws_scid, 'missing_app'):
        change_home_page(scid)
        assert get_home_page() == default_home_page

    # AC: valid changes actually happen:
    try:
        os.mkdir(uws_directory)
    except Exception:
        reason = "Needs access to ~/ directory. " \
               + "CI sandboxed workspace doesn't provide it."
        pytest.skip(reason)
    for scid in ('b', 'a', uws_scid, 'apache-default', 'plinth'):
        change_home_page(scid)
        assert get_home_page() == scid

    # cleanup:
    change_home_page(original_home_page)
    os.rmdir(uws_directory)
    assert get_home_page() == original_home_page