mirror of
https://gitlab.com/allianceauth/allianceauth.git
synced 2026-02-12 01:56:25 +01:00
Merge branch 'v2.9.x' of https://gitlab.com/allianceauth/allianceauth
This commit is contained in:
@@ -6,18 +6,19 @@ from .providers import ObjectNotFound
|
||||
from .models import EveAllianceInfo
|
||||
from .models import EveCharacter
|
||||
from .models import EveCorporationInfo
|
||||
from .models import EveFactionInfo
|
||||
|
||||
|
||||
class EveEntityExistsError(forms.ValidationError):
|
||||
def __init__(self, entity_type_name, id):
|
||||
super(EveEntityExistsError, self).__init__(
|
||||
message='{} with ID {} already exists.'.format(entity_type_name, id))
|
||||
super().__init__(
|
||||
message=f'{entity_type_name} with ID {id} already exists.')
|
||||
|
||||
|
||||
class EveEntityNotFoundError(forms.ValidationError):
|
||||
def __init__(self, entity_type_name, id):
|
||||
super(EveEntityNotFoundError, self).__init__(
|
||||
message='{} with ID {} not found.'.format(entity_type_name, id))
|
||||
super().__init__(
|
||||
message=f'{entity_type_name} with ID {id} not found.')
|
||||
|
||||
|
||||
class EveEntityForm(forms.ModelForm):
|
||||
@@ -34,6 +35,38 @@ class EveEntityForm(forms.ModelForm):
|
||||
pass
|
||||
|
||||
|
||||
def get_faction_choices():
|
||||
# use a method to avoid making an ESI call when the app loads
|
||||
# restrict to only those factions a player can join for faction warfare
|
||||
player_factions = [x for x in EveFactionInfo.provider.get_all_factions() if x['militia_corporation_id']]
|
||||
return [(x['faction_id'], x['name']) for x in player_factions]
|
||||
|
||||
|
||||
|
||||
class EveFactionForm(EveEntityForm):
|
||||
id = forms.ChoiceField(
|
||||
choices=get_faction_choices,
|
||||
label="Name"
|
||||
)
|
||||
|
||||
def clean_id(self):
|
||||
try:
|
||||
assert self.Meta.model.provider.get_faction(self.cleaned_data['id'])
|
||||
except (AssertionError, ObjectNotFound):
|
||||
raise EveEntityNotFoundError('faction', self.cleaned_data['id'])
|
||||
if self.Meta.model.objects.filter(faction_id=self.cleaned_data['id']).exists():
|
||||
raise EveEntityExistsError('faction', self.cleaned_data['id'])
|
||||
return self.cleaned_data['id']
|
||||
|
||||
def save(self, commit=True):
|
||||
faction = self.Meta.model.provider.get_faction(self.cleaned_data['id'])
|
||||
return self.Meta.model.objects.create(faction_id=faction.id, faction_name=faction.name)
|
||||
|
||||
class Meta:
|
||||
fields = ['id']
|
||||
model = EveFactionInfo
|
||||
|
||||
|
||||
class EveCharacterForm(EveEntityForm):
|
||||
entity_type_name = 'character'
|
||||
|
||||
@@ -94,6 +127,21 @@ class EveAllianceForm(EveEntityForm):
|
||||
model = EveAllianceInfo
|
||||
|
||||
|
||||
@admin.register(EveFactionInfo)
|
||||
class EveFactionInfoAdmin(admin.ModelAdmin):
|
||||
search_fields = ['faction_name']
|
||||
list_display = ('faction_name',)
|
||||
ordering = ('faction_name',)
|
||||
|
||||
def has_change_permission(self, request, obj=None):
|
||||
return False
|
||||
|
||||
def get_form(self, request, obj=None, **kwargs):
|
||||
if not obj or not obj.pk:
|
||||
return EveFactionForm
|
||||
return super().get_form(request, obj=obj, **kwargs)
|
||||
|
||||
|
||||
@admin.register(EveCorporationInfo)
|
||||
class EveCorporationInfoAdmin(admin.ModelAdmin):
|
||||
search_fields = ['corporation_name']
|
||||
@@ -135,7 +183,7 @@ class EveCharacterAdmin(admin.ModelAdmin):
|
||||
'character_ownership__user__username'
|
||||
]
|
||||
list_display = (
|
||||
'character_name', 'corporation_name', 'alliance_name', 'user', 'main_character'
|
||||
'character_name', 'corporation_name', 'alliance_name', 'faction_name', 'user', 'main_character'
|
||||
)
|
||||
list_select_related = (
|
||||
'character_ownership', 'character_ownership__user__profile__main_character'
|
||||
@@ -143,6 +191,7 @@ class EveCharacterAdmin(admin.ModelAdmin):
|
||||
list_filter = (
|
||||
'corporation_name',
|
||||
'alliance_name',
|
||||
'faction_name',
|
||||
(
|
||||
'character_ownership__user__profile__main_character',
|
||||
admin.RelatedOnlyFieldListFilter
|
||||
@@ -170,4 +219,4 @@ class EveCharacterAdmin(admin.ModelAdmin):
|
||||
def get_form(self, request, obj=None, **kwargs):
|
||||
if not obj or not obj.pk:
|
||||
return EveCharacterForm
|
||||
return super(EveCharacterAdmin, self).get_form(request, obj=obj, **kwargs)
|
||||
return super().get_form(request, obj=obj, **kwargs)
|
||||
|
||||
@@ -10,7 +10,7 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
def sync_user_groups(modeladmin, request, queryset):
|
||||
for agc in queryset:
|
||||
logger.debug("update_all_states_group_membership for {}".format(agc))
|
||||
logger.debug(f"update_all_states_group_membership for {agc}")
|
||||
agc.update_all_states_group_membership()
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ class AutogroupsConfigAdmin(admin.ModelAdmin):
|
||||
return []
|
||||
|
||||
def get_actions(self, request):
|
||||
actions = super(AutogroupsConfigAdmin, self).get_actions(request)
|
||||
actions = super().get_actions(request)
|
||||
actions['sync_user_groups'] = (sync_user_groups,
|
||||
'sync_user_groups',
|
||||
'Sync all users groups for this Autogroup Config')
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
# Generated by Django 1.11.6 on 2017-12-23 04:30
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
@@ -26,7 +26,7 @@ class AutogroupsConfigManager(models.Manager):
|
||||
for config in self.filter(states=state):
|
||||
logger.debug("in state loop")
|
||||
for user in users:
|
||||
logger.debug("in user loop for {}".format(user))
|
||||
logger.debug(f"in user loop for {user}")
|
||||
config.update_group_membership_for_user(user)
|
||||
|
||||
def update_groups_for_user(self, user: User, state: State = None):
|
||||
@@ -81,7 +81,7 @@ class AutogroupsConfig(models.Model):
|
||||
objects = AutogroupsConfigManager()
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(AutogroupsConfig, self).__init__(*args, **kwargs)
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
def __repr__(self):
|
||||
return self.__class__.__name__
|
||||
@@ -111,24 +111,24 @@ class AutogroupsConfig(models.Model):
|
||||
group = None
|
||||
try:
|
||||
if not self.alliance_groups or not self.user_entitled_to_groups(user):
|
||||
logger.debug('User {} does not have required state for alliance group membership'.format(user))
|
||||
logger.debug(f'User {user} does not have required state for alliance group membership')
|
||||
return
|
||||
else:
|
||||
alliance = user.profile.main_character.alliance
|
||||
if alliance is None:
|
||||
logger.debug('User {} alliance is None, cannot update group membership'.format(user))
|
||||
logger.debug(f'User {user} alliance is None, cannot update group membership')
|
||||
return
|
||||
group = self.get_alliance_group(alliance)
|
||||
except EveAllianceInfo.DoesNotExist:
|
||||
logger.debug('User {} main characters alliance does not exist in the database. Creating.'.format(user))
|
||||
logger.debug(f'User {user} main characters alliance does not exist in the database. Creating.')
|
||||
alliance = EveAllianceInfo.objects.create_alliance(user.profile.main_character.alliance_id)
|
||||
group = self.get_alliance_group(alliance)
|
||||
except AttributeError:
|
||||
logger.warning('User {} does not have a main character. Group membership not updated'.format(user))
|
||||
logger.warning(f'User {user} does not have a main character. Group membership not updated')
|
||||
finally:
|
||||
self.remove_user_from_alliance_groups(user, except_group=group)
|
||||
if group is not None:
|
||||
logger.debug('Adding user {} to alliance group {}'.format(user, group))
|
||||
logger.debug(f'Adding user {user} to alliance group {group}')
|
||||
user.groups.add(group)
|
||||
|
||||
@transaction.atomic
|
||||
@@ -136,20 +136,20 @@ class AutogroupsConfig(models.Model):
|
||||
group = None
|
||||
try:
|
||||
if not self.corp_groups or not self.user_entitled_to_groups(user):
|
||||
logger.debug('User {} does not have required state for corp group membership'.format(user))
|
||||
logger.debug(f'User {user} does not have required state for corp group membership')
|
||||
else:
|
||||
corp = user.profile.main_character.corporation
|
||||
group = self.get_corp_group(corp)
|
||||
except EveCorporationInfo.DoesNotExist:
|
||||
logger.debug('User {} main characters corporation does not exist in the database. Creating.'.format(user))
|
||||
logger.debug(f'User {user} main characters corporation does not exist in the database. Creating.')
|
||||
corp = EveCorporationInfo.objects.create_corporation(user.profile.main_character.corporation_id)
|
||||
group = self.get_corp_group(corp)
|
||||
except AttributeError:
|
||||
logger.warning('User {} does not have a main character. Group membership not updated'.format(user))
|
||||
logger.warning(f'User {user} does not have a main character. Group membership not updated')
|
||||
finally:
|
||||
self.remove_user_from_corp_groups(user, except_group=group)
|
||||
if group is not None:
|
||||
logger.debug('Adding user {} to corp group {}'.format(user, group))
|
||||
logger.debug(f'Adding user {user} to corp group {group}')
|
||||
user.groups.add(group)
|
||||
|
||||
@transaction.atomic
|
||||
|
||||
@@ -15,7 +15,7 @@ def pre_save_config(sender, instance, *args, **kwargs):
|
||||
Checks if enable was toggled on group config and
|
||||
deletes groups if necessary.
|
||||
"""
|
||||
logger.debug("Received pre_save from {}".format(instance))
|
||||
logger.debug(f"Received pre_save from {instance}")
|
||||
if not instance.pk:
|
||||
# new model being created
|
||||
return
|
||||
|
||||
@@ -9,7 +9,7 @@ MODULE_PATH = 'allianceauth.eveonline.autogroups'
|
||||
|
||||
|
||||
def patch(target, *args, **kwargs):
|
||||
return mock.patch('{}{}'.format(MODULE_PATH, target), *args, **kwargs)
|
||||
return mock.patch(f'{MODULE_PATH}{target}', *args, **kwargs)
|
||||
|
||||
|
||||
def connect_signals():
|
||||
|
||||
@@ -56,15 +56,15 @@ def _eve_entity_image_url(
|
||||
tenants = ['tranquility', 'singularity']
|
||||
|
||||
if not entity_id:
|
||||
raise ValueError('Invalid entity_id: {}'.format(entity_id))
|
||||
raise ValueError(f'Invalid entity_id: {entity_id}')
|
||||
else:
|
||||
entity_id = int(entity_id)
|
||||
|
||||
if not size or size < 32 or size > 1024 or (size & (size - 1) != 0):
|
||||
raise ValueError('Invalid size: {}'.format(size))
|
||||
raise ValueError(f'Invalid size: {size}')
|
||||
|
||||
if category not in categories:
|
||||
raise ValueError('Invalid category {}'.format(category))
|
||||
raise ValueError(f'Invalid category {category}')
|
||||
else:
|
||||
endpoint = categories[category]['endpoint']
|
||||
|
||||
@@ -78,7 +78,7 @@ def _eve_entity_image_url(
|
||||
variant = categories[category]['variants'][0]
|
||||
|
||||
if tenant and tenant not in tenants:
|
||||
raise ValueError('Invalid tenant {}'.format(tenant))
|
||||
raise ValueError(f'Invalid tenant {tenant}')
|
||||
|
||||
# compose result URL
|
||||
result = '{}/{}/{}/{}?size={}'.format(
|
||||
@@ -89,7 +89,7 @@ def _eve_entity_image_url(
|
||||
size
|
||||
)
|
||||
if tenant:
|
||||
result += '&tenant={}'.format(tenant)
|
||||
result += f'&tenant={tenant}'
|
||||
|
||||
return result
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ def _build_url(category: str, eve_id: int) -> str:
|
||||
|
||||
url = urljoin(
|
||||
_BASE_URL,
|
||||
'{}/{}'.format(partial, int(eve_id))
|
||||
f'{partial}/{int(eve_id)}'
|
||||
)
|
||||
return url
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ def _build_url(category: str, eve_id: int) -> str:
|
||||
|
||||
url = urljoin(
|
||||
_BASE_URL,
|
||||
'{}/{}/'.format(partial, int(eve_id))
|
||||
f'{partial}/{int(eve_id)}/'
|
||||
)
|
||||
return url
|
||||
|
||||
|
||||
@@ -27,6 +27,8 @@ class EveCharacterManager(models.Manager):
|
||||
alliance_id=character.alliance.id,
|
||||
alliance_name=character.alliance.name,
|
||||
alliance_ticker=getattr(character.alliance, 'ticker', None),
|
||||
faction_id=character.faction.id,
|
||||
faction_name=character.faction.name
|
||||
)
|
||||
|
||||
def update_character(self, character_id):
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
# Generated by Django 1.10.1 on 2016-09-05 21:39
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
# Generated by Django 1.10.1 on 2016-09-10 20:20
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
# Generated by Django 1.10.2 on 2016-10-26 01:49
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
# Generated by Django 1.10.2 on 2016-11-01 04:20
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
# Generated by Django 1.10.1 on 2016-12-16 23:22
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
# Generated by Django 1.10.1 on 2017-01-02 19:23
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
# Generated by Django 1.10.5 on 2017-01-18 13:20
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
def get_duplicates(items):
|
||||
return set([item for item in items if items.count(item) > 1])
|
||||
return {item for item in items if items.count(item) > 1}
|
||||
|
||||
|
||||
def enforce_unique_characters(apps, schema_editor):
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
# Generated by Django 1.10.5 on 2017-03-22 23:09
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
# Generated by Django 1.11.5 on 2017-09-28 02:16
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
35
allianceauth/eveonline/migrations/0015_factions.py
Normal file
35
allianceauth/eveonline/migrations/0015_factions.py
Normal file
@@ -0,0 +1,35 @@
|
||||
# Generated by Django 3.1.13 on 2021-10-12 01:04
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('eveonline', '0014_auto_20210105_1413'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='EveFactionInfo',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('faction_id', models.PositiveIntegerField(db_index=True, unique=True)),
|
||||
('faction_name', models.CharField(max_length=254, unique=True)),
|
||||
],
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='evecharacter',
|
||||
name='faction_id',
|
||||
field=models.PositiveIntegerField(blank=True, default=None, null=True),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='evecharacter',
|
||||
name='faction_name',
|
||||
field=models.CharField(blank=True, default='', max_length=254, null=True),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name='evecharacter',
|
||||
index=models.Index(fields=['faction_id'], name='eveonline_e_faction_d5274e_idx'),
|
||||
),
|
||||
]
|
||||
@@ -10,6 +10,47 @@ from .evelinks import eveimageserver
|
||||
_DEFAULT_IMAGE_SIZE = 32
|
||||
|
||||
|
||||
class EveFactionInfo(models.Model):
|
||||
faction_id = models.PositiveIntegerField(unique=True, db_index=True)
|
||||
faction_name = models.CharField(max_length=254, unique=True)
|
||||
|
||||
provider = providers.provider
|
||||
|
||||
def __str__(self):
|
||||
return self.faction_name
|
||||
|
||||
@staticmethod
|
||||
def generic_logo_url(
|
||||
faction_id: int, size: int = _DEFAULT_IMAGE_SIZE
|
||||
) -> str:
|
||||
"""image URL for the given faction ID"""
|
||||
return eveimageserver.corporation_logo_url(faction_id, size)
|
||||
|
||||
def logo_url(self, size: int = _DEFAULT_IMAGE_SIZE) -> str:
|
||||
"""image URL of this faction"""
|
||||
return self.generic_logo_url(self.faction_id, size)
|
||||
|
||||
@property
|
||||
def logo_url_32(self) -> str:
|
||||
"""image URL for this faction"""
|
||||
return self.logo_url(32)
|
||||
|
||||
@property
|
||||
def logo_url_64(self) -> str:
|
||||
"""image URL for this faction"""
|
||||
return self.logo_url(64)
|
||||
|
||||
@property
|
||||
def logo_url_128(self) -> str:
|
||||
"""image URL for this faction"""
|
||||
return self.logo_url(128)
|
||||
|
||||
@property
|
||||
def logo_url_256(self) -> str:
|
||||
"""image URL for this faction"""
|
||||
return self.logo_url(256)
|
||||
|
||||
|
||||
class EveAllianceInfo(models.Model):
|
||||
alliance_id = models.PositiveIntegerField(unique=True)
|
||||
alliance_name = models.CharField(max_length=254, unique=True)
|
||||
@@ -149,17 +190,20 @@ class EveCharacter(models.Model):
|
||||
alliance_id = models.PositiveIntegerField(blank=True, null=True, default=None)
|
||||
alliance_name = models.CharField(max_length=254, blank=True, null=True, default='')
|
||||
alliance_ticker = models.CharField(max_length=5, blank=True, null=True, default='')
|
||||
faction_id = models.PositiveIntegerField(blank=True, null=True, default=None)
|
||||
faction_name = models.CharField(max_length=254, blank=True, null=True, default='')
|
||||
|
||||
objects = EveCharacterManager()
|
||||
provider = EveCharacterProviderManager()
|
||||
|
||||
class Meta:
|
||||
indexes = [
|
||||
models.Index(fields=['corporation_id',]),
|
||||
models.Index(fields=['alliance_id',]),
|
||||
models.Index(fields=['corporation_name',]),
|
||||
models.Index(fields=['alliance_name',]),
|
||||
]
|
||||
models.Index(fields=['corporation_id',]),
|
||||
models.Index(fields=['alliance_id',]),
|
||||
models.Index(fields=['corporation_name',]),
|
||||
models.Index(fields=['alliance_name',]),
|
||||
models.Index(fields=['faction_id',]),
|
||||
]
|
||||
|
||||
@property
|
||||
def alliance(self) -> Union[EveAllianceInfo, None]:
|
||||
@@ -181,6 +225,17 @@ class EveCharacter(models.Model):
|
||||
"""
|
||||
return EveCorporationInfo.objects.get(corporation_id=self.corporation_id)
|
||||
|
||||
@property
|
||||
def faction(self) -> Union[EveFactionInfo, None]:
|
||||
"""
|
||||
Pseudo foreign key from faction_id to EveFactionInfo
|
||||
:raises: EveFactionInfo.DoesNotExist
|
||||
:return: EveFactionInfo
|
||||
"""
|
||||
if self.faction_id is None:
|
||||
return None
|
||||
return EveFactionInfo.objects.get(faction_id=self.faction_id)
|
||||
|
||||
def update_character(self, character: providers.Character = None):
|
||||
if character is None:
|
||||
character = self.provider.get_character(self.character_id)
|
||||
@@ -191,6 +246,8 @@ class EveCharacter(models.Model):
|
||||
self.alliance_id = character.alliance.id
|
||||
self.alliance_name = character.alliance.name
|
||||
self.alliance_ticker = getattr(character.alliance, 'ticker', None)
|
||||
self.faction_id = character.faction.id
|
||||
self.faction_name = character.faction.name
|
||||
self.save()
|
||||
return self
|
||||
|
||||
@@ -278,3 +335,31 @@ class EveCharacter(models.Model):
|
||||
def alliance_logo_url_256(self) -> str:
|
||||
"""image URL for alliance of this character or empty string"""
|
||||
return self.alliance_logo_url(256)
|
||||
|
||||
|
||||
def faction_logo_url(self, size=_DEFAULT_IMAGE_SIZE) -> str:
|
||||
"""image URL for alliance of this character or empty string"""
|
||||
if self.faction_id:
|
||||
return EveFactionInfo.generic_logo_url(self.faction_id, size)
|
||||
else:
|
||||
return ''
|
||||
|
||||
@property
|
||||
def faction_logo_url_32(self) -> str:
|
||||
"""image URL for alliance of this character or empty string"""
|
||||
return self.faction_logo_url(32)
|
||||
|
||||
@property
|
||||
def faction_logo_url_64(self) -> str:
|
||||
"""image URL for alliance of this character or empty string"""
|
||||
return self.faction_logo_url(64)
|
||||
|
||||
@property
|
||||
def faction_logo_url_128(self) -> str:
|
||||
"""image URL for alliance of this character or empty string"""
|
||||
return self.faction_logo_url(128)
|
||||
|
||||
@property
|
||||
def faction_logo_url_256(self) -> str:
|
||||
"""image URL for alliance of this character or empty string"""
|
||||
return self.faction_logo_url(256)
|
||||
|
||||
@@ -22,6 +22,7 @@ get_corporations_corporation_id
|
||||
get_characters_character_id
|
||||
get_universe_types_type_id
|
||||
post_character_affiliation
|
||||
get_universe_factions
|
||||
"""
|
||||
|
||||
|
||||
@@ -34,11 +35,12 @@ class ObjectNotFound(Exception):
|
||||
self.type = type_name
|
||||
|
||||
def __str__(self):
|
||||
return '%s with ID %s not found.' % (self.type, self.id)
|
||||
return f'{self.type} with ID {self.id} not found.'
|
||||
|
||||
|
||||
class Entity(object):
|
||||
def __init__(self, id=None, name=None):
|
||||
class Entity:
|
||||
def __init__(self, id=None, name=None, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
self.id = id
|
||||
self.name = name
|
||||
|
||||
@@ -46,7 +48,7 @@ class Entity(object):
|
||||
return self.name
|
||||
|
||||
def __repr__(self):
|
||||
return "<{} ({}): {}>".format(self.__class__.__name__, self.id, self.name)
|
||||
return f"<{self.__class__.__name__} ({self.id}): {self.name}>"
|
||||
|
||||
def __bool__(self):
|
||||
return bool(self.id)
|
||||
@@ -55,15 +57,11 @@ class Entity(object):
|
||||
return self.id == other.id
|
||||
|
||||
|
||||
class Corporation(Entity):
|
||||
def __init__(self, ticker=None, ceo_id=None, members=None, alliance_id=None, **kwargs):
|
||||
super(Corporation, self).__init__(**kwargs)
|
||||
self.ticker = ticker
|
||||
self.ceo_id = ceo_id
|
||||
self.members = members
|
||||
class AllianceMixin:
|
||||
def __init__(self, alliance_id=None, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
self.alliance_id = alliance_id
|
||||
self._alliance = None
|
||||
self._ceo = None
|
||||
|
||||
@property
|
||||
def alliance(self):
|
||||
@@ -73,6 +71,30 @@ class Corporation(Entity):
|
||||
return self._alliance
|
||||
return Entity(None, None)
|
||||
|
||||
|
||||
class FactionMixin:
|
||||
def __init__(self, faction_id=None, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
self.faction_id = faction_id
|
||||
self._faction = None
|
||||
|
||||
@property
|
||||
def faction(self):
|
||||
if self.faction_id:
|
||||
if not self._faction:
|
||||
self._faction = provider.get_faction(self.faction_id)
|
||||
return self._faction
|
||||
return Entity(None, None)
|
||||
|
||||
|
||||
class Corporation(Entity, AllianceMixin, FactionMixin):
|
||||
def __init__(self, ticker=None, ceo_id=None, members=None, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
self.ticker = ticker
|
||||
self.ceo_id = ceo_id
|
||||
self.members = members
|
||||
self._ceo = None
|
||||
|
||||
@property
|
||||
def ceo(self):
|
||||
if not self._ceo:
|
||||
@@ -80,9 +102,9 @@ class Corporation(Entity):
|
||||
return self._ceo
|
||||
|
||||
|
||||
class Alliance(Entity):
|
||||
class Alliance(Entity, FactionMixin):
|
||||
def __init__(self, ticker=None, corp_ids=None, executor_corp_id=None, **kwargs):
|
||||
super(Alliance, self).__init__(**kwargs)
|
||||
super().__init__(**kwargs)
|
||||
self.ticker = ticker
|
||||
self.corp_ids = corp_ids
|
||||
self.executor_corp_id = executor_corp_id
|
||||
@@ -97,7 +119,7 @@ class Alliance(Entity):
|
||||
|
||||
@property
|
||||
def corps(self):
|
||||
return sorted([self.corp(c_id) for c_id in self.corp_ids], key=lambda x: x.name)
|
||||
return sorted((self.corp(c_id) for c_id in self.corp_ids), key=lambda x: x.name)
|
||||
|
||||
@property
|
||||
def executor_corp(self):
|
||||
@@ -106,13 +128,11 @@ class Alliance(Entity):
|
||||
return Entity(None, None)
|
||||
|
||||
|
||||
class Character(Entity):
|
||||
def __init__(self, corp_id=None, alliance_id=None, **kwargs):
|
||||
super(Character, self).__init__(**kwargs)
|
||||
class Character(Entity, AllianceMixin, FactionMixin):
|
||||
def __init__(self, corp_id=None, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
self.corp_id = corp_id
|
||||
self.alliance_id = alliance_id
|
||||
self._corp = None
|
||||
self._alliance = None
|
||||
|
||||
@property
|
||||
def corp(self):
|
||||
@@ -120,19 +140,13 @@ class Character(Entity):
|
||||
self._corp = provider.get_corp(self.corp_id)
|
||||
return self._corp
|
||||
|
||||
@property
|
||||
def alliance(self):
|
||||
if self.alliance_id:
|
||||
return self.corp.alliance
|
||||
return Entity(None, None)
|
||||
|
||||
|
||||
class ItemType(Entity):
|
||||
def __init__(self, **kwargs):
|
||||
super(ItemType, self).__init__(**kwargs)
|
||||
super().__init__(**kwargs)
|
||||
|
||||
|
||||
class EveProvider(object):
|
||||
class EveProvider:
|
||||
def get_alliance(self, alliance_id):
|
||||
"""
|
||||
:return: an Alliance object for the given ID
|
||||
@@ -179,6 +193,7 @@ class EveSwaggerProvider(EveProvider):
|
||||
|
||||
self._token = token
|
||||
self.adapter = adapter or self
|
||||
self._faction_list = None # what are the odds this will change? could cache forever!
|
||||
|
||||
@property
|
||||
def client(self):
|
||||
@@ -201,6 +216,7 @@ class EveSwaggerProvider(EveProvider):
|
||||
ticker=data['ticker'],
|
||||
corp_ids=corps,
|
||||
executor_corp_id=data['executor_corporation_id'] if 'executor_corporation_id' in data else None,
|
||||
faction_id=data['faction_id'] if 'faction_id' in data else None,
|
||||
)
|
||||
return model
|
||||
except HTTPNotFound:
|
||||
@@ -216,6 +232,7 @@ class EveSwaggerProvider(EveProvider):
|
||||
ceo_id=data['ceo_id'],
|
||||
members=data['member_count'],
|
||||
alliance_id=data['alliance_id'] if 'alliance_id' in data else None,
|
||||
faction_id=data['faction_id'] if 'faction_id' in data else None,
|
||||
)
|
||||
return model
|
||||
except HTTPNotFound:
|
||||
@@ -231,11 +248,30 @@ class EveSwaggerProvider(EveProvider):
|
||||
name=data['name'],
|
||||
corp_id=affiliation['corporation_id'],
|
||||
alliance_id=affiliation['alliance_id'] if 'alliance_id' in affiliation else None,
|
||||
faction_id=affiliation['faction_id'] if 'faction_id' in affiliation else None,
|
||||
)
|
||||
return model
|
||||
except (HTTPNotFound, HTTPUnprocessableEntity):
|
||||
raise ObjectNotFound(character_id, 'character')
|
||||
|
||||
def get_all_factions(self):
|
||||
if not self._faction_list:
|
||||
self._faction_list = self.client.Universe.get_universe_factions().result()
|
||||
return self._faction_list
|
||||
|
||||
def get_faction(self, faction_id):
|
||||
faction_id=int(faction_id)
|
||||
try:
|
||||
if not self._faction_list:
|
||||
_ = self.get_all_factions()
|
||||
for f in self._faction_list:
|
||||
if f['faction_id'] == faction_id:
|
||||
return Entity(id=f['faction_id'], name=f['name'])
|
||||
else:
|
||||
raise KeyError()
|
||||
except (HTTPNotFound, HTTPUnprocessableEntity, KeyError):
|
||||
raise ObjectNotFound(faction_id, 'faction')
|
||||
|
||||
def get_itemtype(self, type_id):
|
||||
try:
|
||||
data = self.client.Universe.get_universe_types_type_id(type_id=type_id).result()
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -67,7 +67,7 @@ def update_character_chunk(character_ids_chunk: list):
|
||||
character_names = providers.provider.client.Universe\
|
||||
.post_universe_names(ids=character_ids_chunk).result()
|
||||
except:
|
||||
logger.error("Failed to bulk update characters. Attempting single updates")
|
||||
logger.info("Failed to bulk update characters. Attempting single updates")
|
||||
for character_id in character_ids_chunk:
|
||||
update_character.apply_async(
|
||||
args=[character_id], priority=TASK_PRIORITY
|
||||
|
||||
@@ -18,7 +18,7 @@ def set_logger(logger_name: str, name: str) -> object:
|
||||
'%(asctime)s - %(levelname)s - %(module)s:%(funcName)s - %(message)s'
|
||||
)
|
||||
f_handler = logging.FileHandler(
|
||||
'{}.log'.format(os.path.splitext(name)[0]),
|
||||
f'{os.path.splitext(name)[0]}.log',
|
||||
'w+'
|
||||
)
|
||||
f_handler.setFormatter(f_format)
|
||||
|
||||
@@ -3,7 +3,7 @@ from unittest.mock import Mock, patch
|
||||
from django.test import TestCase
|
||||
|
||||
from ..models import (
|
||||
EveCharacter, EveCorporationInfo, EveAllianceInfo
|
||||
EveCharacter, EveCorporationInfo, EveAllianceInfo, EveFactionInfo
|
||||
)
|
||||
from ..providers import Alliance, Corporation, Character
|
||||
from ..evelinks import eveimageserver
|
||||
@@ -126,6 +126,66 @@ class EveCharacterTestCase(TestCase):
|
||||
|
||||
self.assertIsNone(character.alliance)
|
||||
|
||||
def test_faction_prop(self):
|
||||
"""
|
||||
Test that the correct faction is returned by the alliance property
|
||||
"""
|
||||
character = EveCharacter.objects.create(
|
||||
character_id=1234,
|
||||
character_name='character.name',
|
||||
corporation_id=2345,
|
||||
corporation_name='character.corp.name',
|
||||
corporation_ticker='cc1',
|
||||
alliance_id=3456,
|
||||
alliance_name='character.alliance.name',
|
||||
faction_id=1337,
|
||||
faction_name='character.faction.name'
|
||||
)
|
||||
|
||||
expected = EveFactionInfo.objects.create(faction_id=1337, faction_name='faction.name')
|
||||
incorrect = EveFactionInfo.objects.create(faction_id=8008, faction_name='faction.badname')
|
||||
|
||||
self.assertEqual(character.faction, expected)
|
||||
self.assertNotEqual(character.faction, incorrect)
|
||||
|
||||
def test_faction_prop_exception(self):
|
||||
"""
|
||||
Check that an exception is raised when the expected
|
||||
object is not in the database
|
||||
"""
|
||||
character = EveCharacter.objects.create(
|
||||
character_id=1234,
|
||||
character_name='character.name',
|
||||
corporation_id=2345,
|
||||
corporation_name='character.corp.name',
|
||||
corporation_ticker='cc1',
|
||||
alliance_id=3456,
|
||||
alliance_name='character.alliance.name',
|
||||
faction_id=1337,
|
||||
faction_name='character.faction.name'
|
||||
)
|
||||
|
||||
with self.assertRaises(EveFactionInfo.DoesNotExist):
|
||||
character.faction
|
||||
|
||||
def test_faction_prop_none(self):
|
||||
"""
|
||||
Check that None is returned when the character has no alliance
|
||||
"""
|
||||
character = EveCharacter.objects.create(
|
||||
character_id=1234,
|
||||
character_name='character.name',
|
||||
corporation_id=2345,
|
||||
corporation_name='character.corp.name',
|
||||
corporation_ticker='cc1',
|
||||
alliance_id=None,
|
||||
alliance_name=None,
|
||||
faction_id=None,
|
||||
faction_name=None,
|
||||
)
|
||||
|
||||
self.assertIsNone(character.faction)
|
||||
|
||||
@patch('allianceauth.eveonline.providers.provider')
|
||||
def test_update_character(self, mock_provider):
|
||||
mock_provider.get_corp.return_value = Corporation(
|
||||
@@ -144,13 +204,17 @@ class EveCharacterTestCase(TestCase):
|
||||
corporation_ticker='DC1',
|
||||
alliance_id=3001,
|
||||
alliance_name='Dummy Alliance 1',
|
||||
faction_id=1337,
|
||||
faction_name='Dummy Faction 1',
|
||||
)
|
||||
my_updated_character = Character(
|
||||
name='Bruce X. Wayne',
|
||||
corp_id=2002
|
||||
corp_id=2002,
|
||||
faction_id=None,
|
||||
)
|
||||
my_character.update_character(my_updated_character)
|
||||
self.assertEqual(my_character.character_name, 'Bruce X. Wayne')
|
||||
self.assertFalse(my_character.faction_id)
|
||||
|
||||
# todo: add test cases not yet covered, e.g. with alliance
|
||||
|
||||
|
||||
@@ -10,6 +10,8 @@ from . import set_logger
|
||||
from ..providers import (
|
||||
ObjectNotFound,
|
||||
Entity,
|
||||
AllianceMixin,
|
||||
FactionMixin,
|
||||
Character,
|
||||
Corporation,
|
||||
Alliance,
|
||||
@@ -18,7 +20,6 @@ from ..providers import (
|
||||
EveSwaggerProvider
|
||||
)
|
||||
|
||||
|
||||
MODULE_PATH = 'allianceauth.eveonline.providers'
|
||||
SWAGGER_OLD_SPEC_PATH = os.path.join(os.path.dirname(
|
||||
os.path.abspath(__file__)), 'swagger_old.json'
|
||||
@@ -80,6 +81,72 @@ class TestEntity(TestCase):
|
||||
# bug: missing _neq_ in Equity to compliment _eq_
|
||||
|
||||
|
||||
class TestAllianceMixin(TestCase):
|
||||
@patch(MODULE_PATH + '.EveSwaggerProvider.get_alliance')
|
||||
def test_alliance_defined(self, mock_provider_get_alliance):
|
||||
my_alliance = Alliance(
|
||||
id=3001,
|
||||
name='Dummy Alliance',
|
||||
ticker='Dummy',
|
||||
corp_ids=[2001, 2002, 2003],
|
||||
executor_corp_id=2001
|
||||
)
|
||||
mock_provider_get_alliance.return_value = my_alliance
|
||||
|
||||
x = AllianceMixin(alliance_id=3001)
|
||||
self.assertEqual(
|
||||
x.alliance,
|
||||
my_alliance
|
||||
)
|
||||
self.assertEqual(
|
||||
x.alliance,
|
||||
my_alliance
|
||||
)
|
||||
# should fetch alliance once only
|
||||
self.assertEqual(mock_provider_get_alliance.call_count, 1)
|
||||
|
||||
@patch(MODULE_PATH + '.EveSwaggerProvider.get_alliance')
|
||||
def test_alliance_not_defined(self, mock_provider_get_alliance):
|
||||
mock_provider_get_alliance.return_value = None
|
||||
|
||||
x = AllianceMixin()
|
||||
self.assertEqual(
|
||||
x.alliance,
|
||||
Entity(None, None)
|
||||
)
|
||||
self.assertEqual(mock_provider_get_alliance.call_count, 0)
|
||||
|
||||
|
||||
class TestFactionMixin(TestCase):
|
||||
@patch(MODULE_PATH + '.EveSwaggerProvider.get_faction')
|
||||
def test_faction_defined(self, mock_provider_get_faction):
|
||||
my_faction = Entity(id=1337, name='Permabanned')
|
||||
mock_provider_get_faction.return_value = my_faction
|
||||
|
||||
x = FactionMixin(faction_id=3001)
|
||||
self.assertEqual(
|
||||
x.faction,
|
||||
my_faction
|
||||
)
|
||||
self.assertEqual(
|
||||
x.faction,
|
||||
my_faction
|
||||
)
|
||||
# should fetch alliance once only
|
||||
self.assertEqual(mock_provider_get_faction.call_count, 1)
|
||||
|
||||
@patch(MODULE_PATH + '.EveSwaggerProvider.get_alliance')
|
||||
def test_faction_not_defined(self, mock_provider_get_faction):
|
||||
mock_provider_get_faction.return_value = None
|
||||
|
||||
x = FactionMixin()
|
||||
self.assertEqual(
|
||||
x.faction,
|
||||
Entity(None, None)
|
||||
)
|
||||
self.assertEqual(mock_provider_get_faction.call_count, 0)
|
||||
|
||||
|
||||
class TestCorporation(TestCase):
|
||||
|
||||
@patch(MODULE_PATH + '.EveSwaggerProvider.get_alliance')
|
||||
@@ -114,6 +181,7 @@ class TestCorporation(TestCase):
|
||||
x.alliance,
|
||||
Entity(None, None)
|
||||
)
|
||||
self.assertEqual(mock_provider_get_alliance.call_count, 0)
|
||||
|
||||
@patch(MODULE_PATH + '.EveSwaggerProvider.get_character')
|
||||
def test_ceo(self, mock_provider_get_character):
|
||||
@@ -142,6 +210,26 @@ class TestCorporation(TestCase):
|
||||
|
||||
# bug in ceo(): will try to fetch character even if ceo_id is None
|
||||
|
||||
@patch(MODULE_PATH + '.EveSwaggerProvider.get_faction')
|
||||
def test_faction_defined(self, mock_provider_get_faction):
|
||||
my_faction = Entity(id=1337, name='Permabanned')
|
||||
mock_provider_get_faction.return_value = my_faction
|
||||
|
||||
# fetch from provider if not defined
|
||||
x = Corporation(faction_id=1337)
|
||||
self.assertEqual(x.faction, my_faction)
|
||||
|
||||
# return existing if defined
|
||||
mock_provider_get_faction.return_value = None
|
||||
self.assertEqual(x.faction, my_faction)
|
||||
self.assertEqual(mock_provider_get_faction.call_count, 1)
|
||||
|
||||
@patch(MODULE_PATH + '.EveSwaggerProvider.get_faction')
|
||||
def test_faction_undefined(self, mock_provider_get_faction):
|
||||
x = Corporation()
|
||||
self.assertEqual(x.faction, Entity())
|
||||
self.assertEqual(mock_provider_get_faction.call_count, 0)
|
||||
|
||||
|
||||
class TestAlliance(TestCase):
|
||||
|
||||
@@ -151,7 +239,8 @@ class TestAlliance(TestCase):
|
||||
name='Dummy Alliance',
|
||||
ticker='Dummy',
|
||||
corp_ids=[2001, 2002, 2003],
|
||||
executor_corp_id=2001
|
||||
executor_corp_id=2001,
|
||||
faction_id=1337
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
@@ -232,6 +321,25 @@ class TestAlliance(TestCase):
|
||||
Entity(None, None),
|
||||
)
|
||||
|
||||
@patch(MODULE_PATH + '.EveSwaggerProvider.get_faction')
|
||||
def test_faction_defined(self, mock_provider_get_faction):
|
||||
my_faction = Entity(id=1337, name='Permabanned')
|
||||
mock_provider_get_faction.return_value = my_faction
|
||||
|
||||
# fetch from provider if not defined
|
||||
self.assertEqual(self.my_alliance.faction, my_faction)
|
||||
|
||||
# return existing if defined
|
||||
mock_provider_get_faction.return_value = None
|
||||
self.assertEqual(self.my_alliance.faction, my_faction)
|
||||
self.assertEqual(mock_provider_get_faction.call_count, 1)
|
||||
|
||||
@patch(MODULE_PATH + '.EveSwaggerProvider.get_faction')
|
||||
def test_faction_undefined(self, mock_provider_get_faction):
|
||||
self.my_alliance.faction_id = None
|
||||
self.assertEqual(self.my_alliance.faction, Entity())
|
||||
self.assertEqual(mock_provider_get_faction.call_count, 0)
|
||||
|
||||
|
||||
class TestCharacter(TestCase):
|
||||
|
||||
@@ -240,7 +348,8 @@ class TestCharacter(TestCase):
|
||||
id=1001,
|
||||
name='Bruce Wayne',
|
||||
corp_id=2001,
|
||||
alliance_id=3001
|
||||
alliance_id=3001,
|
||||
faction_id=1337,
|
||||
)
|
||||
|
||||
@patch(MODULE_PATH + '.EveSwaggerProvider.get_corp')
|
||||
@@ -282,12 +391,32 @@ class TestCharacter(TestCase):
|
||||
self.assertEqual(self.my_character.alliance, my_alliance)
|
||||
|
||||
# should call the provider one time only
|
||||
self.assertEqual(mock_provider_get_corp.call_count, 1)
|
||||
self.assertEqual(mock_provider_get_alliance.call_count, 1)
|
||||
|
||||
def test_alliance_has_none(self):
|
||||
@patch(MODULE_PATH + '.EveSwaggerProvider.get_alliance')
|
||||
def test_alliance_has_none(self, mock_provider_get_alliance):
|
||||
self.my_character.alliance_id = None
|
||||
self.assertEqual(self.my_character.alliance, Entity(None, None))
|
||||
self.assertEqual(mock_provider_get_alliance.call_count, 0)
|
||||
|
||||
@patch(MODULE_PATH + '.EveSwaggerProvider.get_faction')
|
||||
def test_faction_defined(self, mock_provider_get_faction):
|
||||
my_faction = Entity(id=1337, name='Permabanned')
|
||||
mock_provider_get_faction.return_value = my_faction
|
||||
|
||||
# fetch from provider if not defined
|
||||
self.assertEqual(self.my_character.faction, my_faction)
|
||||
|
||||
# return existing if defined
|
||||
mock_provider_get_faction.return_value = None
|
||||
self.assertEqual(self.my_character.faction, my_faction)
|
||||
self.assertEqual(mock_provider_get_faction.call_count, 1)
|
||||
|
||||
@patch(MODULE_PATH + '.EveSwaggerProvider.get_faction')
|
||||
def test_faction_undefined(self, mock_provider_get_faction):
|
||||
self.my_character.faction_id = None
|
||||
self.assertEqual(self.my_character.faction, Entity())
|
||||
self.assertEqual(mock_provider_get_faction.call_count, 0)
|
||||
|
||||
|
||||
class TestItemType(TestCase):
|
||||
@@ -449,10 +578,10 @@ class TestEveSwaggerProvider(TestCase):
|
||||
|
||||
@patch(MODULE_PATH + '.esi_client_factory')
|
||||
def test_get_alliance(self, mock_esi_client_factory):
|
||||
mock_esi_client_factory.return_value\
|
||||
mock_esi_client_factory.return_value \
|
||||
.Alliance.get_alliances_alliance_id \
|
||||
= TestEveSwaggerProvider.esi_get_alliances_alliance_id
|
||||
mock_esi_client_factory.return_value\
|
||||
mock_esi_client_factory.return_value \
|
||||
.Alliance.get_alliances_alliance_id_corporations \
|
||||
= TestEveSwaggerProvider.esi_get_alliances_alliance_id_corporations
|
||||
|
||||
@@ -477,7 +606,7 @@ class TestEveSwaggerProvider(TestCase):
|
||||
|
||||
@patch(MODULE_PATH + '.esi_client_factory')
|
||||
def test_get_corp(self, mock_esi_client_factory):
|
||||
mock_esi_client_factory.return_value\
|
||||
mock_esi_client_factory.return_value \
|
||||
.Corporation.get_corporations_corporation_id \
|
||||
= TestEveSwaggerProvider.esi_get_corporations_corporation_id
|
||||
|
||||
@@ -503,10 +632,10 @@ class TestEveSwaggerProvider(TestCase):
|
||||
|
||||
@patch(MODULE_PATH + '.esi_client_factory')
|
||||
def test_get_character(self, mock_esi_client_factory):
|
||||
mock_esi_client_factory.return_value\
|
||||
mock_esi_client_factory.return_value \
|
||||
.Character.get_characters_character_id \
|
||||
= TestEveSwaggerProvider.esi_get_characters_character_id
|
||||
mock_esi_client_factory.return_value\
|
||||
mock_esi_client_factory.return_value \
|
||||
.Character.post_characters_affiliation \
|
||||
= TestEveSwaggerProvider.esi_post_characters_affiliation
|
||||
|
||||
@@ -530,7 +659,7 @@ class TestEveSwaggerProvider(TestCase):
|
||||
|
||||
@patch(MODULE_PATH + '.esi_client_factory')
|
||||
def test_get_itemtype(self, mock_esi_client_factory):
|
||||
mock_esi_client_factory.return_value\
|
||||
mock_esi_client_factory.return_value \
|
||||
.Universe.get_universe_types_type_id \
|
||||
= TestEveSwaggerProvider.esi_get_universe_types_type_id
|
||||
|
||||
@@ -556,7 +685,7 @@ class TestEveSwaggerProvider(TestCase):
|
||||
@patch(MODULE_PATH + '.settings.DEBUG', False)
|
||||
@patch('socket.socket')
|
||||
def test_create_client_on_normal_startup_w_old_swagger_spec(
|
||||
self, mock_socket
|
||||
self, mock_socket
|
||||
):
|
||||
mock_socket.side_effect = Exception('Network blocked for testing')
|
||||
my_provider = EveSwaggerProvider()
|
||||
@@ -572,7 +701,7 @@ class TestEveSwaggerProvider(TestCase):
|
||||
@patch(MODULE_PATH + '.settings.DEBUG', False)
|
||||
@patch(MODULE_PATH + '.esi_client_factory')
|
||||
def test_dont_create_client_if_client_creation_fails_on_normal_startup(
|
||||
self, mock_esi_client_factory
|
||||
self, mock_esi_client_factory
|
||||
):
|
||||
mock_esi_client_factory.side_effect = RefResolutionError(cause='Test')
|
||||
my_provider = EveSwaggerProvider()
|
||||
@@ -582,7 +711,7 @@ class TestEveSwaggerProvider(TestCase):
|
||||
@patch(MODULE_PATH + '.settings.DEBUG', True)
|
||||
@patch(MODULE_PATH + '.esi_client_factory')
|
||||
def test_client_loads_on_demand(
|
||||
self, mock_esi_client_factory
|
||||
self, mock_esi_client_factory
|
||||
):
|
||||
mock_esi_client_factory.return_value = 'my_client'
|
||||
my_provider = EveSwaggerProvider()
|
||||
@@ -597,7 +726,7 @@ class TestEveSwaggerProvider(TestCase):
|
||||
def test_user_agent_header(self):
|
||||
my_provider = EveSwaggerProvider()
|
||||
my_client = my_provider.client
|
||||
operation = my_client.Status.get_status()
|
||||
operation = my_client.Universe.get_universe_factions()
|
||||
self.assertEqual(
|
||||
operation.future.request.headers['User-Agent'], 'allianceauth v1.0.0'
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user