blob: 528451802e63a69a5983d11153ccbe495eb4a163 (
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
|
"""
THE INITIATIVE FOR THIS TEST IS FROM REALPYTHON ARTICLE
https://realpython.com/Django-pytest-fixtures/
The permissions here are not optimal for this project yet.
TODO - make them so!
"""
import pytest
from django.contrib.auth import get_user_model
from django.contrib.auth.models import Group, Permission
@pytest.fixture
def user_A(db) -> Group:
group = Group.objects.create(name="cct_user")
change_user_permissions = Permission.objects.filter(
codename__in=["change_user", "view_user"],
)
group.permissions.add(*change_user_permissions)
user = get_user_model().objects.create_user("A")
user.groups.add(group)
return user
def test_there_is_a_cct_user_group(db): # adding fixture here
group = Group.objects.create(name="cct_user")
assert Group.objects.get(name="cct_user")
user = get_user_model().objects.create_user(
username="INSPECTOR", name="Mrs Inspector"
)
user.groups.add(group)
assert group in user.groups.all()
def test_user_fixture_has_access_to_all_ctrack_models(db, cct_user_group):
view_org_perm = Permission.objects.get(codename="view_organisation")
add_org_perm = Permission.objects.get(codename="add_organisation")
assert view_org_perm in cct_user_group.permissions.all()
assert add_org_perm in cct_user_group.permissions.all()
# def test_should_create_user(user_A: get_user_model()) -> None:
# assert user_A.username == "A"
# def test_user_is_in_app_user_group(user_A: get_user_model()) -> None:
# assert user_A.groups.filter(name="cct_user").exists()
|