[ADD] sentinel user and migrate fleetactivitytracking

This commit is contained in:
Peter Pfeufer 2023-11-03 18:06:32 +01:00
parent 3f47cecbfc
commit 6a990c11e6
No known key found for this signature in database
GPG Key ID: 6051D2C6AD4EBC27
4 changed files with 89 additions and 4 deletions

View File

@ -0,0 +1,26 @@
"""
Migration to AA Framework API method
"""
from django.conf import settings
from django.db import migrations, models
import allianceauth.framework.api.user
class Migration(migrations.Migration):
dependencies = [
("fleetactivitytracking", "0006_auto_20180803_0430"),
]
operations = [
migrations.AlterField(
model_name="fatlink",
name="creator",
field=models.ForeignKey(
on_delete=models.SET(allianceauth.framework.api.user.get_sentinel_user),
to=settings.AUTH_USER_MODEL
),
),
]

View File

@ -3,10 +3,7 @@ from django.db import models
from django.utils import timezone
from allianceauth.eveonline.models import EveCharacter
def get_sentinel_user():
return User.objects.get_or_create(username='deleted')[0]
from allianceauth.framework.api.user import get_sentinel_user
class Fatlink(models.Model):

View 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]

View 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")