Allow assigning factions to states.

This commit is contained in:
Adarnof
2021-10-26 09:16:28 +00:00
committed by Ariel Rin
parent 2da78f7793
commit 23849b9f42
19 changed files with 629 additions and 67 deletions

View File

@@ -6,6 +6,7 @@ from .providers import ObjectNotFound
from .models import EveAllianceInfo
from .models import EveCharacter
from .models import EveCorporationInfo
from .models import EveFactionInfo
class EveEntityExistsError(forms.ValidationError):
@@ -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

View File

@@ -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):

View 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'),
),
]

View File

@@ -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)

View File

@@ -22,6 +22,7 @@ get_corporations_corporation_id
get_characters_character_id
get_universe_types_type_id
post_character_affiliation
get_universe_factions
"""
@@ -38,7 +39,8 @@ class ObjectNotFound(Exception):
class Entity:
def __init__(self, id=None, name=None):
def __init__(self, id=None, name=None, **kwargs):
super().__init__(**kwargs)
self.id = id
self.name = name
@@ -55,15 +57,11 @@ class Entity:
return self.id == other.id
class Corporation(Entity):
def __init__(self, ticker=None, ceo_id=None, members=None, alliance_id=None, **kwargs):
class AllianceMixin:
def __init__(self, alliance_id=None, **kwargs):
super().__init__(**kwargs)
self.ticker = ticker
self.ceo_id = ceo_id
self.members = members
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,7 +102,7 @@ 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().__init__(**kwargs)
self.ticker = ticker
@@ -106,13 +128,11 @@ class Alliance(Entity):
return Entity(None, None)
class Character(Entity):
def __init__(self, corp_id=None, alliance_id=None, **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,12 +140,6 @@ 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):
@@ -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

View File

@@ -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

View File

@@ -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'
)