aboutsummaryrefslogtreecommitdiffstats
path: root/ctrack/conftest.py
blob: c115b4eed88ee5d75a946070d2e7a824c8332137 (plain) (blame)
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import os

import pytest
from django.contrib.auth.models import Group, Permission
from django.db.models import Q
from django.test import RequestFactory
from selenium import webdriver
from selenium.webdriver.firefox.options import Options

from ctrack.organisations.models import (
    Address,
    AddressType,
    Mode,
    Organisation,
    Stakeholder,
    Submode,
)
from ctrack.organisations.tests.factories import (
    AddressFactory,
    OrganisationFactory,
    PersonFactory,
    RoleFactory,
)
from ctrack.users.models import User
from ctrack.users.tests.factories import UserFactory


@pytest.fixture(autouse=True)
def media_storage(settings, tmpdir):
    settings.MEDIA_ROOT = tmpdir.strpath


@pytest.fixture
def cct_user_group() -> Group:
    """
    TODO: An inspector will not require this many permissions! Reduce.
    """
    group = Group.objects.create(name="cct_user")
    ctrack_permissions = Permission.objects.filter(
        Q(codename__contains="address")
        | Q(codename__contains="addresstype")
        | Q(codename__contains="mode")
        | Q(codename__contains="organisation")
        | Q(codename__contains="role")
        | Q(codename__contains="submode")
        | Q(codename__contains="person")
        | Q(codename__contains="applicablesystem")
        | Q(codename__contains="caf")
        | Q(codename__contains="documentfile")
        | Q(codename__contains="filestore")
        | Q(codename__contains="grading")
        | Q(codename__contains="engagementtype")
        | Q(codename__contains="engagementevent")
        | Q(codename__contains="cafassessment")
        | Q(codename__contains="cafobjective")
        | Q(codename__contains="cafprinciple")
        | Q(codename__contains="cafcontributingoutcome")
        | Q(codename__contains="cafassessmentoutcomescore")
        | Q(codename__contains="achievmentlevel")
        | Q(codename__contains="igp")
        | Q(codename__contains="stakeholder")
        | Q(codename__contains="incidentreport")
    )
    group.permissions.add(*ctrack_permissions)
    return group


@pytest.fixture
def user() -> User:
    return UserFactory()


@pytest.fixture
def person(user):
    role = RoleFactory.create(name="Compliance Inspector")
    mode = Mode.objects.create(descriptor="Rail")
    submode = Submode.objects.create(descriptor="Light Rail", mode=mode)
    org = OrganisationFactory.create(submode=submode)
    person = PersonFactory.create(
        first_name="Toss",
        last_name="McBride",
        role=role,
        predecessor=None,
        organisation__submode=submode,
        organisation=org,
    )
    return person


@pytest.fixture
def org() -> Organisation:
    return OrganisationFactory()


@pytest.fixture
def addr() -> Address:
    address_type = AddressType.objects.create(descriptor="Random Type")
    return AddressFactory(type=address_type)


@pytest.fixture
def stakeholder_user(person):
    user = User.objects.create_user(username="toss", password="knob")
    stakeholder = Stakeholder.objects.create(person=person)
    user.stakeholder = stakeholder
    user.save()
    return user


@pytest.fixture
def request_factory() -> RequestFactory:
    return RequestFactory()


@pytest.fixture
def browser(request):
    "Provide selenium webdriver instance."
    os.environ["PATH"] += os.pathsep + os.getcwd()
    options = Options()
    options.headless = True
    browser_ = webdriver.Firefox(firefox_options=options)
    yield browser_
    browser_.quit()