aa-intel-tool 2.6.1__py3-none-any.whl → 2.6.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- aa_intel_tool/__init__.py +1 -1
- aa_intel_tool/helper/eve_character.py +24 -36
- aa_intel_tool/helper/static_files.py +2 -2
- aa_intel_tool/locale/cs_CZ/LC_MESSAGES/django.po +9 -9
- aa_intel_tool/locale/de/LC_MESSAGES/django.mo +0 -0
- aa_intel_tool/locale/de/LC_MESSAGES/django.po +13 -13
- aa_intel_tool/locale/django.pot +10 -10
- aa_intel_tool/locale/es/LC_MESSAGES/django.po +9 -9
- aa_intel_tool/locale/fr_FR/LC_MESSAGES/django.mo +0 -0
- aa_intel_tool/locale/fr_FR/LC_MESSAGES/django.po +13 -13
- aa_intel_tool/locale/it_IT/LC_MESSAGES/django.po +9 -9
- aa_intel_tool/locale/ja/LC_MESSAGES/django.po +9 -9
- aa_intel_tool/locale/ko_KR/LC_MESSAGES/django.po +9 -9
- aa_intel_tool/locale/nl_NL/LC_MESSAGES/django.po +9 -9
- aa_intel_tool/locale/pl_PL/LC_MESSAGES/django.po +9 -9
- aa_intel_tool/locale/ru/LC_MESSAGES/django.mo +0 -0
- aa_intel_tool/locale/ru/LC_MESSAGES/django.po +13 -13
- aa_intel_tool/locale/sk/LC_MESSAGES/django.po +9 -9
- aa_intel_tool/locale/uk/LC_MESSAGES/django.mo +0 -0
- aa_intel_tool/locale/uk/LC_MESSAGES/django.po +15 -15
- aa_intel_tool/locale/zh_Hans/LC_MESSAGES/django.po +9 -9
- aa_intel_tool/parser/general.py +11 -16
- aa_intel_tool/parser/helper/db.py +8 -11
- aa_intel_tool/parser/module/chatlist.py +97 -126
- aa_intel_tool/parser/module/dscan.py +115 -147
- aa_intel_tool/parser/module/fleetcomp.py +85 -102
- aa_intel_tool/static/aa_intel_tool/css/aa-intel-tool.css +6 -19
- aa_intel_tool/static/aa_intel_tool/css/aa-intel-tool.min.css +1 -1
- aa_intel_tool/static/aa_intel_tool/css/aa-intel-tool.min.css.map +1 -1
- aa_intel_tool/static/aa_intel_tool/javascript/aa-intel-tool-chatscan-highlight.js +104 -64
- aa_intel_tool/static/aa_intel_tool/javascript/aa-intel-tool-chatscan-highlight.min.js.map +1 -1
- aa_intel_tool/static/aa_intel_tool/javascript/aa-intel-tool-chatscan.js +2 -2
- aa_intel_tool/static/aa_intel_tool/javascript/aa-intel-tool-chatscan.min.js +1 -1
- aa_intel_tool/static/aa_intel_tool/javascript/aa-intel-tool-dscan-highlight.js +43 -43
- aa_intel_tool/static/aa_intel_tool/javascript/aa-intel-tool-dscan-highlight.min.js.map +1 -1
- aa_intel_tool/static/aa_intel_tool/javascript/aa-intel-tool-dscan.js +31 -7
- aa_intel_tool/static/aa_intel_tool/javascript/aa-intel-tool-dscan.min.js +1 -1
- aa_intel_tool/static/aa_intel_tool/javascript/aa-intel-tool-dscan.min.js.map +1 -1
- aa_intel_tool/static/aa_intel_tool/javascript/aa-intel-tool-fleetcomposition-highlight.js +51 -51
- aa_intel_tool/static/aa_intel_tool/javascript/aa-intel-tool-fleetcomposition-highlight.min.js.map +1 -1
- aa_intel_tool/static/aa_intel_tool/javascript/aa-intel-tool-fleetcomposition.js +9 -3
- aa_intel_tool/static/aa_intel_tool/javascript/aa-intel-tool-fleetcomposition.min.js +1 -1
- aa_intel_tool/static/aa_intel_tool/javascript/aa-intel-tool-fleetcomposition.min.js.map +1 -1
- aa_intel_tool/static/aa_intel_tool/javascript/aa-intel-tool-scan-result-common.js +53 -31
- aa_intel_tool/static/aa_intel_tool/javascript/aa-intel-tool-scan-result-common.min.js +1 -1
- aa_intel_tool/static/aa_intel_tool/javascript/aa-intel-tool-scan-result-common.min.js.map +1 -1
- aa_intel_tool/templates/aa_intel_tool/partials/scan/evetime.html +1 -1
- aa_intel_tool/tests/test-data/dscan.txt +250 -0
- aa_intel_tool/tests/test_admin.py +50 -38
- aa_intel_tool/tests/test_helper_eve_character.py +405 -0
- aa_intel_tool/tests/test_models.py +188 -4
- aa_intel_tool/tests/test_parser_general.py +771 -0
- aa_intel_tool/tests/test_parser_module_chatlist.py +154 -0
- {aa_intel_tool-2.6.1.dist-info → aa_intel_tool-2.6.2.dist-info}/METADATA +1 -1
- {aa_intel_tool-2.6.1.dist-info → aa_intel_tool-2.6.2.dist-info}/RECORD +57 -55
- aa_intel_tool/tests/test_parser.py +0 -135
- {aa_intel_tool-2.6.1.dist-info → aa_intel_tool-2.6.2.dist-info}/WHEEL +0 -0
- {aa_intel_tool-2.6.1.dist-info → aa_intel_tool-2.6.2.dist-info}/licenses/LICENSE +0 -0
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Tests for the helper functions in the eve_character module.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
# Standard Library
|
|
6
|
+
from unittest.mock import Mock, patch
|
|
7
|
+
|
|
8
|
+
# Django
|
|
9
|
+
from django.test import TestCase
|
|
10
|
+
|
|
11
|
+
# Alliance Auth
|
|
12
|
+
from allianceauth.eveonline.models import (
|
|
13
|
+
EveAllianceInfo,
|
|
14
|
+
EveCharacter,
|
|
15
|
+
EveCorporationInfo,
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
# AA Intel Tool
|
|
19
|
+
from aa_intel_tool.helper.eve_character import (
|
|
20
|
+
_create_alliance,
|
|
21
|
+
_create_character,
|
|
22
|
+
_create_corporation,
|
|
23
|
+
get_or_create_character,
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class TestCreateAlliance(TestCase):
|
|
28
|
+
"""
|
|
29
|
+
Test the _create_alliance function.
|
|
30
|
+
"""
|
|
31
|
+
|
|
32
|
+
def test_creates_new_alliances(self):
|
|
33
|
+
"""
|
|
34
|
+
Test that new alliances are created when they do not exist in the database.
|
|
35
|
+
|
|
36
|
+
:return:
|
|
37
|
+
:rtype:
|
|
38
|
+
"""
|
|
39
|
+
|
|
40
|
+
alliance_ids = [1001, 1002, 1003]
|
|
41
|
+
|
|
42
|
+
with (
|
|
43
|
+
patch.object(
|
|
44
|
+
EveAllianceInfo.objects,
|
|
45
|
+
"filter",
|
|
46
|
+
return_value=EveAllianceInfo.objects.none(),
|
|
47
|
+
),
|
|
48
|
+
patch.object(
|
|
49
|
+
EveAllianceInfo.objects, "create_alliance"
|
|
50
|
+
) as mock_create_alliance,
|
|
51
|
+
):
|
|
52
|
+
_create_alliance(alliance_ids)
|
|
53
|
+
|
|
54
|
+
self.assertEqual(mock_create_alliance.call_count, 3)
|
|
55
|
+
|
|
56
|
+
def test_does_not_create_existing_alliances(self):
|
|
57
|
+
"""
|
|
58
|
+
Test that existing alliances are not created again.
|
|
59
|
+
|
|
60
|
+
:return:
|
|
61
|
+
:rtype:
|
|
62
|
+
"""
|
|
63
|
+
|
|
64
|
+
alliance_ids = [1001, 1002, 1003]
|
|
65
|
+
|
|
66
|
+
# Create existing alliances in the database
|
|
67
|
+
EveAllianceInfo.objects.create(
|
|
68
|
+
alliance_id=1001, alliance_name="Alliance 1001", executor_corp_id=2001
|
|
69
|
+
)
|
|
70
|
+
EveAllianceInfo.objects.create(
|
|
71
|
+
alliance_id=1002, alliance_name="Alliance 1002", executor_corp_id=2002
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
with (
|
|
75
|
+
patch.object(
|
|
76
|
+
EveAllianceInfo.objects,
|
|
77
|
+
"filter",
|
|
78
|
+
wraps=EveAllianceInfo.objects.filter,
|
|
79
|
+
),
|
|
80
|
+
patch.object(
|
|
81
|
+
EveAllianceInfo.objects, "create_alliance"
|
|
82
|
+
) as mock_create_alliance,
|
|
83
|
+
):
|
|
84
|
+
_create_alliance(alliance_ids)
|
|
85
|
+
|
|
86
|
+
mock_create_alliance.assert_called_once_with(alliance_id=1003)
|
|
87
|
+
|
|
88
|
+
def test_handles_empty_alliance_ids(self):
|
|
89
|
+
"""
|
|
90
|
+
Test that no alliances are created when the input list is empty.
|
|
91
|
+
|
|
92
|
+
:return:
|
|
93
|
+
:rtype:
|
|
94
|
+
"""
|
|
95
|
+
|
|
96
|
+
alliance_ids = []
|
|
97
|
+
|
|
98
|
+
with (
|
|
99
|
+
patch.object(EveAllianceInfo.objects, "filter"),
|
|
100
|
+
patch.object(
|
|
101
|
+
EveAllianceInfo.objects, "create_alliance"
|
|
102
|
+
) as mock_create_alliance,
|
|
103
|
+
):
|
|
104
|
+
_create_alliance(alliance_ids)
|
|
105
|
+
|
|
106
|
+
mock_create_alliance.assert_not_called()
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
class TestCreateCorporation(TestCase):
|
|
110
|
+
"""
|
|
111
|
+
Test the _create_corporation function.
|
|
112
|
+
"""
|
|
113
|
+
|
|
114
|
+
def test_creates_new_corporations(self):
|
|
115
|
+
"""
|
|
116
|
+
Test that new corporations are created when they do not exist in the database.
|
|
117
|
+
|
|
118
|
+
:return:
|
|
119
|
+
:rtype:
|
|
120
|
+
"""
|
|
121
|
+
|
|
122
|
+
corporation_ids = [2001, 2002, 2003]
|
|
123
|
+
|
|
124
|
+
with (
|
|
125
|
+
patch.object(
|
|
126
|
+
EveCorporationInfo.objects,
|
|
127
|
+
"filter",
|
|
128
|
+
return_value=EveCorporationInfo.objects.none(),
|
|
129
|
+
),
|
|
130
|
+
patch.object(
|
|
131
|
+
EveCorporationInfo.objects, "create_corporation"
|
|
132
|
+
) as mock_create_corporation,
|
|
133
|
+
):
|
|
134
|
+
_create_corporation(corporation_ids)
|
|
135
|
+
|
|
136
|
+
self.assertEqual(mock_create_corporation.call_count, 3)
|
|
137
|
+
|
|
138
|
+
def test_does_not_create_existing_corporations(self):
|
|
139
|
+
"""
|
|
140
|
+
Test that existing corporations are not created again.
|
|
141
|
+
|
|
142
|
+
:return:
|
|
143
|
+
:rtype:
|
|
144
|
+
"""
|
|
145
|
+
|
|
146
|
+
corporation_ids = [2001, 2002, 2003]
|
|
147
|
+
|
|
148
|
+
EveCorporationInfo.objects.create(
|
|
149
|
+
corporation_id=2001, corporation_name="Corporation 2001", member_count=10
|
|
150
|
+
)
|
|
151
|
+
EveCorporationInfo.objects.create(
|
|
152
|
+
corporation_id=2002, corporation_name="Corporation 2002", member_count=20
|
|
153
|
+
)
|
|
154
|
+
|
|
155
|
+
with (
|
|
156
|
+
patch.object(
|
|
157
|
+
EveCorporationInfo.objects,
|
|
158
|
+
"filter",
|
|
159
|
+
wraps=EveCorporationInfo.objects.filter,
|
|
160
|
+
),
|
|
161
|
+
patch.object(
|
|
162
|
+
EveCorporationInfo.objects, "create_corporation"
|
|
163
|
+
) as mock_create_corporation,
|
|
164
|
+
):
|
|
165
|
+
_create_corporation(corporation_ids)
|
|
166
|
+
|
|
167
|
+
mock_create_corporation.assert_called_once_with(corp_id=2003)
|
|
168
|
+
|
|
169
|
+
def test_handles_empty_corporation_ids(self):
|
|
170
|
+
"""
|
|
171
|
+
Test that no corporations are created when the input list is empty.
|
|
172
|
+
|
|
173
|
+
:return:
|
|
174
|
+
:rtype:
|
|
175
|
+
"""
|
|
176
|
+
|
|
177
|
+
corporation_ids = []
|
|
178
|
+
|
|
179
|
+
with (
|
|
180
|
+
patch.object(EveCorporationInfo.objects, "filter"),
|
|
181
|
+
patch.object(
|
|
182
|
+
EveCorporationInfo.objects, "create_corporation"
|
|
183
|
+
) as mock_create_corporation,
|
|
184
|
+
):
|
|
185
|
+
_create_corporation(corporation_ids)
|
|
186
|
+
|
|
187
|
+
mock_create_corporation.assert_not_called()
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
class TestCreateCharacter(TestCase):
|
|
191
|
+
"""
|
|
192
|
+
Test the _create_character function.
|
|
193
|
+
"""
|
|
194
|
+
|
|
195
|
+
@patch("aa_intel_tool.helper.eve_character.EveCharacter.objects.create_character")
|
|
196
|
+
@patch("aa_intel_tool.helper.eve_character.EveAllianceInfo.objects.create_alliance")
|
|
197
|
+
@patch("allianceauth.eveonline.providers.provider.get_corp")
|
|
198
|
+
def test_creates_new_characters(
|
|
199
|
+
self, mock_get_corp, mock_create_alliance, mock_create_character
|
|
200
|
+
):
|
|
201
|
+
# Setup mock return values
|
|
202
|
+
mock_create_character.side_effect = [
|
|
203
|
+
Mock(character_id=1001, alliance_id=3001, corporation_id=2001),
|
|
204
|
+
Mock(character_id=1002, alliance_id=3001, corporation_id=2002),
|
|
205
|
+
Mock(character_id=1003, alliance_id=None, corporation_id=2003),
|
|
206
|
+
]
|
|
207
|
+
|
|
208
|
+
mock_get_corp_side_effect = [
|
|
209
|
+
Mock(
|
|
210
|
+
id=2001,
|
|
211
|
+
name="Corporation 2001",
|
|
212
|
+
ticker="TICK1",
|
|
213
|
+
alliance_id=3001,
|
|
214
|
+
members=10,
|
|
215
|
+
),
|
|
216
|
+
Mock(
|
|
217
|
+
id=2002,
|
|
218
|
+
name="Corporation 2002",
|
|
219
|
+
ticker="TICK2",
|
|
220
|
+
alliance_id=3001,
|
|
221
|
+
members=20,
|
|
222
|
+
),
|
|
223
|
+
Mock(
|
|
224
|
+
id=2003,
|
|
225
|
+
name="Corporation 2003",
|
|
226
|
+
ticker="TICK3",
|
|
227
|
+
alliance_id=None,
|
|
228
|
+
members=30,
|
|
229
|
+
),
|
|
230
|
+
]
|
|
231
|
+
|
|
232
|
+
# Ensure the mock objects return plain values for attributes
|
|
233
|
+
for mock_corp in mock_get_corp_side_effect:
|
|
234
|
+
mock_corp.name = "Corporation " + str(mock_corp.id)
|
|
235
|
+
mock_corp.ticker = "TICK" + str(mock_corp.id % 1000)
|
|
236
|
+
mock_corp.members = mock_corp.members
|
|
237
|
+
|
|
238
|
+
mock_get_corp.side_effect = (
|
|
239
|
+
lambda *args, **kwargs: mock_get_corp_side_effect.pop(0)
|
|
240
|
+
)
|
|
241
|
+
|
|
242
|
+
# Call the function under test
|
|
243
|
+
_create_character(character_ids=[1, 2, 3], with_affiliation=True)
|
|
244
|
+
|
|
245
|
+
# Assert that create_character was called three times
|
|
246
|
+
self.assertEqual(mock_create_character.call_count, 3)
|
|
247
|
+
|
|
248
|
+
# Assert that create_alliance was called once with the correct ID
|
|
249
|
+
mock_create_alliance.assert_called_once_with(alliance_id=3001)
|
|
250
|
+
|
|
251
|
+
def test_handles_empty_character_ids(self):
|
|
252
|
+
"""
|
|
253
|
+
Test that no characters are created when the input list is empty.
|
|
254
|
+
|
|
255
|
+
:return:
|
|
256
|
+
:rtype:
|
|
257
|
+
"""
|
|
258
|
+
|
|
259
|
+
character_ids = []
|
|
260
|
+
|
|
261
|
+
with (
|
|
262
|
+
patch.object(EveCharacter.objects, "filter"),
|
|
263
|
+
patch.object(
|
|
264
|
+
EveCharacter.objects, "create_character"
|
|
265
|
+
) as mock_create_character,
|
|
266
|
+
):
|
|
267
|
+
_create_character(character_ids)
|
|
268
|
+
|
|
269
|
+
mock_create_character.assert_not_called()
|
|
270
|
+
|
|
271
|
+
@patch("aa_intel_tool.helper.eve_character.EveCharacter.objects.create_character")
|
|
272
|
+
@patch("aa_intel_tool.helper.eve_character.EveAllianceInfo.objects.create_alliance")
|
|
273
|
+
@patch("allianceauth.eveonline.providers.provider.get_corp")
|
|
274
|
+
def creates_characters_without_affiliation(
|
|
275
|
+
self, mock_get_corp, mock_create_alliance, mock_create_character
|
|
276
|
+
):
|
|
277
|
+
# Setup mock return values
|
|
278
|
+
mock_create_character.side_effect = [
|
|
279
|
+
Mock(character_id=1001, alliance_id=3001, corporation_id=2001),
|
|
280
|
+
Mock(character_id=1002, alliance_id=3001, corporation_id=2002),
|
|
281
|
+
Mock(character_id=1003, alliance_id=None, corporation_id=2003),
|
|
282
|
+
]
|
|
283
|
+
|
|
284
|
+
mock_get_corp_side_effect = [
|
|
285
|
+
Mock(
|
|
286
|
+
id=2001,
|
|
287
|
+
name="Corporation 2001",
|
|
288
|
+
ticker="TICK1",
|
|
289
|
+
alliance_id=3001,
|
|
290
|
+
members=10,
|
|
291
|
+
),
|
|
292
|
+
Mock(
|
|
293
|
+
id=2002,
|
|
294
|
+
name="Corporation 2002",
|
|
295
|
+
ticker="TICK2",
|
|
296
|
+
alliance_id=3001,
|
|
297
|
+
members=20,
|
|
298
|
+
),
|
|
299
|
+
Mock(
|
|
300
|
+
id=2003,
|
|
301
|
+
name="Corporation 2003",
|
|
302
|
+
ticker="TICK3",
|
|
303
|
+
alliance_id=None,
|
|
304
|
+
members=30,
|
|
305
|
+
),
|
|
306
|
+
]
|
|
307
|
+
|
|
308
|
+
# Ensure the mock objects return plain values for attributes
|
|
309
|
+
for mock_corp in mock_get_corp_side_effect:
|
|
310
|
+
mock_corp.name = "Corporation " + str(mock_corp.id)
|
|
311
|
+
mock_corp.ticker = "TICK" + str(mock_corp.id % 1000)
|
|
312
|
+
mock_corp.members = mock_corp.members
|
|
313
|
+
|
|
314
|
+
mock_get_corp.side_effect = (
|
|
315
|
+
lambda *args, **kwargs: mock_get_corp_side_effect.pop(0)
|
|
316
|
+
)
|
|
317
|
+
|
|
318
|
+
# Call the function under test
|
|
319
|
+
_create_character(character_ids=[1, 2, 3], with_affiliation=False)
|
|
320
|
+
|
|
321
|
+
# Assert that create_character was called three times
|
|
322
|
+
self.assertEqual(mock_create_character.call_count, 3)
|
|
323
|
+
|
|
324
|
+
# Assert that create_alliance was called once with the correct ID
|
|
325
|
+
mock_create_alliance.assert_called_once_with(alliance_id=3001)
|
|
326
|
+
|
|
327
|
+
|
|
328
|
+
class TestGetOrCreateCharacter(TestCase):
|
|
329
|
+
"""
|
|
330
|
+
Test the get_or_create_character function.
|
|
331
|
+
"""
|
|
332
|
+
|
|
333
|
+
@patch("aa_intel_tool.helper.eve_character._create_character")
|
|
334
|
+
def test_returns_existing_characters(self, mock_create_character):
|
|
335
|
+
"""
|
|
336
|
+
Test that existing characters are returned without creating new ones.
|
|
337
|
+
|
|
338
|
+
:param mock_create_character:
|
|
339
|
+
:type mock_create_character:
|
|
340
|
+
:return:
|
|
341
|
+
:rtype:
|
|
342
|
+
"""
|
|
343
|
+
|
|
344
|
+
character_ids = [3001, 3002]
|
|
345
|
+
EveCharacter.objects.create(
|
|
346
|
+
character_id=3001,
|
|
347
|
+
character_name="Character 3001",
|
|
348
|
+
corporation_id=2001,
|
|
349
|
+
alliance_id=1001,
|
|
350
|
+
)
|
|
351
|
+
EveCharacter.objects.create(
|
|
352
|
+
character_id=3002,
|
|
353
|
+
character_name="Character 3002",
|
|
354
|
+
corporation_id=2002,
|
|
355
|
+
alliance_id=1002,
|
|
356
|
+
)
|
|
357
|
+
|
|
358
|
+
characters = get_or_create_character(character_ids)
|
|
359
|
+
|
|
360
|
+
self.assertEqual(characters.count(), 2)
|
|
361
|
+
mock_create_character.assert_not_called()
|
|
362
|
+
|
|
363
|
+
@patch("aa_intel_tool.helper.eve_character._create_character")
|
|
364
|
+
def test_creates_missing_characters(self, mock_create_character):
|
|
365
|
+
"""
|
|
366
|
+
Test that missing characters are created when they do not exist in the database.
|
|
367
|
+
|
|
368
|
+
:param mock_create_character:
|
|
369
|
+
:type mock_create_character:
|
|
370
|
+
:return:
|
|
371
|
+
:rtype:
|
|
372
|
+
"""
|
|
373
|
+
|
|
374
|
+
character_ids = [3001, 3002, 3003]
|
|
375
|
+
EveCharacter.objects.create(
|
|
376
|
+
character_id=3001,
|
|
377
|
+
character_name="Character 3001",
|
|
378
|
+
corporation_id=2001,
|
|
379
|
+
alliance_id=1001,
|
|
380
|
+
)
|
|
381
|
+
|
|
382
|
+
characters = get_or_create_character(character_ids)
|
|
383
|
+
|
|
384
|
+
self.assertEqual(characters.count(), 1)
|
|
385
|
+
mock_create_character.assert_called_once_with(
|
|
386
|
+
character_ids={3002, 3003}, with_affiliation=True
|
|
387
|
+
)
|
|
388
|
+
|
|
389
|
+
@patch("aa_intel_tool.helper.eve_character._create_character")
|
|
390
|
+
def handles_empty_character_ids(self, mock_create_character):
|
|
391
|
+
character_ids = []
|
|
392
|
+
|
|
393
|
+
characters = get_or_create_character(character_ids)
|
|
394
|
+
|
|
395
|
+
self.assertEqual(characters.count(), 0)
|
|
396
|
+
mock_create_character.assert_not_called()
|
|
397
|
+
|
|
398
|
+
@patch("aa_intel_tool.helper.eve_character._create_character")
|
|
399
|
+
def handles_none_character_ids(self, mock_create_character):
|
|
400
|
+
character_ids = None
|
|
401
|
+
|
|
402
|
+
characters = get_or_create_character(character_ids)
|
|
403
|
+
|
|
404
|
+
self.assertEqual(characters.count(), 0)
|
|
405
|
+
mock_create_character.assert_not_called()
|
|
@@ -2,18 +2,106 @@
|
|
|
2
2
|
Tests for our models
|
|
3
3
|
"""
|
|
4
4
|
|
|
5
|
+
# Standard Library
|
|
6
|
+
from unittest.mock import patch
|
|
7
|
+
|
|
5
8
|
# Django
|
|
9
|
+
from django.db import IntegrityError
|
|
6
10
|
from django.test import TestCase
|
|
7
11
|
|
|
8
12
|
# AA Intel Tool
|
|
9
|
-
from aa_intel_tool.models import Scan
|
|
13
|
+
from aa_intel_tool.models import Scan, ScanData
|
|
10
14
|
|
|
11
15
|
|
|
12
|
-
class
|
|
16
|
+
class TestScanModel(TestCase):
|
|
13
17
|
"""
|
|
14
|
-
|
|
18
|
+
Test the Scan model
|
|
15
19
|
"""
|
|
16
20
|
|
|
21
|
+
def test_generates_unique_hash(self):
|
|
22
|
+
"""
|
|
23
|
+
Test that the hash is unique
|
|
24
|
+
|
|
25
|
+
:return:
|
|
26
|
+
:rtype:
|
|
27
|
+
"""
|
|
28
|
+
|
|
29
|
+
hash1 = Scan.generate_scan_hash()
|
|
30
|
+
hash2 = Scan.generate_scan_hash()
|
|
31
|
+
|
|
32
|
+
self.assertNotEqual(hash1, hash2)
|
|
33
|
+
|
|
34
|
+
def test_generates_hash_of_correct_length(self):
|
|
35
|
+
"""
|
|
36
|
+
Test that the hash is of the correct length
|
|
37
|
+
|
|
38
|
+
:return:
|
|
39
|
+
:rtype:
|
|
40
|
+
"""
|
|
41
|
+
|
|
42
|
+
scan_hash = Scan.generate_scan_hash()
|
|
43
|
+
|
|
44
|
+
self.assertEqual(len(scan_hash), 30)
|
|
45
|
+
|
|
46
|
+
def test_generates_hash_not_in_database(self):
|
|
47
|
+
"""
|
|
48
|
+
Test that the generated hash is not in the database
|
|
49
|
+
|
|
50
|
+
:return:
|
|
51
|
+
:rtype:
|
|
52
|
+
"""
|
|
53
|
+
|
|
54
|
+
existing_scan = Scan.objects.create(raw_data="test data")
|
|
55
|
+
scan_hash = Scan.generate_scan_hash()
|
|
56
|
+
|
|
57
|
+
self.assertNotEqual(scan_hash, existing_scan.hash)
|
|
58
|
+
|
|
59
|
+
def test_handles_collision_by_generating_new_hash(self):
|
|
60
|
+
"""
|
|
61
|
+
Test that the hash collision is handled by generating a new hash
|
|
62
|
+
|
|
63
|
+
:return:
|
|
64
|
+
:rtype:
|
|
65
|
+
"""
|
|
66
|
+
|
|
67
|
+
with patch("aa_intel_tool.models.Scan.objects.filter") as mock_filter:
|
|
68
|
+
# Simulate hash collision by returning True for the first two calls
|
|
69
|
+
mock_filter.return_value.exists.side_effect = [True, True, False]
|
|
70
|
+
|
|
71
|
+
new_hash = Scan.generate_scan_hash()
|
|
72
|
+
|
|
73
|
+
self.assertIsNotNone(new_hash)
|
|
74
|
+
self.assertEqual(len(new_hash), 30)
|
|
75
|
+
self.assertNotIn(new_hash, ["collision_hash1", "collision_hash2"])
|
|
76
|
+
|
|
77
|
+
def test_saves_with_generated_hash(self):
|
|
78
|
+
"""
|
|
79
|
+
Test that the hash is generated on save
|
|
80
|
+
|
|
81
|
+
:return:
|
|
82
|
+
:rtype:
|
|
83
|
+
"""
|
|
84
|
+
|
|
85
|
+
scan = Scan(raw_data="test data")
|
|
86
|
+
scan.save()
|
|
87
|
+
|
|
88
|
+
self.assertIsNotNone(scan.hash)
|
|
89
|
+
self.assertEqual(len(scan.hash), 30)
|
|
90
|
+
|
|
91
|
+
def test_generates_new_hash_if_empty_on_save(self):
|
|
92
|
+
"""
|
|
93
|
+
Test that a new hash is generated if the hash is empty on save
|
|
94
|
+
|
|
95
|
+
:return:
|
|
96
|
+
:rtype:
|
|
97
|
+
"""
|
|
98
|
+
|
|
99
|
+
scan = Scan(hash="", raw_data="test data")
|
|
100
|
+
scan.save()
|
|
101
|
+
|
|
102
|
+
self.assertNotEqual(scan.hash, "")
|
|
103
|
+
self.assertEqual(len(scan.hash), 30)
|
|
104
|
+
|
|
17
105
|
def test_model_string_names(self):
|
|
18
106
|
"""
|
|
19
107
|
Test model string name
|
|
@@ -27,15 +115,111 @@ class TestScan(TestCase):
|
|
|
27
115
|
)
|
|
28
116
|
scan.save()
|
|
29
117
|
expected_hash = scan.hash
|
|
118
|
+
|
|
30
119
|
self.assertEqual(first=str(scan), second=expected_hash)
|
|
31
120
|
|
|
32
121
|
scan.raw_data = "BarFoo"
|
|
33
122
|
scan.save()
|
|
123
|
+
|
|
34
124
|
self.assertEqual(first=str(scan), second=expected_hash)
|
|
35
125
|
|
|
36
126
|
scan.hash = ""
|
|
37
127
|
scan.save()
|
|
128
|
+
|
|
38
129
|
self.assertNotEqual(first=str(scan), second="")
|
|
39
130
|
self.assertNotEqual(first=str(scan), second=expected_hash)
|
|
40
131
|
|
|
41
|
-
|
|
132
|
+
|
|
133
|
+
class TestScanDataModel(TestCase):
|
|
134
|
+
"""
|
|
135
|
+
Test the ScanData model
|
|
136
|
+
"""
|
|
137
|
+
|
|
138
|
+
def test_creates_scan_data_with_valid_section(self):
|
|
139
|
+
"""
|
|
140
|
+
Test that the ScanData model can be created with a valid section
|
|
141
|
+
|
|
142
|
+
:return:
|
|
143
|
+
:rtype:
|
|
144
|
+
"""
|
|
145
|
+
|
|
146
|
+
scan = Scan.objects.create(raw_data="test data")
|
|
147
|
+
scan_data = ScanData.objects.create(
|
|
148
|
+
scan=scan,
|
|
149
|
+
section=ScanData.Section.PILOTLIST,
|
|
150
|
+
processed_data={"key": "value"},
|
|
151
|
+
)
|
|
152
|
+
|
|
153
|
+
self.assertEqual(scan_data.section, ScanData.Section.PILOTLIST)
|
|
154
|
+
self.assertEqual(scan_data.processed_data, {"key": "value"})
|
|
155
|
+
|
|
156
|
+
def test_defaults_to_invalid_section(self):
|
|
157
|
+
"""
|
|
158
|
+
Test that the ScanData model defaults to INVALID section if not specified
|
|
159
|
+
|
|
160
|
+
:return:
|
|
161
|
+
:rtype:
|
|
162
|
+
"""
|
|
163
|
+
|
|
164
|
+
scan = Scan.objects.create(raw_data="test data")
|
|
165
|
+
scan_data = ScanData.objects.create(scan=scan, processed_data={"key": "value"})
|
|
166
|
+
|
|
167
|
+
self.assertEqual(scan_data.section, ScanData.Section.INVALID)
|
|
168
|
+
|
|
169
|
+
def test_allows_null_scan(self):
|
|
170
|
+
"""
|
|
171
|
+
Test that the ScanData model allows null scan
|
|
172
|
+
|
|
173
|
+
:return:
|
|
174
|
+
:rtype:
|
|
175
|
+
"""
|
|
176
|
+
|
|
177
|
+
scan_data = ScanData.objects.create(
|
|
178
|
+
section=ScanData.Section.PILOTLIST, processed_data={"key": "value"}
|
|
179
|
+
)
|
|
180
|
+
|
|
181
|
+
self.assertIsNone(scan_data.scan)
|
|
182
|
+
|
|
183
|
+
def test_enforces_unique_together_constraint(self):
|
|
184
|
+
"""
|
|
185
|
+
Test that the ScanData model enforces unique together constraint on scan and section and raises IntegrityError
|
|
186
|
+
|
|
187
|
+
:return:
|
|
188
|
+
:rtype:
|
|
189
|
+
"""
|
|
190
|
+
|
|
191
|
+
scan = Scan.objects.create(raw_data="test data")
|
|
192
|
+
ScanData.objects.create(
|
|
193
|
+
scan=scan,
|
|
194
|
+
section=ScanData.Section.PILOTLIST,
|
|
195
|
+
processed_data={"key": "value"},
|
|
196
|
+
)
|
|
197
|
+
|
|
198
|
+
with self.assertRaises(IntegrityError):
|
|
199
|
+
ScanData.objects.create(
|
|
200
|
+
scan=scan,
|
|
201
|
+
section=ScanData.Section.PILOTLIST,
|
|
202
|
+
processed_data={"key": "another value"},
|
|
203
|
+
)
|
|
204
|
+
|
|
205
|
+
def test_allows_different_sections_for_same_scan(self):
|
|
206
|
+
"""
|
|
207
|
+
Test that the ScanData model allows different sections for the same scan
|
|
208
|
+
|
|
209
|
+
:return:
|
|
210
|
+
:rtype:
|
|
211
|
+
"""
|
|
212
|
+
|
|
213
|
+
scan = Scan.objects.create(raw_data="test data")
|
|
214
|
+
scan_data1 = ScanData.objects.create(
|
|
215
|
+
scan=scan,
|
|
216
|
+
section=ScanData.Section.PILOTLIST,
|
|
217
|
+
processed_data={"key": "value"},
|
|
218
|
+
)
|
|
219
|
+
scan_data2 = ScanData.objects.create(
|
|
220
|
+
scan=scan,
|
|
221
|
+
section=ScanData.Section.CORPORATIONLIST,
|
|
222
|
+
processed_data={"key": "value"},
|
|
223
|
+
)
|
|
224
|
+
|
|
225
|
+
self.assertNotEqual(scan_data1.section, scan_data2.section)
|