2022-06-04 08:41:53 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2024-01-15 20:20:10 +00:00
|
|
|
# type: ignore
|
2022-06-04 08:41:53 +00:00
|
|
|
from django.contrib.auth.models import AnonymousUser
|
2024-01-15 20:20:10 +00:00
|
|
|
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_authenticated_anonymous_user(rf: RequestFactory):
|
2022-06-04 08:41:53 +00:00
|
|
|
# Given
|
|
|
|
request = rf.get('/')
|
|
|
|
request.user = AnonymousUser()
|
|
|
|
|
|
|
|
# When
|
|
|
|
result = auth_checks.is_authenticated(request)
|
|
|
|
|
|
|
|
# Then
|
|
|
|
assert result is False
|
|
|
|
|
|
|
|
|
2024-01-15 20:20:10 +00:00
|
|
|
def test_is_authenticated_inactive(rf: RequestFactory, inactive_user: User):
|
2022-06-04 08:41:53 +00:00
|
|
|
# Given
|
|
|
|
request = rf.get('/')
|
|
|
|
request.user = inactive_user
|
|
|
|
|
|
|
|
# When
|
|
|
|
result = auth_checks.is_authenticated(request)
|
|
|
|
|
|
|
|
# Then
|
|
|
|
assert result is False
|
|
|
|
|
|
|
|
|
2024-01-15 20:20:10 +00:00
|
|
|
def test_is_authenticated_ok(rf: RequestFactory, user: User):
|
2022-06-04 08:41:53 +00:00
|
|
|
# Given
|
|
|
|
request = rf.get('/')
|
|
|
|
request.user = user
|
|
|
|
|
|
|
|
# When
|
|
|
|
result = auth_checks.is_authenticated(request)
|
|
|
|
|
|
|
|
# Then
|
|
|
|
assert result is True
|