mirror of
https://gitlab.com/allianceauth/allianceauth.git
synced 2026-02-06 15:16:20 +01:00
[ADD] sentinel user and migrate fleetactivitytracking
This commit is contained in:
15
allianceauth/framework/api/user.py
Normal file
15
allianceauth/framework/api/user.py
Normal file
@@ -0,0 +1,15 @@
|
||||
"""
|
||||
Alliance Auth User API
|
||||
"""
|
||||
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
|
||||
def get_sentinel_user() -> User:
|
||||
"""
|
||||
Get the sentinel user or create one
|
||||
|
||||
:return:
|
||||
"""
|
||||
|
||||
return User.objects.get_or_create(username="deleted")[0]
|
||||
47
allianceauth/framework/tests/test_sentinel_user.py
Normal file
47
allianceauth/framework/tests/test_sentinel_user.py
Normal file
@@ -0,0 +1,47 @@
|
||||
"""
|
||||
Test sentinel user
|
||||
"""
|
||||
|
||||
# Django
|
||||
from django.contrib.auth.models import User
|
||||
from django.test import TestCase
|
||||
|
||||
# Alliance Auth
|
||||
from allianceauth.framework.api.user import get_sentinel_user
|
||||
|
||||
|
||||
class TestSentinelUser(TestCase):
|
||||
"""
|
||||
Tests for the sentinel user
|
||||
"""
|
||||
|
||||
def test_should_create_user_when_it_does_not_exist(self) -> None:
|
||||
"""
|
||||
Test should create a sentinel user when it doesn't exist
|
||||
|
||||
:return:
|
||||
:rtype:
|
||||
"""
|
||||
|
||||
# when
|
||||
user = get_sentinel_user()
|
||||
|
||||
# then
|
||||
self.assertEqual(first=user.username, second="deleted")
|
||||
|
||||
def test_should_return_user_when_it_does(self) -> None:
|
||||
"""
|
||||
Test should return sentinel user when it exists
|
||||
|
||||
:return:
|
||||
:rtype:
|
||||
"""
|
||||
|
||||
# given
|
||||
User.objects.create_user(username="deleted")
|
||||
|
||||
# when
|
||||
user = get_sentinel_user()
|
||||
|
||||
# then
|
||||
self.assertEqual(first=user.username, second="deleted")
|
||||
Reference in New Issue
Block a user