2022-06-04 08:41:53 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2024-01-15 20:20:10 +00:00
|
|
|
# type: ignore
|
|
|
|
from django.contrib.auth.models import User
|
|
|
|
from django.test import RequestFactory
|
|
|
|
|
2022-06-04 08:41:53 +00:00
|
|
|
from bthlabs_jsonrpc_django import auth_checks
|
|
|
|
|
|
|
|
|
2024-01-15 20:20:10 +00:00
|
|
|
def test_is_staff_regular_user(rf: RequestFactory, user: User):
|
2022-06-04 08:41:53 +00:00
|
|
|
# Given
|
|
|
|
request = rf.get('/')
|
|
|
|
request.user = user
|
|
|
|
|
|
|
|
# When
|
|
|
|
result = auth_checks.is_staff(request)
|
|
|
|
|
|
|
|
# Then
|
|
|
|
assert result is False
|
|
|
|
|
|
|
|
|
2024-01-15 20:20:10 +00:00
|
|
|
def test_is_staff_ok(rf: RequestFactory, staff_user: User):
|
2022-06-04 08:41:53 +00:00
|
|
|
# Given
|
|
|
|
request = rf.get('/')
|
|
|
|
request.user = staff_user
|
|
|
|
|
|
|
|
# When
|
|
|
|
result = auth_checks.is_staff(request)
|
|
|
|
|
|
|
|
# Then
|
|
|
|
assert result is True
|