mirror of
https://gitlab.com/allianceauth/allianceauth.git
synced 2025-07-11 21:40:17 +02:00
Merge branch 'improve_evelinks' into 'master'
Add support for type icons to evelinks See merge request allianceauth/allianceauth!1210
This commit is contained in:
commit
f3065d79b3
@ -4,14 +4,14 @@
|
|||||||
# It contains of modules for views and templatetags for templates
|
# It contains of modules for views and templatetags for templates
|
||||||
|
|
||||||
# list of all eve entity categories as defined in ESI
|
# list of all eve entity categories as defined in ESI
|
||||||
ESI_CATEGORY_AGENT = "agent"
|
_ESI_CATEGORY_AGENT = "agent"
|
||||||
ESI_CATEGORY_ALLIANCE = "alliance"
|
_ESI_CATEGORY_ALLIANCE = "alliance"
|
||||||
ESI_CATEGORY_CHARACTER = "character"
|
_ESI_CATEGORY_CHARACTER = "character"
|
||||||
ESI_CATEGORY_CONSTELLATION = "constellation"
|
_ESI_CATEGORY_CONSTELLATION = "constellation"
|
||||||
ESI_CATEGORY_CORPORATION = "corporation"
|
_ESI_CATEGORY_CORPORATION = "corporation"
|
||||||
ESI_CATEGORY_FACTION = "faction"
|
_ESI_CATEGORY_FACTION = "faction"
|
||||||
ESI_CATEGORY_INVENTORYTYPE = "inventory_type"
|
_ESI_CATEGORY_INVENTORYTYPE = "inventory_type"
|
||||||
ESI_CATEGORY_REGION = "region"
|
_ESI_CATEGORY_REGION = "region"
|
||||||
ESI_CATEGORY_SOLARSYSTEM = "solar_system"
|
_ESI_CATEGORY_SOLARSYSTEM = "solar_system"
|
||||||
ESI_CATEGORY_STATION = "station"
|
_ESI_CATEGORY_STATION = "station"
|
||||||
ESI_CATEGORY_WORMHOLE = "wormhole"
|
_ESI_CATEGORY_WORMHOLE = "wormhole"
|
||||||
|
@ -2,24 +2,30 @@
|
|||||||
|
|
||||||
from urllib.parse import urljoin, quote
|
from urllib.parse import urljoin, quote
|
||||||
|
|
||||||
from . import *
|
from . import (
|
||||||
|
_ESI_CATEGORY_ALLIANCE,
|
||||||
|
_ESI_CATEGORY_CORPORATION,
|
||||||
|
_ESI_CATEGORY_REGION,
|
||||||
|
_ESI_CATEGORY_SOLARSYSTEM
|
||||||
|
)
|
||||||
|
|
||||||
BASE_URL = 'http://evemaps.dotlan.net'
|
|
||||||
|
_BASE_URL = 'http://evemaps.dotlan.net'
|
||||||
|
|
||||||
|
|
||||||
def _build_url(category: str, name: str) -> str:
|
def _build_url(category: str, name: str) -> str:
|
||||||
"""return url to profile page for an eve entity"""
|
"""return url to profile page for an eve entity"""
|
||||||
|
|
||||||
if category == ESI_CATEGORY_ALLIANCE:
|
if category == _ESI_CATEGORY_ALLIANCE:
|
||||||
partial = 'alliance'
|
partial = 'alliance'
|
||||||
|
|
||||||
elif category == ESI_CATEGORY_CORPORATION:
|
elif category == _ESI_CATEGORY_CORPORATION:
|
||||||
partial = 'corp'
|
partial = 'corp'
|
||||||
|
|
||||||
elif category == ESI_CATEGORY_REGION:
|
elif category == _ESI_CATEGORY_REGION:
|
||||||
partial = 'map'
|
partial = 'map'
|
||||||
|
|
||||||
elif category == ESI_CATEGORY_SOLARSYSTEM:
|
elif category == _ESI_CATEGORY_SOLARSYSTEM:
|
||||||
partial = 'system'
|
partial = 'system'
|
||||||
|
|
||||||
else:
|
else:
|
||||||
@ -28,7 +34,7 @@ def _build_url(category: str, name: str) -> str:
|
|||||||
)
|
)
|
||||||
|
|
||||||
url = urljoin(
|
url = urljoin(
|
||||||
BASE_URL,
|
_BASE_URL,
|
||||||
'{}/{}'.format(partial, quote(str(name).replace(" ", "_")))
|
'{}/{}'.format(partial, quote(str(name).replace(" ", "_")))
|
||||||
|
|
||||||
)
|
)
|
||||||
@ -37,16 +43,19 @@ def _build_url(category: str, name: str) -> str:
|
|||||||
|
|
||||||
def alliance_url(name: str) -> str:
|
def alliance_url(name: str) -> str:
|
||||||
"""url for page about given alliance on dotlan"""
|
"""url for page about given alliance on dotlan"""
|
||||||
return _build_url(ESI_CATEGORY_ALLIANCE, name)
|
return _build_url(_ESI_CATEGORY_ALLIANCE, name)
|
||||||
|
|
||||||
|
|
||||||
def corporation_url(name: str) -> str:
|
def corporation_url(name: str) -> str:
|
||||||
"""url for page about given corporation on dotlan"""
|
"""url for page about given corporation on dotlan"""
|
||||||
return _build_url(ESI_CATEGORY_CORPORATION, name)
|
return _build_url(_ESI_CATEGORY_CORPORATION, name)
|
||||||
|
|
||||||
|
|
||||||
def region_url(name: str) -> str:
|
def region_url(name: str) -> str:
|
||||||
"""url for page about given region on dotlan"""
|
"""url for page about given region on dotlan"""
|
||||||
return _build_url(ESI_CATEGORY_REGION, name)
|
return _build_url(_ESI_CATEGORY_REGION, name)
|
||||||
|
|
||||||
|
|
||||||
def solar_system_url(name: str) -> str:
|
def solar_system_url(name: str) -> str:
|
||||||
"""url for page about given solar system on dotlan"""
|
"""url for page about given solar system on dotlan"""
|
||||||
return _build_url(ESI_CATEGORY_SOLARSYSTEM, name)
|
return _build_url(_ESI_CATEGORY_SOLARSYSTEM, name)
|
||||||
|
129
allianceauth/eveonline/evelinks/eveimageserver.py
Normal file
129
allianceauth/eveonline/evelinks/eveimageserver.py
Normal file
@ -0,0 +1,129 @@
|
|||||||
|
from . import (
|
||||||
|
_ESI_CATEGORY_ALLIANCE,
|
||||||
|
_ESI_CATEGORY_CHARACTER,
|
||||||
|
_ESI_CATEGORY_CORPORATION,
|
||||||
|
_ESI_CATEGORY_INVENTORYTYPE
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
_EVE_IMAGE_SERVER_URL = 'https://images.evetech.net'
|
||||||
|
_DEFAULT_IMAGE_SIZE = 32
|
||||||
|
|
||||||
|
|
||||||
|
def _eve_entity_image_url(
|
||||||
|
category: str,
|
||||||
|
entity_id: int,
|
||||||
|
size: int = 32,
|
||||||
|
variant: str = None,
|
||||||
|
tenant: str = None,
|
||||||
|
) -> str:
|
||||||
|
"""returns image URL for an Eve Online ID.
|
||||||
|
Supported categories: alliance, corporation, character, inventory_type
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
- category: category of the ID, see ESI category constants
|
||||||
|
- entity_id: Eve ID of the entity
|
||||||
|
- size: (optional) render size of the image.must be between 32 (default) and 1024
|
||||||
|
- variant: (optional) image variant for category. currently not relevant.
|
||||||
|
- tenant: (optional) Eve Server, either `tranquility`(default) or `singularity`
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
- URL string for the requested image on the Eve image server
|
||||||
|
|
||||||
|
Exceptions:
|
||||||
|
- Throws ValueError on invalid input
|
||||||
|
"""
|
||||||
|
|
||||||
|
# input validations
|
||||||
|
categories = {
|
||||||
|
_ESI_CATEGORY_ALLIANCE: {
|
||||||
|
'endpoint': 'alliances',
|
||||||
|
'variants': ['logo']
|
||||||
|
},
|
||||||
|
_ESI_CATEGORY_CORPORATION: {
|
||||||
|
'endpoint': 'corporations',
|
||||||
|
'variants': ['logo']
|
||||||
|
},
|
||||||
|
_ESI_CATEGORY_CHARACTER: {
|
||||||
|
'endpoint': 'characters',
|
||||||
|
'variants': ['portrait']
|
||||||
|
},
|
||||||
|
_ESI_CATEGORY_INVENTORYTYPE: {
|
||||||
|
'endpoint': 'types',
|
||||||
|
'variants': ['icon', 'render']
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tenants = ['tranquility', 'singularity']
|
||||||
|
|
||||||
|
if not entity_id:
|
||||||
|
raise ValueError('Invalid entity_id: {}'.format(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))
|
||||||
|
|
||||||
|
if category not in categories:
|
||||||
|
raise ValueError('Invalid category {}'.format(category))
|
||||||
|
else:
|
||||||
|
endpoint = categories[category]['endpoint']
|
||||||
|
|
||||||
|
if variant:
|
||||||
|
if variant not in categories[category]['variants']:
|
||||||
|
raise ValueError('Invalid variant {} for category {}'.format(
|
||||||
|
variant,
|
||||||
|
category
|
||||||
|
))
|
||||||
|
else:
|
||||||
|
variant = categories[category]['variants'][0]
|
||||||
|
|
||||||
|
if tenant and tenant not in tenants:
|
||||||
|
raise ValueError('Invalid tenant {}'.format(tenant))
|
||||||
|
|
||||||
|
# compose result URL
|
||||||
|
result = '{}/{}/{}/{}?size={}'.format(
|
||||||
|
_EVE_IMAGE_SERVER_URL,
|
||||||
|
endpoint,
|
||||||
|
entity_id,
|
||||||
|
variant,
|
||||||
|
size
|
||||||
|
)
|
||||||
|
if tenant:
|
||||||
|
result += '&tenant={}'.format(tenant)
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
def alliance_logo_url(alliance_id: int, size: int = _DEFAULT_IMAGE_SIZE) -> str:
|
||||||
|
"""image URL for the given alliance ID"""
|
||||||
|
return _eve_entity_image_url(_ESI_CATEGORY_ALLIANCE, alliance_id, size)
|
||||||
|
|
||||||
|
|
||||||
|
def corporation_logo_url(
|
||||||
|
corporation_id: int, size: int = _DEFAULT_IMAGE_SIZE
|
||||||
|
) -> str:
|
||||||
|
"""image URL for the given corporation ID"""
|
||||||
|
return _eve_entity_image_url(
|
||||||
|
_ESI_CATEGORY_CORPORATION, corporation_id, size
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def character_portrait_url(
|
||||||
|
character_id: int, size: int = _DEFAULT_IMAGE_SIZE
|
||||||
|
) -> str:
|
||||||
|
"""image URL for the given character ID"""
|
||||||
|
return _eve_entity_image_url(_ESI_CATEGORY_CHARACTER, character_id, size)
|
||||||
|
|
||||||
|
|
||||||
|
def type_icon_url(type_id: int, size: int = _DEFAULT_IMAGE_SIZE) -> str:
|
||||||
|
"""icon image URL for the given type ID"""
|
||||||
|
return _eve_entity_image_url(
|
||||||
|
_ESI_CATEGORY_INVENTORYTYPE, type_id, size, variant='icon'
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def type_render_url(type_id: int, size: int = _DEFAULT_IMAGE_SIZE) -> str:
|
||||||
|
"""render image URL for the given type ID"""
|
||||||
|
return _eve_entity_image_url(
|
||||||
|
_ESI_CATEGORY_INVENTORYTYPE, type_id, size, variant='render'
|
||||||
|
)
|
@ -1,22 +1,27 @@
|
|||||||
# this module generates profile URLs for evewho
|
# this module generates profile URLs for evewho
|
||||||
|
|
||||||
from urllib.parse import urljoin, quote
|
from urllib.parse import urljoin
|
||||||
|
|
||||||
from . import *
|
from . import (
|
||||||
|
_ESI_CATEGORY_ALLIANCE,
|
||||||
|
_ESI_CATEGORY_CORPORATION,
|
||||||
|
_ESI_CATEGORY_CHARACTER,
|
||||||
|
)
|
||||||
|
|
||||||
BASE_URL = 'https://evewho.com'
|
|
||||||
|
_BASE_URL = 'https://evewho.com'
|
||||||
|
|
||||||
|
|
||||||
def _build_url(category: str, eve_id: int) -> str:
|
def _build_url(category: str, eve_id: int) -> str:
|
||||||
"""return url to profile page for an eve entity"""
|
"""return url to profile page for an eve entity"""
|
||||||
|
|
||||||
if category == ESI_CATEGORY_ALLIANCE:
|
if category == _ESI_CATEGORY_ALLIANCE:
|
||||||
partial = 'alliance'
|
partial = 'alliance'
|
||||||
|
|
||||||
elif category == ESI_CATEGORY_CORPORATION:
|
elif category == _ESI_CATEGORY_CORPORATION:
|
||||||
partial = 'corporation'
|
partial = 'corporation'
|
||||||
|
|
||||||
elif category == ESI_CATEGORY_CHARACTER:
|
elif category == _ESI_CATEGORY_CHARACTER:
|
||||||
partial = 'character'
|
partial = 'character'
|
||||||
|
|
||||||
else:
|
else:
|
||||||
@ -25,7 +30,7 @@ def _build_url(category: str, eve_id: int) -> str:
|
|||||||
)
|
)
|
||||||
|
|
||||||
url = urljoin(
|
url = urljoin(
|
||||||
BASE_URL,
|
_BASE_URL,
|
||||||
'{}/{}'.format(partial, int(eve_id))
|
'{}/{}'.format(partial, int(eve_id))
|
||||||
)
|
)
|
||||||
return url
|
return url
|
||||||
@ -33,12 +38,14 @@ def _build_url(category: str, eve_id: int) -> str:
|
|||||||
|
|
||||||
def alliance_url(eve_id: int) -> str:
|
def alliance_url(eve_id: int) -> str:
|
||||||
"""url for page about given alliance on evewho"""
|
"""url for page about given alliance on evewho"""
|
||||||
return _build_url(ESI_CATEGORY_ALLIANCE, eve_id)
|
return _build_url(_ESI_CATEGORY_ALLIANCE, eve_id)
|
||||||
|
|
||||||
|
|
||||||
def character_url(eve_id: int) -> str:
|
def character_url(eve_id: int) -> str:
|
||||||
"""url for page about given character on evewho"""
|
"""url for page about given character on evewho"""
|
||||||
return _build_url(ESI_CATEGORY_CHARACTER, eve_id)
|
return _build_url(_ESI_CATEGORY_CHARACTER, eve_id)
|
||||||
|
|
||||||
|
|
||||||
def corporation_url(eve_id: int) -> str:
|
def corporation_url(eve_id: int) -> str:
|
||||||
"""url for page about given corporation on evewho"""
|
"""url for page about given corporation on evewho"""
|
||||||
return _build_url(ESI_CATEGORY_CORPORATION, eve_id)
|
return _build_url(_ESI_CATEGORY_CORPORATION, eve_id)
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
|
|
||||||
from ...models import EveCharacter, EveCorporationInfo, EveAllianceInfo
|
from ...models import EveCharacter, EveCorporationInfo, EveAllianceInfo
|
||||||
from .. import dotlan, zkillboard, evewho
|
from .. import dotlan, zkillboard, evewho, eveimageserver
|
||||||
from ...templatetags import evelinks
|
from ...templatetags import evelinks
|
||||||
|
|
||||||
|
|
||||||
@ -90,3 +90,115 @@ class TestZkillboard(TestCase):
|
|||||||
'https://zkillboard.com/system/12345678/'
|
'https://zkillboard.com/system/12345678/'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class TestEveImageServer(TestCase):
|
||||||
|
"""unit test for eveimageserver"""
|
||||||
|
|
||||||
|
def test_sizes(self):
|
||||||
|
self.assertEqual(
|
||||||
|
eveimageserver._eve_entity_image_url('character', 42),
|
||||||
|
'https://images.evetech.net/characters/42/portrait?size=32'
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
eveimageserver._eve_entity_image_url('character', 42, size=32),
|
||||||
|
'https://images.evetech.net/characters/42/portrait?size=32'
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
eveimageserver._eve_entity_image_url('character', 42, size=64),
|
||||||
|
'https://images.evetech.net/characters/42/portrait?size=64'
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
eveimageserver._eve_entity_image_url('character', 42, size=128),
|
||||||
|
'https://images.evetech.net/characters/42/portrait?size=128'
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
eveimageserver._eve_entity_image_url('character', 42, size=256),
|
||||||
|
'https://images.evetech.net/characters/42/portrait?size=256'
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
eveimageserver._eve_entity_image_url('character', 42, size=512),
|
||||||
|
'https://images.evetech.net/characters/42/portrait?size=512'
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
eveimageserver._eve_entity_image_url('character', 42, size=1024),
|
||||||
|
'https://images.evetech.net/characters/42/portrait?size=1024'
|
||||||
|
)
|
||||||
|
with self.assertRaises(ValueError):
|
||||||
|
eveimageserver._eve_entity_image_url('corporation', 42, size=-5)
|
||||||
|
|
||||||
|
with self.assertRaises(ValueError):
|
||||||
|
eveimageserver._eve_entity_image_url('corporation', 42, size=0)
|
||||||
|
|
||||||
|
with self.assertRaises(ValueError):
|
||||||
|
eveimageserver._eve_entity_image_url('corporation', 42, size=31)
|
||||||
|
|
||||||
|
with self.assertRaises(ValueError):
|
||||||
|
eveimageserver._eve_entity_image_url('corporation', 42, size=1025)
|
||||||
|
|
||||||
|
with self.assertRaises(ValueError):
|
||||||
|
eveimageserver._eve_entity_image_url('corporation', 42, size=2048)
|
||||||
|
|
||||||
|
|
||||||
|
def test_variant(self):
|
||||||
|
self.assertEqual(
|
||||||
|
eveimageserver._eve_entity_image_url('character', 42, variant='portrait'),
|
||||||
|
'https://images.evetech.net/characters/42/portrait?size=32'
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
eveimageserver._eve_entity_image_url('alliance', 42, variant='logo'),
|
||||||
|
'https://images.evetech.net/alliances/42/logo?size=32'
|
||||||
|
)
|
||||||
|
with self.assertRaises(ValueError):
|
||||||
|
eveimageserver._eve_entity_image_url('character', 42, variant='logo')
|
||||||
|
|
||||||
|
|
||||||
|
def test_alliance(self):
|
||||||
|
self.assertEqual(
|
||||||
|
eveimageserver._eve_entity_image_url('alliance', 42),
|
||||||
|
'https://images.evetech.net/alliances/42/logo?size=32'
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
eveimageserver._eve_entity_image_url('corporation', 42),
|
||||||
|
'https://images.evetech.net/corporations/42/logo?size=32'
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
eveimageserver._eve_entity_image_url('character', 42),
|
||||||
|
'https://images.evetech.net/characters/42/portrait?size=32'
|
||||||
|
)
|
||||||
|
with self.assertRaises(ValueError):
|
||||||
|
eveimageserver._eve_entity_image_url('station', 42)
|
||||||
|
|
||||||
|
|
||||||
|
def test_tenants(self):
|
||||||
|
self.assertEqual(
|
||||||
|
eveimageserver._eve_entity_image_url('character', 42, tenant='tranquility'),
|
||||||
|
'https://images.evetech.net/characters/42/portrait?size=32&tenant=tranquility'
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
eveimageserver._eve_entity_image_url('character', 42, tenant='singularity'),
|
||||||
|
'https://images.evetech.net/characters/42/portrait?size=32&tenant=singularity'
|
||||||
|
)
|
||||||
|
with self.assertRaises(ValueError):
|
||||||
|
eveimageserver._eve_entity_image_url('character', 42, tenant='xxx')
|
||||||
|
|
||||||
|
def test_alliance_logo_url(self):
|
||||||
|
expected = 'https://images.evetech.net/alliances/42/logo?size=128'
|
||||||
|
self.assertEqual(eveimageserver.alliance_logo_url(42, 128), expected)
|
||||||
|
|
||||||
|
def test_corporation_logo_url(self):
|
||||||
|
expected = 'https://images.evetech.net/corporations/42/logo?size=128'
|
||||||
|
self.assertEqual(eveimageserver.corporation_logo_url(42, 128), expected)
|
||||||
|
|
||||||
|
def test_character_portrait_url(self):
|
||||||
|
expected = 'https://images.evetech.net/characters/42/portrait?size=128'
|
||||||
|
self.assertEqual(
|
||||||
|
eveimageserver.character_portrait_url(42, 128), expected
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_type_icon_url(self):
|
||||||
|
expected = 'https://images.evetech.net/types/42/icon?size=128'
|
||||||
|
self.assertEqual(eveimageserver.type_icon_url(42, 128), expected)
|
||||||
|
|
||||||
|
def test_type_render_url(self):
|
||||||
|
expected = 'https://images.evetech.net/types/42/render?size=128'
|
||||||
|
self.assertEqual(eveimageserver.type_render_url(42, 128), expected)
|
@ -1,7 +1,7 @@
|
|||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
|
|
||||||
from ...models import EveCharacter, EveCorporationInfo, EveAllianceInfo
|
from ...models import EveCharacter, EveCorporationInfo, EveAllianceInfo
|
||||||
from .. import dotlan, zkillboard, evewho
|
from .. import eveimageserver, evewho, dotlan, zkillboard
|
||||||
from ...templatetags import evelinks
|
from ...templatetags import evelinks
|
||||||
|
|
||||||
|
|
||||||
@ -332,3 +332,28 @@ class TestTemplateTags(TestCase):
|
|||||||
''
|
''
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_type_icon_url(self):
|
||||||
|
expected = eveimageserver.type_icon_url(123)
|
||||||
|
self.assertEqual(evelinks.type_icon_url(123), expected)
|
||||||
|
|
||||||
|
expected = eveimageserver.type_icon_url(123, 128)
|
||||||
|
self.assertEqual(evelinks.type_icon_url(123, 128), expected)
|
||||||
|
|
||||||
|
expected = ''
|
||||||
|
self.assertEqual(evelinks.type_icon_url(123, 99), expected)
|
||||||
|
|
||||||
|
expected = ''
|
||||||
|
self.assertEqual(evelinks.type_icon_url(None), expected)
|
||||||
|
|
||||||
|
def test_type_render_url(self):
|
||||||
|
expected = eveimageserver.type_render_url(123)
|
||||||
|
self.assertEqual(evelinks.type_render_url(123), expected)
|
||||||
|
|
||||||
|
expected = eveimageserver.type_render_url(123, 128)
|
||||||
|
self.assertEqual(evelinks.type_render_url(123, 128), expected)
|
||||||
|
|
||||||
|
expected = ''
|
||||||
|
self.assertEqual(evelinks.type_render_url(123, 99), expected)
|
||||||
|
|
||||||
|
expected = ''
|
||||||
|
self.assertEqual(evelinks.type_render_url(None), expected)
|
@ -1,28 +1,35 @@
|
|||||||
# this module generates profile URLs for zKillboard
|
# this module generates profile URLs for zKillboard
|
||||||
|
|
||||||
from urllib.parse import urljoin, quote
|
from urllib.parse import urljoin
|
||||||
|
|
||||||
from . import *
|
from . import (
|
||||||
|
_ESI_CATEGORY_ALLIANCE,
|
||||||
|
_ESI_CATEGORY_CORPORATION,
|
||||||
|
_ESI_CATEGORY_CHARACTER,
|
||||||
|
_ESI_CATEGORY_REGION,
|
||||||
|
_ESI_CATEGORY_SOLARSYSTEM
|
||||||
|
)
|
||||||
|
|
||||||
BASE_URL = 'https://zkillboard.com'
|
|
||||||
|
_BASE_URL = 'https://zkillboard.com'
|
||||||
|
|
||||||
|
|
||||||
def _build_url(category: str, eve_id: int) -> str:
|
def _build_url(category: str, eve_id: int) -> str:
|
||||||
"""return url to profile page for an eve entity"""
|
"""return url to profile page for an eve entity"""
|
||||||
|
|
||||||
if category == ESI_CATEGORY_ALLIANCE:
|
if category == _ESI_CATEGORY_ALLIANCE:
|
||||||
partial = 'alliance'
|
partial = 'alliance'
|
||||||
|
|
||||||
elif category == ESI_CATEGORY_CORPORATION:
|
elif category == _ESI_CATEGORY_CORPORATION:
|
||||||
partial = 'corporation'
|
partial = 'corporation'
|
||||||
|
|
||||||
elif category == ESI_CATEGORY_CHARACTER:
|
elif category == _ESI_CATEGORY_CHARACTER:
|
||||||
partial = 'character'
|
partial = 'character'
|
||||||
|
|
||||||
elif category == ESI_CATEGORY_REGION:
|
elif category == _ESI_CATEGORY_REGION:
|
||||||
partial = 'region'
|
partial = 'region'
|
||||||
|
|
||||||
elif category == ESI_CATEGORY_SOLARSYSTEM:
|
elif category == _ESI_CATEGORY_SOLARSYSTEM:
|
||||||
partial = 'system'
|
partial = 'system'
|
||||||
|
|
||||||
else:
|
else:
|
||||||
@ -31,7 +38,7 @@ def _build_url(category: str, eve_id: int) -> str:
|
|||||||
)
|
)
|
||||||
|
|
||||||
url = urljoin(
|
url = urljoin(
|
||||||
BASE_URL,
|
_BASE_URL,
|
||||||
'{}/{}/'.format(partial, int(eve_id))
|
'{}/{}/'.format(partial, int(eve_id))
|
||||||
)
|
)
|
||||||
return url
|
return url
|
||||||
@ -39,19 +46,23 @@ def _build_url(category: str, eve_id: int) -> str:
|
|||||||
|
|
||||||
def alliance_url(eve_id: int) -> str:
|
def alliance_url(eve_id: int) -> str:
|
||||||
"""url for page about given alliance on zKillboard"""
|
"""url for page about given alliance on zKillboard"""
|
||||||
return _build_url(ESI_CATEGORY_ALLIANCE, eve_id)
|
return _build_url(_ESI_CATEGORY_ALLIANCE, eve_id)
|
||||||
|
|
||||||
|
|
||||||
def character_url(eve_id: int) -> str:
|
def character_url(eve_id: int) -> str:
|
||||||
"""url for page about given character on zKillboard"""
|
"""url for page about given character on zKillboard"""
|
||||||
return _build_url(ESI_CATEGORY_CHARACTER, eve_id)
|
return _build_url(_ESI_CATEGORY_CHARACTER, eve_id)
|
||||||
|
|
||||||
|
|
||||||
def corporation_url(eve_id: int) -> str:
|
def corporation_url(eve_id: int) -> str:
|
||||||
"""url for page about given corporation on zKillboard"""
|
"""url for page about given corporation on zKillboard"""
|
||||||
return _build_url(ESI_CATEGORY_CORPORATION, eve_id)
|
return _build_url(_ESI_CATEGORY_CORPORATION, eve_id)
|
||||||
|
|
||||||
|
|
||||||
def region_url(eve_id: int) -> str:
|
def region_url(eve_id: int) -> str:
|
||||||
"""url for page about given region on zKillboard"""
|
"""url for page about given region on zKillboard"""
|
||||||
return _build_url(ESI_CATEGORY_REGION, eve_id)
|
return _build_url(_ESI_CATEGORY_REGION, eve_id)
|
||||||
|
|
||||||
|
|
||||||
def solar_system_url(eve_id: int) -> str:
|
def solar_system_url(eve_id: int) -> str:
|
||||||
return _build_url(ESI_CATEGORY_SOLARSYSTEM, eve_id)
|
return _build_url(_ESI_CATEGORY_SOLARSYSTEM, eve_id)
|
||||||
|
@ -89,4 +89,6 @@ class EveCorporationManager(models.Manager):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def update_corporation(self, corp_id):
|
def update_corporation(self, corp_id):
|
||||||
return self.get(corporation_id=corp_id).update_corporation(self.provider.get_corporation(corp_id))
|
return self\
|
||||||
|
.get(corporation_id=corp_id)\
|
||||||
|
.update_corporation(self.provider.get_corporation(corp_id))
|
||||||
|
@ -5,90 +5,9 @@ from .managers import EveCharacterManager, EveCharacterProviderManager
|
|||||||
from .managers import EveCorporationManager, EveCorporationProviderManager
|
from .managers import EveCorporationManager, EveCorporationProviderManager
|
||||||
from .managers import EveAllianceManager, EveAllianceProviderManager
|
from .managers import EveAllianceManager, EveAllianceProviderManager
|
||||||
from . import providers
|
from . import providers
|
||||||
|
from .evelinks import eveimageserver
|
||||||
|
|
||||||
|
_DEFAULT_IMAGE_SIZE = 32
|
||||||
EVE_IMAGE_SERVER_URL = 'https://images.evetech.net'
|
|
||||||
|
|
||||||
|
|
||||||
def _eve_entity_image_url(
|
|
||||||
category: str,
|
|
||||||
id: int,
|
|
||||||
size: int = 32,
|
|
||||||
variant: str = None,
|
|
||||||
tenant: str = None,
|
|
||||||
) -> str:
|
|
||||||
"""returns image URL for an Eve Online ID.
|
|
||||||
Supported categories: `alliance`, `corporation`, `character`
|
|
||||||
|
|
||||||
Arguments:
|
|
||||||
- category: category of the ID
|
|
||||||
- id: Eve ID of the entity
|
|
||||||
- size: (optional) render size of the image.must be between 32 (default) and 1024
|
|
||||||
- variant: (optional) image variant for category. currently not relevant.
|
|
||||||
- tentant: (optional) Eve Server, either `tranquility`(default) or `singularity`
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
- URL string for the requested image on the Eve image server
|
|
||||||
|
|
||||||
Exceptions:
|
|
||||||
- Throws ValueError on invalid input
|
|
||||||
"""
|
|
||||||
|
|
||||||
# input validations
|
|
||||||
categories = {
|
|
||||||
'alliance': {
|
|
||||||
'endpoint': 'alliances',
|
|
||||||
'variants': [
|
|
||||||
'logo'
|
|
||||||
]
|
|
||||||
},
|
|
||||||
'corporation': {
|
|
||||||
'endpoint': 'corporations',
|
|
||||||
'variants': [
|
|
||||||
'logo'
|
|
||||||
]
|
|
||||||
},
|
|
||||||
'character': {
|
|
||||||
'endpoint': 'characters',
|
|
||||||
'variants': [
|
|
||||||
'portrait'
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
tenants = ['tranquility', 'singularity']
|
|
||||||
|
|
||||||
if size < 32 or size > 1024 or (size & (size - 1) != 0):
|
|
||||||
raise ValueError('Invalid size: {}'.format(size))
|
|
||||||
|
|
||||||
if category not in categories:
|
|
||||||
raise ValueError('Invalid category {}'.format(category))
|
|
||||||
else:
|
|
||||||
endpoint = categories[category]['endpoint']
|
|
||||||
|
|
||||||
if variant:
|
|
||||||
if variant not in categories[category]['variants']:
|
|
||||||
raise ValueError('Invalid variant {} for category {}'.format(
|
|
||||||
variant,
|
|
||||||
category
|
|
||||||
))
|
|
||||||
else:
|
|
||||||
variant = categories[category]['variants'][0]
|
|
||||||
|
|
||||||
if tenant and tenant not in tenants:
|
|
||||||
raise ValueError('Invalid tentant {}'.format(tenant))
|
|
||||||
|
|
||||||
# compose result URL
|
|
||||||
result = '{}/{}/{}/{}?size={}'.format(
|
|
||||||
EVE_IMAGE_SERVER_URL,
|
|
||||||
endpoint,
|
|
||||||
id,
|
|
||||||
variant,
|
|
||||||
size
|
|
||||||
)
|
|
||||||
if tenant:
|
|
||||||
result += '&tenant={}'.format(tenant)
|
|
||||||
|
|
||||||
return result
|
|
||||||
|
|
||||||
|
|
||||||
class EveAllianceInfo(models.Model):
|
class EveAllianceInfo(models.Model):
|
||||||
@ -105,9 +24,13 @@ class EveAllianceInfo(models.Model):
|
|||||||
for corp_id in alliance.corp_ids:
|
for corp_id in alliance.corp_ids:
|
||||||
if not EveCorporationInfo.objects.filter(corporation_id=corp_id).exists():
|
if not EveCorporationInfo.objects.filter(corporation_id=corp_id).exists():
|
||||||
EveCorporationInfo.objects.create_corporation(corp_id)
|
EveCorporationInfo.objects.create_corporation(corp_id)
|
||||||
EveCorporationInfo.objects.filter(corporation_id__in=alliance.corp_ids).update(alliance=self)
|
EveCorporationInfo.objects.filter(
|
||||||
EveCorporationInfo.objects.filter(alliance=self).exclude(corporation_id__in=alliance.corp_ids).update(
|
corporation_id__in=alliance.corp_ids).update(alliance=self
|
||||||
alliance=None)
|
)
|
||||||
|
EveCorporationInfo.objects\
|
||||||
|
.filter(alliance=self)\
|
||||||
|
.exclude(corporation_id__in=alliance.corp_ids)\
|
||||||
|
.update(alliance=None)
|
||||||
|
|
||||||
def update_alliance(self, alliance: providers.Alliance = None):
|
def update_alliance(self, alliance: providers.Alliance = None):
|
||||||
if alliance is None:
|
if alliance is None:
|
||||||
@ -120,11 +43,13 @@ class EveAllianceInfo(models.Model):
|
|||||||
return self.alliance_name
|
return self.alliance_name
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def generic_logo_url(alliance_id: int, size: int = 32) -> str:
|
def generic_logo_url(
|
||||||
|
alliance_id: int, size: int = _DEFAULT_IMAGE_SIZE
|
||||||
|
) -> str:
|
||||||
"""image URL for the given alliance ID"""
|
"""image URL for the given alliance ID"""
|
||||||
return _eve_entity_image_url('alliance', alliance_id, size)
|
return eveimageserver.alliance_logo_url(alliance_id, size)
|
||||||
|
|
||||||
def logo_url(self, size:int = 32) -> str:
|
def logo_url(self, size: int = _DEFAULT_IMAGE_SIZE) -> str:
|
||||||
"""image URL of this alliance"""
|
"""image URL of this alliance"""
|
||||||
return self.generic_logo_url(self.alliance_id, size)
|
return self.generic_logo_url(self.alliance_id, size)
|
||||||
|
|
||||||
@ -154,7 +79,9 @@ class EveCorporationInfo(models.Model):
|
|||||||
corporation_name = models.CharField(max_length=254, unique=True)
|
corporation_name = models.CharField(max_length=254, unique=True)
|
||||||
corporation_ticker = models.CharField(max_length=254)
|
corporation_ticker = models.CharField(max_length=254)
|
||||||
member_count = models.IntegerField()
|
member_count = models.IntegerField()
|
||||||
alliance = models.ForeignKey(EveAllianceInfo, blank=True, null=True, on_delete=models.SET_NULL)
|
alliance = models.ForeignKey(
|
||||||
|
EveAllianceInfo, blank=True, null=True, on_delete=models.SET_NULL
|
||||||
|
)
|
||||||
|
|
||||||
objects = EveCorporationManager()
|
objects = EveCorporationManager()
|
||||||
provider = EveCorporationProviderManager()
|
provider = EveCorporationProviderManager()
|
||||||
@ -174,11 +101,13 @@ class EveCorporationInfo(models.Model):
|
|||||||
return self.corporation_name
|
return self.corporation_name
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def generic_logo_url(corporation_id: int, size: int = 32) -> str:
|
def generic_logo_url(
|
||||||
|
corporation_id: int, size: int = _DEFAULT_IMAGE_SIZE
|
||||||
|
) -> str:
|
||||||
"""image URL for the given corporation ID"""
|
"""image URL for the given corporation ID"""
|
||||||
return _eve_entity_image_url('corporation', corporation_id, size)
|
return eveimageserver.corporation_logo_url(corporation_id, size)
|
||||||
|
|
||||||
def logo_url(self, size:int = 32) -> str:
|
def logo_url(self, size: int = _DEFAULT_IMAGE_SIZE) -> str:
|
||||||
"""image URL for this corporation"""
|
"""image URL for this corporation"""
|
||||||
return self.generic_logo_url(self.corporation_id, size)
|
return self.generic_logo_url(self.corporation_id, size)
|
||||||
|
|
||||||
@ -253,11 +182,13 @@ class EveCharacter(models.Model):
|
|||||||
return self.character_name
|
return self.character_name
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def generic_portrait_url(character_id: int, size: int = 32) -> str:
|
def generic_portrait_url(
|
||||||
|
character_id: int, size: int = _DEFAULT_IMAGE_SIZE
|
||||||
|
) -> str:
|
||||||
"""image URL for the given character ID"""
|
"""image URL for the given character ID"""
|
||||||
return _eve_entity_image_url('character', character_id, size)
|
return eveimageserver.character_portrait_url(character_id, size)
|
||||||
|
|
||||||
def portrait_url(self, size = 32) -> str:
|
def portrait_url(self, size=_DEFAULT_IMAGE_SIZE) -> str:
|
||||||
"""image URL for this character"""
|
"""image URL for this character"""
|
||||||
return self.generic_portrait_url(self.character_id, size)
|
return self.generic_portrait_url(self.character_id, size)
|
||||||
|
|
||||||
@ -281,7 +212,7 @@ class EveCharacter(models.Model):
|
|||||||
"""image URL for this character"""
|
"""image URL for this character"""
|
||||||
return self.portrait_url(256)
|
return self.portrait_url(256)
|
||||||
|
|
||||||
def corporation_logo_url(self, size = 32) -> str:
|
def corporation_logo_url(self, size=_DEFAULT_IMAGE_SIZE) -> str:
|
||||||
"""image URL for corporation of this character"""
|
"""image URL for corporation of this character"""
|
||||||
return EveCorporationInfo.generic_logo_url(self.corporation_id, size)
|
return EveCorporationInfo.generic_logo_url(self.corporation_id, size)
|
||||||
|
|
||||||
@ -305,7 +236,7 @@ class EveCharacter(models.Model):
|
|||||||
"""image URL for corporation of this character"""
|
"""image URL for corporation of this character"""
|
||||||
return self.corporation_logo_url(256)
|
return self.corporation_logo_url(256)
|
||||||
|
|
||||||
def alliance_logo_url(self, size = 32) -> str:
|
def alliance_logo_url(self, size=_DEFAULT_IMAGE_SIZE) -> str:
|
||||||
"""image URL for alliance of this character or empty string"""
|
"""image URL for alliance of this character or empty string"""
|
||||||
if self.alliance_id:
|
if self.alliance_id:
|
||||||
return EveAllianceInfo.generic_logo_url(self.alliance_id, size)
|
return EveAllianceInfo.generic_logo_url(self.alliance_id, size)
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
from django import template
|
from django import template
|
||||||
|
|
||||||
from ..models import EveCharacter, EveCorporationInfo, EveAllianceInfo
|
from ..models import EveCharacter, EveCorporationInfo, EveAllianceInfo
|
||||||
from ..evelinks import evewho, dotlan, zkillboard
|
from ..evelinks import eveimageserver, evewho, dotlan, zkillboard
|
||||||
|
|
||||||
register = template.Library()
|
register = template.Library()
|
||||||
|
|
||||||
@ -163,7 +163,7 @@ def dotlan_solar_system_url(eve_obj: object) -> str:
|
|||||||
return _generic_evelinks_url(dotlan, 'solar_system_url', eve_obj)
|
return _generic_evelinks_url(dotlan, 'solar_system_url', eve_obj)
|
||||||
|
|
||||||
|
|
||||||
#zkillboard
|
# zkillboard
|
||||||
|
|
||||||
@register.filter
|
@register.filter
|
||||||
def zkillboard_character_url(eve_obj: EveCharacter) -> str:
|
def zkillboard_character_url(eve_obj: EveCharacter) -> str:
|
||||||
@ -212,7 +212,6 @@ def zkillboard_solar_system_url(eve_obj: object) -> str:
|
|||||||
|
|
||||||
# image urls
|
# image urls
|
||||||
|
|
||||||
|
|
||||||
@register.filter
|
@register.filter
|
||||||
def character_portrait_url(
|
def character_portrait_url(
|
||||||
eve_obj: object,
|
eve_obj: object,
|
||||||
@ -284,3 +283,30 @@ def alliance_logo_url(
|
|||||||
except ValueError:
|
except ValueError:
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
|
|
||||||
|
@register.filter
|
||||||
|
def type_icon_url(
|
||||||
|
type_id: int,
|
||||||
|
size: int = _DEFAULT_IMAGE_SIZE
|
||||||
|
) -> str:
|
||||||
|
"""generates a icon image URL for the given type ID
|
||||||
|
Returns URL or empty string
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
return eveimageserver.type_icon_url(type_id, size)
|
||||||
|
except ValueError:
|
||||||
|
return ''
|
||||||
|
|
||||||
|
|
||||||
|
@register.filter
|
||||||
|
def type_render_url(
|
||||||
|
type_id: int,
|
||||||
|
size: int = _DEFAULT_IMAGE_SIZE
|
||||||
|
) -> str:
|
||||||
|
"""generates a render image URL for the given type ID
|
||||||
|
Returns URL or empty string
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
return eveimageserver.type_render_url(type_id, size)
|
||||||
|
except ValueError:
|
||||||
|
return ''
|
||||||
|
@ -58,23 +58,19 @@ class EveCharacterManagerTestCase(TestCase):
|
|||||||
@mock.patch('allianceauth.eveonline.managers.providers.provider')
|
@mock.patch('allianceauth.eveonline.managers.providers.provider')
|
||||||
def test_update_character(self, provider):
|
def test_update_character(self, provider):
|
||||||
# Also covers Model.update_character
|
# Also covers Model.update_character
|
||||||
existing = EveCharacter.objects.create(
|
EveCharacter.objects.create(
|
||||||
character_id='1234',
|
character_id='1234',
|
||||||
character_name='character.name',
|
character_name='character.name',
|
||||||
corporation_id='character.corp.id',
|
corporation_id='character.corp.id',
|
||||||
corporation_name='character.corp.name',
|
corporation_name='character.corp.name',
|
||||||
corporation_ticker='character.corp.ticker',
|
corporation_ticker='abc',
|
||||||
alliance_id='character.alliance.id',
|
alliance_id='character.alliance.id',
|
||||||
alliance_name='character.alliance.name',
|
alliance_name='character.alliance.name',
|
||||||
)
|
)
|
||||||
|
|
||||||
expected = self.TestCharacter(
|
expected = self.TestCharacter(
|
||||||
id='1234',
|
id='1234', name='Test Character', corp_id='2345', alliance_id='3456'
|
||||||
name='Test Character',
|
|
||||||
corp_id='2345',
|
|
||||||
alliance_id='3456'
|
|
||||||
)
|
)
|
||||||
|
|
||||||
provider.get_character.return_value = expected
|
provider.get_character.return_value = expected
|
||||||
|
|
||||||
result = EveCharacter.objects.update_character('1234')
|
result = EveCharacter.objects.update_character('1234')
|
||||||
@ -94,7 +90,7 @@ class EveCharacterManagerTestCase(TestCase):
|
|||||||
character_name='character.name',
|
character_name='character.name',
|
||||||
corporation_id='character.corp.id',
|
corporation_id='character.corp.id',
|
||||||
corporation_name='character.corp.name',
|
corporation_name='character.corp.name',
|
||||||
corporation_ticker='character.corp.ticker',
|
corporation_ticker='abc',
|
||||||
alliance_id='character.alliance.id',
|
alliance_id='character.alliance.id',
|
||||||
alliance_name='character.alliance.name',
|
alliance_name='character.alliance.name',
|
||||||
)
|
)
|
||||||
@ -271,7 +267,7 @@ class EveCorporationManagerTestCase(TestCase):
|
|||||||
EveCorporationInfo.objects.create(
|
EveCorporationInfo.objects.create(
|
||||||
corporation_id='2345',
|
corporation_id='2345',
|
||||||
corporation_name='corp.name',
|
corporation_name='corp.name',
|
||||||
corporation_ticker='corp.ticker',
|
corporation_ticker='abc',
|
||||||
member_count=10,
|
member_count=10,
|
||||||
alliance=None,
|
alliance=None,
|
||||||
)
|
)
|
||||||
|
@ -2,103 +2,13 @@ from unittest.mock import Mock, patch
|
|||||||
|
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
|
|
||||||
from ..models import EveCharacter, EveCorporationInfo, \
|
from ..models import (
|
||||||
EveAllianceInfo, _eve_entity_image_url
|
EveCharacter, EveCorporationInfo, EveAllianceInfo
|
||||||
|
)
|
||||||
from ..providers import Alliance, Corporation, Character
|
from ..providers import Alliance, Corporation, Character
|
||||||
|
from ..evelinks import eveimageserver
|
||||||
|
|
||||||
|
|
||||||
class EveUniverseImageUrlTestCase(TestCase):
|
|
||||||
"""unit test for _eve_entity_image_url()"""
|
|
||||||
|
|
||||||
def test_sizes(self):
|
|
||||||
self.assertEqual(
|
|
||||||
_eve_entity_image_url('character', 42),
|
|
||||||
'https://images.evetech.net/characters/42/portrait?size=32'
|
|
||||||
)
|
|
||||||
self.assertEqual(
|
|
||||||
_eve_entity_image_url('character', 42, size=32),
|
|
||||||
'https://images.evetech.net/characters/42/portrait?size=32'
|
|
||||||
)
|
|
||||||
self.assertEqual(
|
|
||||||
_eve_entity_image_url('character', 42, size=64),
|
|
||||||
'https://images.evetech.net/characters/42/portrait?size=64'
|
|
||||||
)
|
|
||||||
self.assertEqual(
|
|
||||||
_eve_entity_image_url('character', 42, size=128),
|
|
||||||
'https://images.evetech.net/characters/42/portrait?size=128'
|
|
||||||
)
|
|
||||||
self.assertEqual(
|
|
||||||
_eve_entity_image_url('character', 42, size=256),
|
|
||||||
'https://images.evetech.net/characters/42/portrait?size=256'
|
|
||||||
)
|
|
||||||
self.assertEqual(
|
|
||||||
_eve_entity_image_url('character', 42, size=512),
|
|
||||||
'https://images.evetech.net/characters/42/portrait?size=512'
|
|
||||||
)
|
|
||||||
self.assertEqual(
|
|
||||||
_eve_entity_image_url('character', 42, size=1024),
|
|
||||||
'https://images.evetech.net/characters/42/portrait?size=1024'
|
|
||||||
)
|
|
||||||
with self.assertRaises(ValueError):
|
|
||||||
_eve_entity_image_url('corporation', 42, size=-5)
|
|
||||||
|
|
||||||
with self.assertRaises(ValueError):
|
|
||||||
_eve_entity_image_url('corporation', 42, size=0)
|
|
||||||
|
|
||||||
with self.assertRaises(ValueError):
|
|
||||||
_eve_entity_image_url('corporation', 42, size=31)
|
|
||||||
|
|
||||||
with self.assertRaises(ValueError):
|
|
||||||
_eve_entity_image_url('corporation', 42, size=1025)
|
|
||||||
|
|
||||||
with self.assertRaises(ValueError):
|
|
||||||
_eve_entity_image_url('corporation', 42, size=2048)
|
|
||||||
|
|
||||||
|
|
||||||
def test_variant(self):
|
|
||||||
self.assertEqual(
|
|
||||||
_eve_entity_image_url('character', 42, variant='portrait'),
|
|
||||||
'https://images.evetech.net/characters/42/portrait?size=32'
|
|
||||||
)
|
|
||||||
self.assertEqual(
|
|
||||||
_eve_entity_image_url('alliance', 42, variant='logo'),
|
|
||||||
'https://images.evetech.net/alliances/42/logo?size=32'
|
|
||||||
)
|
|
||||||
with self.assertRaises(ValueError):
|
|
||||||
_eve_entity_image_url('character', 42, variant='logo')
|
|
||||||
|
|
||||||
|
|
||||||
def test_alliance(self):
|
|
||||||
|
|
||||||
self.assertEqual(
|
|
||||||
_eve_entity_image_url('alliance', 42),
|
|
||||||
'https://images.evetech.net/alliances/42/logo?size=32'
|
|
||||||
)
|
|
||||||
self.assertEqual(
|
|
||||||
_eve_entity_image_url('corporation', 42),
|
|
||||||
'https://images.evetech.net/corporations/42/logo?size=32'
|
|
||||||
)
|
|
||||||
self.assertEqual(
|
|
||||||
_eve_entity_image_url('character', 42),
|
|
||||||
'https://images.evetech.net/characters/42/portrait?size=32'
|
|
||||||
)
|
|
||||||
with self.assertRaises(ValueError):
|
|
||||||
_eve_entity_image_url('station', 42)
|
|
||||||
|
|
||||||
|
|
||||||
def test_tenants(self):
|
|
||||||
self.assertEqual(
|
|
||||||
_eve_entity_image_url('character', 42, tenant='tranquility'),
|
|
||||||
'https://images.evetech.net/characters/42/portrait?size=32&tenant=tranquility'
|
|
||||||
)
|
|
||||||
self.assertEqual(
|
|
||||||
_eve_entity_image_url('character', 42, tenant='singularity'),
|
|
||||||
'https://images.evetech.net/characters/42/portrait?size=32&tenant=singularity'
|
|
||||||
)
|
|
||||||
with self.assertRaises(ValueError):
|
|
||||||
_eve_entity_image_url('character', 42, tenant='xxx')
|
|
||||||
|
|
||||||
|
|
||||||
class EveCharacterTestCase(TestCase):
|
class EveCharacterTestCase(TestCase):
|
||||||
def test_corporation_prop(self):
|
def test_corporation_prop(self):
|
||||||
"""
|
"""
|
||||||
@ -109,7 +19,7 @@ class EveCharacterTestCase(TestCase):
|
|||||||
character_name='character.name',
|
character_name='character.name',
|
||||||
corporation_id='2345',
|
corporation_id='2345',
|
||||||
corporation_name='character.corp.name',
|
corporation_name='character.corp.name',
|
||||||
corporation_ticker='character.corp.ticker',
|
corporation_ticker='abc',
|
||||||
alliance_id='character.alliance.id',
|
alliance_id='character.alliance.id',
|
||||||
alliance_name='character.alliance.name',
|
alliance_name='character.alliance.name',
|
||||||
)
|
)
|
||||||
@ -117,7 +27,7 @@ class EveCharacterTestCase(TestCase):
|
|||||||
expected = EveCorporationInfo.objects.create(
|
expected = EveCorporationInfo.objects.create(
|
||||||
corporation_id='2345',
|
corporation_id='2345',
|
||||||
corporation_name='corp.name',
|
corporation_name='corp.name',
|
||||||
corporation_ticker='corp.ticker',
|
corporation_ticker='abc',
|
||||||
member_count=10,
|
member_count=10,
|
||||||
alliance=None,
|
alliance=None,
|
||||||
)
|
)
|
||||||
@ -125,7 +35,7 @@ class EveCharacterTestCase(TestCase):
|
|||||||
incorrect = EveCorporationInfo.objects.create(
|
incorrect = EveCorporationInfo.objects.create(
|
||||||
corporation_id='9999',
|
corporation_id='9999',
|
||||||
corporation_name='corp.name1',
|
corporation_name='corp.name1',
|
||||||
corporation_ticker='corp.ticker1',
|
corporation_ticker='abc1',
|
||||||
member_count=10,
|
member_count=10,
|
||||||
alliance=None,
|
alliance=None,
|
||||||
)
|
)
|
||||||
@ -143,13 +53,13 @@ class EveCharacterTestCase(TestCase):
|
|||||||
character_name='character.name',
|
character_name='character.name',
|
||||||
corporation_id='2345',
|
corporation_id='2345',
|
||||||
corporation_name='character.corp.name',
|
corporation_name='character.corp.name',
|
||||||
corporation_ticker='character.corp.ticker',
|
corporation_ticker='abc',
|
||||||
alliance_id='character.alliance.id',
|
alliance_id='character.alliance.id',
|
||||||
alliance_name='character.alliance.name',
|
alliance_name='character.alliance.name',
|
||||||
)
|
)
|
||||||
|
|
||||||
with self.assertRaises(EveCorporationInfo.DoesNotExist):
|
with self.assertRaises(EveCorporationInfo.DoesNotExist):
|
||||||
result = character.corporation
|
character.corporation
|
||||||
|
|
||||||
def test_alliance_prop(self):
|
def test_alliance_prop(self):
|
||||||
"""
|
"""
|
||||||
@ -160,7 +70,7 @@ class EveCharacterTestCase(TestCase):
|
|||||||
character_name='character.name',
|
character_name='character.name',
|
||||||
corporation_id='2345',
|
corporation_id='2345',
|
||||||
corporation_name='character.corp.name',
|
corporation_name='character.corp.name',
|
||||||
corporation_ticker='character.corp.ticker',
|
corporation_ticker='abc',
|
||||||
alliance_id='3456',
|
alliance_id='3456',
|
||||||
alliance_name='character.alliance.name',
|
alliance_name='character.alliance.name',
|
||||||
)
|
)
|
||||||
@ -192,13 +102,13 @@ class EveCharacterTestCase(TestCase):
|
|||||||
character_name='character.name',
|
character_name='character.name',
|
||||||
corporation_id='2345',
|
corporation_id='2345',
|
||||||
corporation_name='character.corp.name',
|
corporation_name='character.corp.name',
|
||||||
corporation_ticker='character.corp.ticker',
|
corporation_ticker='abc',
|
||||||
alliance_id='3456',
|
alliance_id='3456',
|
||||||
alliance_name='character.alliance.name',
|
alliance_name='character.alliance.name',
|
||||||
)
|
)
|
||||||
|
|
||||||
with self.assertRaises(EveAllianceInfo.DoesNotExist):
|
with self.assertRaises(EveAllianceInfo.DoesNotExist):
|
||||||
result = character.alliance
|
character.alliance
|
||||||
|
|
||||||
def test_alliance_prop_none(self):
|
def test_alliance_prop_none(self):
|
||||||
"""
|
"""
|
||||||
@ -209,7 +119,7 @@ class EveCharacterTestCase(TestCase):
|
|||||||
character_name='character.name',
|
character_name='character.name',
|
||||||
corporation_id='2345',
|
corporation_id='2345',
|
||||||
corporation_name='character.corp.name',
|
corporation_name='character.corp.name',
|
||||||
corporation_ticker='character.corp.ticker',
|
corporation_ticker='abc',
|
||||||
alliance_id=None,
|
alliance_id=None,
|
||||||
alliance_name=None,
|
alliance_name=None,
|
||||||
)
|
)
|
||||||
@ -244,15 +154,14 @@ class EveCharacterTestCase(TestCase):
|
|||||||
|
|
||||||
# todo: add test cases not yet covered, e.g. with alliance
|
# todo: add test cases not yet covered, e.g. with alliance
|
||||||
|
|
||||||
|
|
||||||
def test_image_url(self):
|
def test_image_url(self):
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
EveCharacter.generic_portrait_url(42),
|
EveCharacter.generic_portrait_url(42),
|
||||||
_eve_entity_image_url('character', 42)
|
eveimageserver._eve_entity_image_url('character', 42)
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
EveCharacter.generic_portrait_url(42, 256),
|
EveCharacter.generic_portrait_url(42, 256),
|
||||||
_eve_entity_image_url('character', 42, 256)
|
eveimageserver._eve_entity_image_url('character', 42, 256)
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_portrait_urls(self):
|
def test_portrait_urls(self):
|
||||||
@ -265,30 +174,29 @@ class EveCharacterTestCase(TestCase):
|
|||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
x.portrait_url(),
|
x.portrait_url(),
|
||||||
_eve_entity_image_url('character', 42)
|
eveimageserver._eve_entity_image_url('character', 42)
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
x.portrait_url(64),
|
x.portrait_url(64),
|
||||||
_eve_entity_image_url('character', 42, size=64)
|
eveimageserver._eve_entity_image_url('character', 42, size=64)
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
x.portrait_url_32,
|
x.portrait_url_32,
|
||||||
_eve_entity_image_url('character', 42, size=32)
|
eveimageserver._eve_entity_image_url('character', 42, size=32)
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
x.portrait_url_64,
|
x.portrait_url_64,
|
||||||
_eve_entity_image_url('character', 42, size=64)
|
eveimageserver._eve_entity_image_url('character', 42, size=64)
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
x.portrait_url_128,
|
x.portrait_url_128,
|
||||||
_eve_entity_image_url('character', 42, size=128)
|
eveimageserver._eve_entity_image_url('character', 42, size=128)
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
x.portrait_url_256,
|
x.portrait_url_256,
|
||||||
_eve_entity_image_url('character', 42, size=256)
|
eveimageserver._eve_entity_image_url('character', 42, size=256)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_corporation_logo_urls(self):
|
def test_corporation_logo_urls(self):
|
||||||
x = EveCharacter(
|
x = EveCharacter(
|
||||||
character_id='42',
|
character_id='42',
|
||||||
@ -299,30 +207,29 @@ class EveCharacterTestCase(TestCase):
|
|||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
x.corporation_logo_url(),
|
x.corporation_logo_url(),
|
||||||
_eve_entity_image_url('corporation', 123)
|
eveimageserver._eve_entity_image_url('corporation', 123)
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
x.corporation_logo_url(256),
|
x.corporation_logo_url(256),
|
||||||
_eve_entity_image_url('corporation', 123, size=256)
|
eveimageserver._eve_entity_image_url('corporation', 123, size=256)
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
x.corporation_logo_url_32,
|
x.corporation_logo_url_32,
|
||||||
_eve_entity_image_url('corporation', 123, size=32)
|
eveimageserver._eve_entity_image_url('corporation', 123, size=32)
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
x.corporation_logo_url_64,
|
x.corporation_logo_url_64,
|
||||||
_eve_entity_image_url('corporation', 123, size=64)
|
eveimageserver._eve_entity_image_url('corporation', 123, size=64)
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
x.corporation_logo_url_128,
|
x.corporation_logo_url_128,
|
||||||
_eve_entity_image_url('corporation', 123, size=128)
|
eveimageserver._eve_entity_image_url('corporation', 123, size=128)
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
x.corporation_logo_url_256,
|
x.corporation_logo_url_256,
|
||||||
_eve_entity_image_url('corporation', 123, size=256)
|
eveimageserver._eve_entity_image_url('corporation', 123, size=256)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_alliance_logo_urls(self):
|
def test_alliance_logo_urls(self):
|
||||||
x = EveCharacter(
|
x = EveCharacter(
|
||||||
character_id='42',
|
character_id='42',
|
||||||
@ -354,27 +261,27 @@ class EveCharacterTestCase(TestCase):
|
|||||||
x.alliance_id = 987
|
x.alliance_id = 987
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
x.alliance_logo_url(),
|
x.alliance_logo_url(),
|
||||||
_eve_entity_image_url('alliance', 987)
|
eveimageserver._eve_entity_image_url('alliance', 987)
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
x.alliance_logo_url(128),
|
x.alliance_logo_url(128),
|
||||||
_eve_entity_image_url('alliance', 987, size=128)
|
eveimageserver._eve_entity_image_url('alliance', 987, size=128)
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
x.alliance_logo_url_32,
|
x.alliance_logo_url_32,
|
||||||
_eve_entity_image_url('alliance', 987, size=32)
|
eveimageserver._eve_entity_image_url('alliance', 987, size=32)
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
x.alliance_logo_url_64,
|
x.alliance_logo_url_64,
|
||||||
_eve_entity_image_url('alliance', 987, size=64)
|
eveimageserver._eve_entity_image_url('alliance', 987, size=64)
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
x.alliance_logo_url_128,
|
x.alliance_logo_url_128,
|
||||||
_eve_entity_image_url('alliance', 987, size=128)
|
eveimageserver._eve_entity_image_url('alliance', 987, size=128)
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
x.alliance_logo_url_256,
|
x.alliance_logo_url_256,
|
||||||
_eve_entity_image_url('alliance', 987, size=256)
|
eveimageserver._eve_entity_image_url('alliance', 987, size=256)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -456,7 +363,6 @@ class EveAllianceTestCase(TestCase):
|
|||||||
# potential bug
|
# potential bug
|
||||||
# update_alliance() is only updateting executor_corp_id when object is given
|
# update_alliance() is only updateting executor_corp_id when object is given
|
||||||
|
|
||||||
|
|
||||||
def test_update_alliance_wo_object(self):
|
def test_update_alliance_wo_object(self):
|
||||||
mock_EveAllianceProviderManager = Mock()
|
mock_EveAllianceProviderManager = Mock()
|
||||||
mock_EveAllianceProviderManager.get_alliance.return_value = \
|
mock_EveAllianceProviderManager.get_alliance.return_value = \
|
||||||
@ -475,11 +381,11 @@ class EveAllianceTestCase(TestCase):
|
|||||||
)
|
)
|
||||||
my_alliance.provider = mock_EveAllianceProviderManager
|
my_alliance.provider = mock_EveAllianceProviderManager
|
||||||
my_alliance.save()
|
my_alliance.save()
|
||||||
updated_alliance = Alliance(
|
Alliance(
|
||||||
name='Dummy Alliance 2',
|
name='Dummy Alliance 2',
|
||||||
corp_ids=[2004],
|
corp_ids=[2004],
|
||||||
executor_corp_id=2004
|
executor_corp_id=2004
|
||||||
)
|
)
|
||||||
my_alliance.update_alliance()
|
my_alliance.update_alliance()
|
||||||
my_alliance.refresh_from_db()
|
my_alliance.refresh_from_db()
|
||||||
self.assertEqual(int(my_alliance.executor_corp_id), 2004)
|
self.assertEqual(int(my_alliance.executor_corp_id), 2004)
|
||||||
@ -487,15 +393,14 @@ class EveAllianceTestCase(TestCase):
|
|||||||
# potential bug
|
# potential bug
|
||||||
# update_alliance() is only updateting executor_corp_id nothing else ???
|
# update_alliance() is only updateting executor_corp_id nothing else ???
|
||||||
|
|
||||||
|
|
||||||
def test_image_url(self):
|
def test_image_url(self):
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
EveAllianceInfo.generic_logo_url(42),
|
EveAllianceInfo.generic_logo_url(42),
|
||||||
_eve_entity_image_url('alliance', 42)
|
eveimageserver._eve_entity_image_url('alliance', 42)
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
EveAllianceInfo.generic_logo_url(42, 256),
|
EveAllianceInfo.generic_logo_url(42, 256),
|
||||||
_eve_entity_image_url('alliance', 42, 256)
|
eveimageserver._eve_entity_image_url('alliance', 42, 256)
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_logo_url(self):
|
def test_logo_url(self):
|
||||||
@ -563,9 +468,7 @@ class EveCorporationTestCase(TestCase):
|
|||||||
|
|
||||||
def test_update_corporation_no_object_w_alliance(self):
|
def test_update_corporation_no_object_w_alliance(self):
|
||||||
mock_provider = Mock()
|
mock_provider = Mock()
|
||||||
mock_provider.get_corporation.return_value = Corporation(
|
mock_provider.get_corporation.return_value = Corporation(members=87)
|
||||||
members=87
|
|
||||||
)
|
|
||||||
self.my_corp.provider = mock_provider
|
self.my_corp.provider = mock_provider
|
||||||
|
|
||||||
self.my_corp.update_corporation()
|
self.my_corp.update_corporation()
|
||||||
@ -585,15 +488,14 @@ class EveCorporationTestCase(TestCase):
|
|||||||
self.assertEqual(my_corp2.member_count, 8)
|
self.assertEqual(my_corp2.member_count, 8)
|
||||||
self.assertIsNone(my_corp2.alliance)
|
self.assertIsNone(my_corp2.alliance)
|
||||||
|
|
||||||
|
|
||||||
def test_image_url(self):
|
def test_image_url(self):
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
EveCorporationInfo.generic_logo_url(42),
|
EveCorporationInfo.generic_logo_url(42),
|
||||||
_eve_entity_image_url('corporation', 42)
|
eveimageserver._eve_entity_image_url('corporation', 42)
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
EveCorporationInfo.generic_logo_url(42, 256),
|
EveCorporationInfo.generic_logo_url(42, 256),
|
||||||
_eve_entity_image_url('corporation', 42, 256)
|
eveimageserver._eve_entity_image_url('corporation', 42, 256)
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_logo_url(self):
|
def test_logo_url(self):
|
||||||
@ -621,4 +523,3 @@ class EveCorporationTestCase(TestCase):
|
|||||||
self.my_corp.logo_url_256,
|
self.my_corp.logo_url_256,
|
||||||
'https://images.evetech.net/corporations/2001/logo?size=256'
|
'https://images.evetech.net/corporations/2001/logo?size=256'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1,21 +1,28 @@
|
|||||||
import os
|
import os
|
||||||
from unittest.mock import Mock, patch
|
from unittest.mock import Mock, patch
|
||||||
|
|
||||||
from bravado.exception import HTTPNotFound, HTTPUnprocessableEntity
|
from bravado.exception import HTTPNotFound
|
||||||
from jsonschema.exceptions import RefResolutionError
|
from jsonschema.exceptions import RefResolutionError
|
||||||
|
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
|
|
||||||
from . import set_logger
|
from . import set_logger
|
||||||
from ..models import EveCharacter, EveCorporationInfo, EveAllianceInfo
|
from ..providers import (
|
||||||
from ..providers import ObjectNotFound, Entity, Character, Corporation, \
|
ObjectNotFound,
|
||||||
Alliance, ItemType, EveProvider, EveSwaggerProvider
|
Entity,
|
||||||
|
Character,
|
||||||
|
Corporation,
|
||||||
|
Alliance,
|
||||||
|
ItemType,
|
||||||
|
EveProvider,
|
||||||
|
EveSwaggerProvider
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
MODULE_PATH = 'allianceauth.eveonline.providers'
|
MODULE_PATH = 'allianceauth.eveonline.providers'
|
||||||
SWAGGER_OLD_SPEC_PATH = os.path.join(os.path.dirname(
|
SWAGGER_OLD_SPEC_PATH = os.path.join(os.path.dirname(
|
||||||
os.path.abspath(__file__)), 'swagger_old.json'
|
os.path.abspath(__file__)), 'swagger_old.json'
|
||||||
)
|
)
|
||||||
set_logger(MODULE_PATH, __file__)
|
set_logger(MODULE_PATH, __file__)
|
||||||
|
|
||||||
|
|
||||||
@ -51,7 +58,6 @@ class TestEntity(TestCase):
|
|||||||
x = Entity()
|
x = Entity()
|
||||||
self.assertEqual(repr(x), '<Entity (None): None>')
|
self.assertEqual(repr(x), '<Entity (None): None>')
|
||||||
|
|
||||||
|
|
||||||
def test_bool(self):
|
def test_bool(self):
|
||||||
x = Entity(1001)
|
x = Entity(1001)
|
||||||
self.assertTrue(bool(x))
|
self.assertTrue(bool(x))
|
||||||
@ -99,7 +105,6 @@ class TestCorporation(TestCase):
|
|||||||
# should fetch alliance once only
|
# should fetch alliance once only
|
||||||
self.assertEqual(mock_provider_get_alliance.call_count, 1)
|
self.assertEqual(mock_provider_get_alliance.call_count, 1)
|
||||||
|
|
||||||
|
|
||||||
@patch(MODULE_PATH + '.EveSwaggerProvider.get_alliance')
|
@patch(MODULE_PATH + '.EveSwaggerProvider.get_alliance')
|
||||||
def test_alliance_not_defined(self, mock_provider_get_alliance):
|
def test_alliance_not_defined(self, mock_provider_get_alliance):
|
||||||
mock_provider_get_alliance.return_value = None
|
mock_provider_get_alliance.return_value = None
|
||||||
@ -110,7 +115,6 @@ class TestCorporation(TestCase):
|
|||||||
Entity(None, None)
|
Entity(None, None)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@patch(MODULE_PATH + '.EveSwaggerProvider.get_character')
|
@patch(MODULE_PATH + '.EveSwaggerProvider.get_character')
|
||||||
def test_ceo(self, mock_provider_get_character):
|
def test_ceo(self, mock_provider_get_character):
|
||||||
my_ceo = Character(
|
my_ceo = Character(
|
||||||
@ -200,7 +204,6 @@ class TestAlliance(TestCase):
|
|||||||
# should be called once by used corp only
|
# should be called once by used corp only
|
||||||
self.assertEqual(mock_provider_get_corp.call_count, 2)
|
self.assertEqual(mock_provider_get_corp.call_count, 2)
|
||||||
|
|
||||||
|
|
||||||
@patch(MODULE_PATH + '.EveSwaggerProvider.get_corp')
|
@patch(MODULE_PATH + '.EveSwaggerProvider.get_corp')
|
||||||
def test_corps(self, mock_provider_get_corp):
|
def test_corps(self, mock_provider_get_corp):
|
||||||
mock_provider_get_corp.side_effect = TestAlliance._get_corp
|
mock_provider_get_corp.side_effect = TestAlliance._get_corp
|
||||||
@ -253,7 +256,6 @@ class TestCharacter(TestCase):
|
|||||||
|
|
||||||
# should call the provider one time only
|
# should call the provider one time only
|
||||||
self.assertEqual(mock_provider_get_corp.call_count, 1)
|
self.assertEqual(mock_provider_get_corp.call_count, 1)
|
||||||
|
|
||||||
|
|
||||||
@patch(MODULE_PATH + '.EveSwaggerProvider.get_alliance')
|
@patch(MODULE_PATH + '.EveSwaggerProvider.get_alliance')
|
||||||
@patch(MODULE_PATH + '.EveSwaggerProvider.get_corp')
|
@patch(MODULE_PATH + '.EveSwaggerProvider.get_corp')
|
||||||
@ -283,7 +285,6 @@ class TestCharacter(TestCase):
|
|||||||
self.assertEqual(mock_provider_get_corp.call_count, 1)
|
self.assertEqual(mock_provider_get_corp.call_count, 1)
|
||||||
self.assertEqual(mock_provider_get_alliance.call_count, 1)
|
self.assertEqual(mock_provider_get_alliance.call_count, 1)
|
||||||
|
|
||||||
|
|
||||||
def test_alliance_has_none(self):
|
def test_alliance_has_none(self):
|
||||||
self.my_character.alliance_id = None
|
self.my_character.alliance_id = None
|
||||||
self.assertEqual(self.my_character.alliance, Entity(None, None))
|
self.assertEqual(self.my_character.alliance, Entity(None, None))
|
||||||
@ -343,7 +344,6 @@ class TestEveSwaggerProvider(TestCase):
|
|||||||
else:
|
else:
|
||||||
raise HTTPNotFound(Mock())
|
raise HTTPNotFound(Mock())
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def esi_get_alliances_alliance_id_corporations(alliance_id):
|
def esi_get_alliances_alliance_id_corporations(alliance_id):
|
||||||
alliances = {
|
alliances = {
|
||||||
@ -357,7 +357,6 @@ class TestEveSwaggerProvider(TestCase):
|
|||||||
else:
|
else:
|
||||||
raise HTTPNotFound(Mock())
|
raise HTTPNotFound(Mock())
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def esi_get_corporations_corporation_id(corporation_id):
|
def esi_get_corporations_corporation_id(corporation_id):
|
||||||
corporations = {
|
corporations = {
|
||||||
@ -382,7 +381,6 @@ class TestEveSwaggerProvider(TestCase):
|
|||||||
else:
|
else:
|
||||||
raise HTTPNotFound(Mock())
|
raise HTTPNotFound(Mock())
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def esi_get_characters_character_id(character_id):
|
def esi_get_characters_character_id(character_id):
|
||||||
characters = {
|
characters = {
|
||||||
@ -403,7 +401,6 @@ class TestEveSwaggerProvider(TestCase):
|
|||||||
else:
|
else:
|
||||||
raise HTTPNotFound(Mock())
|
raise HTTPNotFound(Mock())
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def esi_post_characters_affiliation(characters):
|
def esi_post_characters_affiliation(characters):
|
||||||
character_data = {
|
character_data = {
|
||||||
@ -428,7 +425,6 @@ class TestEveSwaggerProvider(TestCase):
|
|||||||
else:
|
else:
|
||||||
raise TypeError()
|
raise TypeError()
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def esi_get_universe_types_type_id(type_id):
|
def esi_get_universe_types_type_id(type_id):
|
||||||
types = {
|
types = {
|
||||||
@ -446,13 +442,11 @@ class TestEveSwaggerProvider(TestCase):
|
|||||||
else:
|
else:
|
||||||
raise HTTPNotFound(Mock())
|
raise HTTPNotFound(Mock())
|
||||||
|
|
||||||
|
|
||||||
@patch(MODULE_PATH + '.esi_client_factory')
|
@patch(MODULE_PATH + '.esi_client_factory')
|
||||||
def test_str(self, mock_esi_client_factory):
|
def test_str(self, mock_esi_client_factory):
|
||||||
my_provider = EveSwaggerProvider()
|
my_provider = EveSwaggerProvider()
|
||||||
self.assertEqual(str(my_provider), 'esi')
|
self.assertEqual(str(my_provider), 'esi')
|
||||||
|
|
||||||
|
|
||||||
@patch(MODULE_PATH + '.esi_client_factory')
|
@patch(MODULE_PATH + '.esi_client_factory')
|
||||||
def test_get_alliance(self, mock_esi_client_factory):
|
def test_get_alliance(self, mock_esi_client_factory):
|
||||||
mock_esi_client_factory.return_value\
|
mock_esi_client_factory.return_value\
|
||||||
@ -481,7 +475,6 @@ class TestEveSwaggerProvider(TestCase):
|
|||||||
with self.assertRaises(ObjectNotFound):
|
with self.assertRaises(ObjectNotFound):
|
||||||
my_provider.get_alliance(3999)
|
my_provider.get_alliance(3999)
|
||||||
|
|
||||||
|
|
||||||
@patch(MODULE_PATH + '.esi_client_factory')
|
@patch(MODULE_PATH + '.esi_client_factory')
|
||||||
def test_get_corp(self, mock_esi_client_factory):
|
def test_get_corp(self, mock_esi_client_factory):
|
||||||
mock_esi_client_factory.return_value\
|
mock_esi_client_factory.return_value\
|
||||||
@ -508,7 +501,6 @@ class TestEveSwaggerProvider(TestCase):
|
|||||||
with self.assertRaises(ObjectNotFound):
|
with self.assertRaises(ObjectNotFound):
|
||||||
my_provider.get_corp(2999)
|
my_provider.get_corp(2999)
|
||||||
|
|
||||||
|
|
||||||
@patch(MODULE_PATH + '.esi_client_factory')
|
@patch(MODULE_PATH + '.esi_client_factory')
|
||||||
def test_get_character(self, mock_esi_client_factory):
|
def test_get_character(self, mock_esi_client_factory):
|
||||||
mock_esi_client_factory.return_value\
|
mock_esi_client_factory.return_value\
|
||||||
@ -536,7 +528,6 @@ class TestEveSwaggerProvider(TestCase):
|
|||||||
with self.assertRaises(ObjectNotFound):
|
with self.assertRaises(ObjectNotFound):
|
||||||
my_provider.get_character(1999)
|
my_provider.get_character(1999)
|
||||||
|
|
||||||
|
|
||||||
@patch(MODULE_PATH + '.esi_client_factory')
|
@patch(MODULE_PATH + '.esi_client_factory')
|
||||||
def test_get_itemtype(self, mock_esi_client_factory):
|
def test_get_itemtype(self, mock_esi_client_factory):
|
||||||
mock_esi_client_factory.return_value\
|
mock_esi_client_factory.return_value\
|
||||||
@ -601,5 +592,3 @@ class TestEveSwaggerProvider(TestCase):
|
|||||||
self.assertTrue(mock_esi_client_factory.called)
|
self.assertTrue(mock_esi_client_factory.called)
|
||||||
self.assertIsNotNone(my_provider._client)
|
self.assertIsNotNone(my_provider._client)
|
||||||
self.assertEqual(my_client, 'my_client')
|
self.assertEqual(my_client, 'my_client')
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,10 +1,14 @@
|
|||||||
from unittest.mock import patch, Mock
|
from unittest.mock import patch
|
||||||
|
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
|
|
||||||
from ..models import EveCharacter, EveCorporationInfo, EveAllianceInfo
|
from ..models import EveCharacter, EveCorporationInfo, EveAllianceInfo
|
||||||
from ..tasks import update_alliance, update_corp, update_character, \
|
from ..tasks import (
|
||||||
|
update_alliance,
|
||||||
|
update_corp,
|
||||||
|
update_character,
|
||||||
run_model_update
|
run_model_update
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class TestTasks(TestCase):
|
class TestTasks(TestCase):
|
||||||
@ -13,42 +17,33 @@ class TestTasks(TestCase):
|
|||||||
def test_update_corp(self, mock_EveCorporationInfo):
|
def test_update_corp(self, mock_EveCorporationInfo):
|
||||||
update_corp(42)
|
update_corp(42)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
mock_EveCorporationInfo.objects.update_corporation.call_count,
|
mock_EveCorporationInfo.objects.update_corporation.call_count, 1
|
||||||
1
|
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
mock_EveCorporationInfo.objects.update_corporation.call_args[0][0],
|
mock_EveCorporationInfo.objects.update_corporation.call_args[0][0], 42
|
||||||
42
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@patch('allianceauth.eveonline.tasks.EveAllianceInfo')
|
@patch('allianceauth.eveonline.tasks.EveAllianceInfo')
|
||||||
def test_update_alliance(self, mock_EveAllianceInfo):
|
def test_update_alliance(self, mock_EveAllianceInfo):
|
||||||
update_alliance(42)
|
update_alliance(42)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
mock_EveAllianceInfo.objects.update_alliance.call_args[0][0],
|
mock_EveAllianceInfo.objects.update_alliance.call_args[0][0], 42
|
||||||
42
|
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
mock_EveAllianceInfo.objects\
|
mock_EveAllianceInfo.objects
|
||||||
.update_alliance.return_value.populate_alliance.call_count,
|
.update_alliance.return_value.populate_alliance.call_count, 1
|
||||||
1
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@patch('allianceauth.eveonline.tasks.EveCharacter')
|
@patch('allianceauth.eveonline.tasks.EveCharacter')
|
||||||
def test_update_character(self, mock_EveCharacter):
|
def test_update_character(self, mock_EveCharacter):
|
||||||
update_character(42)
|
update_character(42)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
mock_EveCharacter.objects.update_character.call_count,
|
mock_EveCharacter.objects.update_character.call_count, 1
|
||||||
1
|
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
mock_EveCharacter.objects.update_character.call_args[0][0],
|
mock_EveCharacter.objects.update_character.call_args[0][0], 42
|
||||||
42
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@patch('allianceauth.eveonline.tasks.update_character')
|
@patch('allianceauth.eveonline.tasks.update_character')
|
||||||
@patch('allianceauth.eveonline.tasks.update_alliance')
|
@patch('allianceauth.eveonline.tasks.update_alliance')
|
||||||
@patch('allianceauth.eveonline.tasks.update_corp')
|
@patch('allianceauth.eveonline.tasks.update_corp')
|
||||||
@ -89,22 +84,15 @@ class TestTasks(TestCase):
|
|||||||
|
|
||||||
self.assertEqual(mock_update_corp.apply_async.call_count, 1)
|
self.assertEqual(mock_update_corp.apply_async.call_count, 1)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
int(mock_update_corp.apply_async.call_args[1]['args'][0]),
|
int(mock_update_corp.apply_async.call_args[1]['args'][0]), 2345
|
||||||
2345
|
|
||||||
)
|
)
|
||||||
|
|
||||||
self.assertEqual(mock_update_alliance.apply_async.call_count, 1)
|
self.assertEqual(mock_update_alliance.apply_async.call_count, 1)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
int(mock_update_alliance.apply_async.call_args[1]['args'][0]),
|
int(mock_update_alliance.apply_async.call_args[1]['args'][0]), 3456
|
||||||
3456
|
|
||||||
)
|
)
|
||||||
|
|
||||||
self.assertEqual(mock_update_character.apply_async.call_count, 1)
|
self.assertEqual(mock_update_character.apply_async.call_count, 1)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
int(mock_update_character.apply_async.call_args[1]['args'][0]),
|
int(mock_update_character.apply_async.call_args[1]['args'][0]), 1234
|
||||||
1234
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -6,6 +6,13 @@ This package generates profile URLs for eve entities on 3rd party websites like
|
|||||||
|
|
||||||
Location: ``allianceauth.eveonline.evelinks``
|
Location: ``allianceauth.eveonline.evelinks``
|
||||||
|
|
||||||
|
eveimageserver
|
||||||
|
===============
|
||||||
|
|
||||||
|
.. automodule:: allianceauth.eveonline.evelinks.eveimageserver
|
||||||
|
:members:
|
||||||
|
:undoc-members:
|
||||||
|
|
||||||
dotlan
|
dotlan
|
||||||
===============
|
===============
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user