File: test_uws.py

package info (click to toggle)
freedombox 26.2
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 82,976 kB
  • sloc: python: 48,504; javascript: 1,736; xml: 481; makefile: 290; sh: 167; php: 32
file content (31 lines) | stat: -rw-r--r-- 1,245 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# SPDX-License-Identifier: AGPL-3.0-or-later
"""
Test module for (U)ser (Web) (S)ites.
"""

from plinth.modules.apache import (user_of_uws_directory, user_of_uws_url,
                                   uws_directory_of_url, uws_directory_of_user,
                                   uws_url_of_directory, uws_url_of_user)


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')