From 9fd6da1585c7ba6082370ab3ef021748962ecc20 Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Sat, 30 May 2020 17:24:18 +0100 Subject: started to think about Groups and added a test from real python article to play --- ctrack/users/tests/test_credentials.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 ctrack/users/tests/test_credentials.py (limited to 'ctrack/users') diff --git a/ctrack/users/tests/test_credentials.py b/ctrack/users/tests/test_credentials.py new file mode 100644 index 0000000..7538643 --- /dev/null +++ b/ctrack/users/tests/test_credentials.py @@ -0,0 +1,30 @@ +""" +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_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() -- cgit v1.2.3