File: utils.py

package info (click to toggle)
django-menu-generator-ng 1.2.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 276 kB
  • sloc: python: 729; makefile: 17
file content (56 lines) | stat: -rwxr-xr-x 1,524 bytes parent folder | download
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
def is_user_happy(request):
    return request.user.is_auth and request.user.is_happy  # pragma: no cover


def is_paid_user(request):
    return request.user.is_auth and request.user.is_happy  # pragma: no cover


def is_main_site(request):
    """
    Non-User condition.
    """
    return True  # pragma: no covere


def validator_with_parameters(request, param1, param2):
    return True


class TestUser(object):
    """
    Test User Object.
    """
    is_auth = False
    is_staff = False
    is_superuser = False
    is_happy = False
    is_paid = False
    permissions = []

    def __init__(self, staff=False, superuser=False, authenticated=False, happy=False, paid=False):
        self.is_auth = authenticated
        self.is_staff = authenticated and staff
        self.is_superuser = authenticated and superuser
        self.is_happy = authenticated and happy
        self.is_paid = authenticated and paid
        self.permissions = []

    @property
    def is_authenticated(self):
        return self.is_auth

    def add_perm(self, permission):
        """
        Method for add a permission to test user
        :param permission: Permission to be added
        """
        self.permissions.append(permission)

    def has_perm(self, permission):
        """
        Method for checking if a test user has a permission
        :param permission: Permission to be checked
        :return: Boolean indicating if a test user has a permission or not
        """
        return permission in self.permissions