44 lines
941 B
Python
44 lines
941 B
Python
# -*- coding: utf-8 -*-
|
|
# type: ignore
|
|
from django.contrib.auth.models import AnonymousUser
|
|
from django.contrib.auth.models import User
|
|
from django.test import RequestFactory
|
|
|
|
from bthlabs_jsonrpc_django import auth_checks
|
|
|
|
|
|
def test_is_authenticated_anonymous_user(rf: RequestFactory):
|
|
# Given
|
|
request = rf.get('/')
|
|
request.user = AnonymousUser()
|
|
|
|
# When
|
|
result = auth_checks.is_authenticated(request)
|
|
|
|
# Then
|
|
assert result is False
|
|
|
|
|
|
def test_is_authenticated_inactive(rf: RequestFactory, inactive_user: User):
|
|
# Given
|
|
request = rf.get('/')
|
|
request.user = inactive_user
|
|
|
|
# When
|
|
result = auth_checks.is_authenticated(request)
|
|
|
|
# Then
|
|
assert result is False
|
|
|
|
|
|
def test_is_authenticated_ok(rf: RequestFactory, user: User):
|
|
# Given
|
|
request = rf.get('/')
|
|
request.user = user
|
|
|
|
# When
|
|
result = auth_checks.is_authenticated(request)
|
|
|
|
# Then
|
|
assert result is True
|