mirror of
https://gitlab.com/allianceauth/allianceauth.git
synced 2025-07-09 20:40:17 +02:00
[ADD] sentinel user and migrate fleetactivitytracking
This commit is contained in:
parent
3f47cecbfc
commit
6a990c11e6
@ -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
|
||||||
|
),
|
||||||
|
),
|
||||||
|
]
|
@ -3,10 +3,7 @@ from django.db import models
|
|||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
|
||||||
from allianceauth.eveonline.models import EveCharacter
|
from allianceauth.eveonline.models import EveCharacter
|
||||||
|
from allianceauth.framework.api.user import get_sentinel_user
|
||||||
|
|
||||||
def get_sentinel_user():
|
|
||||||
return User.objects.get_or_create(username='deleted')[0]
|
|
||||||
|
|
||||||
|
|
||||||
class Fatlink(models.Model):
|
class Fatlink(models.Model):
|
||||||
|
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")
|
Loading…
x
Reference in New Issue
Block a user