aa-killtracker 0.18.0a2__py3-none-any.whl → 1.0.0a1__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_killtracker-0.18.0a2.dist-info → aa_killtracker-1.0.0a1.dist-info}/METADATA +7 -7
- {aa_killtracker-0.18.0a2.dist-info → aa_killtracker-1.0.0a1.dist-info}/RECORD +33 -30
- killtracker/__init__.py +1 -1
- killtracker/admin.py +1 -1
- killtracker/app_settings.py +14 -7
- killtracker/core/discord.py +162 -0
- killtracker/core/helpers.py +13 -0
- killtracker/core/{discord_messages.py → trackers.py} +16 -75
- killtracker/core/{worker_shutdown.py → workers.py} +3 -4
- killtracker/core/{killmails.py → zkb.py} +32 -40
- killtracker/managers.py +1 -1
- killtracker/models/trackers.py +4 -5
- killtracker/models/webhooks.py +4 -53
- killtracker/signals.py +4 -4
- killtracker/tasks.py +47 -49
- killtracker/tests/core/test_discord.py +184 -0
- killtracker/tests/core/test_helpers.py +23 -0
- killtracker/tests/core/{test_discord_messages_1.py → test_tracker_1.py} +12 -39
- killtracker/tests/core/{test_discord_messages_2.py → test_tracker_2.py} +3 -3
- killtracker/tests/core/test_workers.py +49 -0
- killtracker/tests/core/{test_killmails.py → test_zkb.py} +58 -46
- killtracker/tests/models/test_killmails.py +0 -2
- killtracker/tests/models/test_trackers_1.py +1 -1
- killtracker/tests/models/test_trackers_2.py +2 -2
- killtracker/tests/models/test_webhooks.py +63 -0
- killtracker/tests/test_integration.py +26 -13
- killtracker/tests/test_tasks.py +68 -58
- killtracker/tests/test_utils.py +39 -0
- killtracker/tests/testdata/factories.py +1 -1
- killtracker/tests/testdata/helpers.py +1 -1
- killtracker/tests/utils.py +28 -0
- killtracker/exceptions.py +0 -32
- killtracker/tests/core/test_worker_shutdown.py +0 -34
- killtracker/tests/models/test_webhook.py +0 -164
- killtracker/tests/test_exceptions.py +0 -12
- {aa_killtracker-0.18.0a2.dist-info → aa_killtracker-1.0.0a1.dist-info}/WHEEL +0 -0
- {aa_killtracker-0.18.0a2.dist-info → aa_killtracker-1.0.0a1.dist-info}/licenses/LICENSE +0 -0
@@ -0,0 +1,49 @@
|
|
1
|
+
from unittest.mock import patch
|
2
|
+
|
3
|
+
from django.test import TestCase
|
4
|
+
|
5
|
+
from killtracker.core import workers
|
6
|
+
from killtracker.tests.utils import CacheFake
|
7
|
+
|
8
|
+
MODULE_PATH = "killtracker.core.workers"
|
9
|
+
|
10
|
+
|
11
|
+
class TaskFake:
|
12
|
+
class RequestFake:
|
13
|
+
def __init__(self, hostname: str):
|
14
|
+
self.hostname = hostname
|
15
|
+
|
16
|
+
def __init__(self, hostname: str):
|
17
|
+
self.request = self.RequestFake(hostname)
|
18
|
+
|
19
|
+
|
20
|
+
class TestWorker(TestCase):
|
21
|
+
def test_should_report_false_when_not_set(self):
|
22
|
+
with patch(MODULE_PATH + ".cache", new_callable=CacheFake):
|
23
|
+
got = workers.is_shutting_down("dummy")
|
24
|
+
self.assertFalse(got)
|
25
|
+
|
26
|
+
def test_should_report_true_when_set(self):
|
27
|
+
with patch(MODULE_PATH + ".cache", new_callable=CacheFake):
|
28
|
+
workers.state_set("alpha")
|
29
|
+
got = workers.is_shutting_down(TaskFake("alpha"))
|
30
|
+
self.assertTrue(got)
|
31
|
+
|
32
|
+
def test_should_report_false_when_other_worker_is_shutting_down(self):
|
33
|
+
with patch(MODULE_PATH + ".cache", new_callable=CacheFake):
|
34
|
+
workers.state_set("alpha")
|
35
|
+
got = workers.is_shutting_down(TaskFake("bravo"))
|
36
|
+
self.assertFalse(got)
|
37
|
+
|
38
|
+
def test_should_report_false_when_task_not_valid(self):
|
39
|
+
with patch(MODULE_PATH + ".cache", new_callable=CacheFake):
|
40
|
+
workers.state_set("alpha")
|
41
|
+
got = workers.is_shutting_down("invalid")
|
42
|
+
self.assertFalse(got)
|
43
|
+
|
44
|
+
def test_should_report_false_when_worker_shutdown_has_reset(self):
|
45
|
+
with patch(MODULE_PATH + ".cache", new_callable=CacheFake):
|
46
|
+
workers.state_set("alpha")
|
47
|
+
workers.state_reset("alpha")
|
48
|
+
got = workers.is_shutting_down(TaskFake("alpha"))
|
49
|
+
self.assertFalse(got)
|
@@ -4,7 +4,6 @@ from unittest.mock import patch
|
|
4
4
|
|
5
5
|
import requests_mock
|
6
6
|
|
7
|
-
from django.core.cache import cache
|
8
7
|
from django.core.exceptions import ImproperlyConfigured
|
9
8
|
from django.test import TestCase
|
10
9
|
from django.utils.dateparse import parse_datetime
|
@@ -13,33 +12,35 @@ from django.utils.timezone import now
|
|
13
12
|
from app_utils.esi_testing import BravadoOperationStub
|
14
13
|
from app_utils.testing import NoSocketsTestCase
|
15
14
|
|
16
|
-
from killtracker.core.
|
17
|
-
|
18
|
-
|
15
|
+
from killtracker.core.zkb import (
|
16
|
+
_KEY_LAST_REQUEST,
|
17
|
+
_KEY_RETRY_AT,
|
18
|
+
_ZKB_API_URL,
|
19
|
+
_ZKB_REDISQ_URL,
|
19
20
|
Killmail,
|
21
|
+
KillmailDoesNotExist,
|
20
22
|
ZKBTooManyRequestsError,
|
21
23
|
_EntityCount,
|
22
24
|
)
|
23
|
-
from killtracker.exceptions import KillmailDoesNotExist
|
24
25
|
from killtracker.tests import CacheStub
|
25
26
|
from killtracker.tests.testdata.factories import KillmailFactory
|
26
27
|
from killtracker.tests.testdata.helpers import killmails_data, load_killmail
|
28
|
+
from killtracker.tests.utils import CacheFake
|
27
29
|
|
28
|
-
MODULE_PATH = "killtracker.core.
|
30
|
+
MODULE_PATH = "killtracker.core.zkb"
|
29
31
|
unittest.util._MAX_LENGTH = 1000
|
30
32
|
requests_mock.mock.case_sensitive = True
|
31
33
|
|
32
34
|
|
33
35
|
@requests_mock.Mocker()
|
34
|
-
@patch(MODULE_PATH + ".cache")
|
36
|
+
@patch(MODULE_PATH + ".cache", new_callable=CacheFake)
|
35
37
|
class TestCreateFromZkbRedisq(NoSocketsTestCase):
|
36
38
|
@patch(MODULE_PATH + ".KILLTRACKER_QUEUE_ID", "dummy")
|
37
39
|
def test_should_return_killmail(self, requests_mocker, mock_cache):
|
38
40
|
# given
|
39
|
-
mock_cache.get.return_value = None
|
40
41
|
requests_mocker.register_uri(
|
41
42
|
"GET",
|
42
|
-
|
43
|
+
_ZKB_REDISQ_URL,
|
43
44
|
status_code=200,
|
44
45
|
json={"package": killmails_data()[10000001]},
|
45
46
|
)
|
@@ -79,9 +80,36 @@ class TestCreateFromZkbRedisq(NoSocketsTestCase):
|
|
79
80
|
self, requests_mocker, mock_cache
|
80
81
|
):
|
81
82
|
# given
|
82
|
-
mock_cache.get.return_value = None
|
83
83
|
requests_mocker.register_uri(
|
84
|
-
"GET",
|
84
|
+
"GET", _ZKB_REDISQ_URL, status_code=200, json={"package": None}
|
85
|
+
)
|
86
|
+
# when
|
87
|
+
killmail = Killmail.create_from_zkb_redisq()
|
88
|
+
# then
|
89
|
+
self.assertIsNone(killmail)
|
90
|
+
|
91
|
+
@patch(MODULE_PATH + ".KILLTRACKER_QUEUE_ID", "dummy")
|
92
|
+
def test_should_ignore_invalid_value_for_retry_at_key(
|
93
|
+
self, requests_mocker, mock_cache
|
94
|
+
):
|
95
|
+
# given
|
96
|
+
mock_cache.set(_KEY_RETRY_AT, "abc")
|
97
|
+
requests_mocker.register_uri(
|
98
|
+
"GET", _ZKB_REDISQ_URL, status_code=200, json={"package": None}
|
99
|
+
)
|
100
|
+
# when
|
101
|
+
killmail = Killmail.create_from_zkb_redisq()
|
102
|
+
# then
|
103
|
+
self.assertIsNone(killmail)
|
104
|
+
|
105
|
+
@patch(MODULE_PATH + ".KILLTRACKER_QUEUE_ID", "dummy")
|
106
|
+
def test_should_ignore_invalid_value_for_last_request_key(
|
107
|
+
self, requests_mocker, mock_cache
|
108
|
+
):
|
109
|
+
# given
|
110
|
+
mock_cache.set(_KEY_LAST_REQUEST, "abc")
|
111
|
+
requests_mocker.register_uri(
|
112
|
+
"GET", _ZKB_REDISQ_URL, status_code=200, json={"package": None}
|
85
113
|
)
|
86
114
|
# when
|
87
115
|
killmail = Killmail.create_from_zkb_redisq()
|
@@ -93,10 +121,9 @@ class TestCreateFromZkbRedisq(NoSocketsTestCase):
|
|
93
121
|
self, requests_mocker, mock_cache
|
94
122
|
):
|
95
123
|
# given
|
96
|
-
mock_cache.get.return_value = None
|
97
124
|
requests_mocker.register_uri(
|
98
125
|
"GET",
|
99
|
-
|
126
|
+
_ZKB_REDISQ_URL,
|
100
127
|
status_code=200,
|
101
128
|
json={"package": killmails_data()[10000402]},
|
102
129
|
)
|
@@ -108,8 +135,7 @@ class TestCreateFromZkbRedisq(NoSocketsTestCase):
|
|
108
135
|
@patch(MODULE_PATH + ".KILLTRACKER_QUEUE_ID", "dummy")
|
109
136
|
def test_should_return_none_when_http_error(self, requests_mocker, mock_cache):
|
110
137
|
# given
|
111
|
-
|
112
|
-
requests_mocker.register_uri("GET", ZKB_REDISQ_URL, status_code=500)
|
138
|
+
requests_mocker.register_uri("GET", _ZKB_REDISQ_URL, status_code=500)
|
113
139
|
# when
|
114
140
|
killmail = Killmail.create_from_zkb_redisq()
|
115
141
|
# then
|
@@ -120,9 +146,8 @@ class TestCreateFromZkbRedisq(NoSocketsTestCase):
|
|
120
146
|
self, requests_mocker, mock_cache
|
121
147
|
):
|
122
148
|
# given
|
123
|
-
mock_cache.get.return_value = None
|
124
149
|
requests_mocker.register_uri(
|
125
|
-
"GET",
|
150
|
+
"GET", _ZKB_REDISQ_URL, status_code=429, text="429 too many requests"
|
126
151
|
)
|
127
152
|
# when/then
|
128
153
|
with self.assertRaises(ZKBTooManyRequestsError):
|
@@ -134,8 +159,8 @@ class TestCreateFromZkbRedisq(NoSocketsTestCase):
|
|
134
159
|
):
|
135
160
|
# given
|
136
161
|
retry_at = now() + dt.timedelta(hours=3)
|
137
|
-
mock_cache.
|
138
|
-
requests_mocker.register_uri("GET",
|
162
|
+
mock_cache.set(_KEY_RETRY_AT, retry_at)
|
163
|
+
requests_mocker.register_uri("GET", _ZKB_REDISQ_URL, status_code=500)
|
139
164
|
# when/then
|
140
165
|
self.assertEqual(requests_mocker.call_count, 0)
|
141
166
|
with self.assertRaises(ZKBTooManyRequestsError) as ex:
|
@@ -147,10 +172,9 @@ class TestCreateFromZkbRedisq(NoSocketsTestCase):
|
|
147
172
|
self, requests_mocker, mock_cache
|
148
173
|
):
|
149
174
|
# given
|
150
|
-
mock_cache.get.return_value = None
|
151
175
|
requests_mocker.register_uri(
|
152
176
|
"GET",
|
153
|
-
|
177
|
+
_ZKB_REDISQ_URL,
|
154
178
|
status_code=200,
|
155
179
|
text="""Your IP has been banned because of excessive errors.
|
156
180
|
|
@@ -166,9 +190,8 @@ You can only have one request to listen.php in flight at any time, otherwise you
|
|
166
190
|
self, requests_mocker, mock_cache
|
167
191
|
):
|
168
192
|
# given
|
169
|
-
mock_cache.get.return_value = None
|
170
193
|
requests_mocker.register_uri(
|
171
|
-
"GET",
|
194
|
+
"GET", _ZKB_REDISQ_URL, status_code=200, text="this is not JSON"
|
172
195
|
)
|
173
196
|
# when
|
174
197
|
killmail = Killmail.create_from_zkb_redisq()
|
@@ -178,9 +201,8 @@ You can only have one request to listen.php in flight at any time, otherwise you
|
|
178
201
|
@patch(MODULE_PATH + ".KILLTRACKER_QUEUE_ID", "Voltron9000")
|
179
202
|
def test_should_have_queue_id_in_request(self, requests_mocker, mock_cache):
|
180
203
|
# given
|
181
|
-
mock_cache.get.return_value = None
|
182
204
|
requests_mocker.register_uri(
|
183
|
-
"GET",
|
205
|
+
"GET", _ZKB_REDISQ_URL, status_code=200, json={"package": None}
|
184
206
|
)
|
185
207
|
# when
|
186
208
|
Killmail.create_from_zkb_redisq()
|
@@ -194,9 +216,8 @@ You can only have one request to listen.php in flight at any time, otherwise you
|
|
194
216
|
@patch(MODULE_PATH + ".KILLTRACKER_QUEUE_ID", "")
|
195
217
|
def test_should_abort_when_no_queue_id_defined(self, requests_mocker, mock_cache):
|
196
218
|
# given
|
197
|
-
mock_cache.get.return_value = None
|
198
219
|
requests_mocker.register_uri(
|
199
|
-
"GET",
|
220
|
+
"GET", _ZKB_REDISQ_URL, status_code=200, json={"package": None}
|
200
221
|
)
|
201
222
|
# when/then
|
202
223
|
with self.assertRaises(ImproperlyConfigured):
|
@@ -205,9 +226,8 @@ You can only have one request to listen.php in flight at any time, otherwise you
|
|
205
226
|
@patch(MODULE_PATH + ".KILLTRACKER_QUEUE_ID", "Möchtegern")
|
206
227
|
def test_should_urlize_queue_ids(self, requests_mocker, mock_cache):
|
207
228
|
# given
|
208
|
-
mock_cache.get.return_value = None
|
209
229
|
requests_mocker.register_uri(
|
210
|
-
"GET",
|
230
|
+
"GET", _ZKB_REDISQ_URL, status_code=200, json={"package": None}
|
211
231
|
)
|
212
232
|
# when
|
213
233
|
Killmail.create_from_zkb_redisq()
|
@@ -221,9 +241,8 @@ You can only have one request to listen.php in flight at any time, otherwise you
|
|
221
241
|
@patch(MODULE_PATH + ".KILLTRACKER_QUEUE_ID", "alpha,bravo")
|
222
242
|
def test_should_not_accept_list_for_queue_id(self, requests_mocker, mock_cache):
|
223
243
|
# given
|
224
|
-
mock_cache.get.return_value = None
|
225
244
|
requests_mocker.register_uri(
|
226
|
-
"GET",
|
245
|
+
"GET", _ZKB_REDISQ_URL, status_code=200, json={"package": None}
|
227
246
|
)
|
228
247
|
# when/then
|
229
248
|
with self.assertRaises(ImproperlyConfigured):
|
@@ -234,15 +253,10 @@ You can only have one request to listen.php in flight at any time, otherwise you
|
|
234
253
|
def test_should_wait_until_next_slot_if_needed(
|
235
254
|
self, requests_mocker, mock_sleep, mock_cache
|
236
255
|
):
|
237
|
-
def cache_get(v):
|
238
|
-
if v != "killtracker-last-request":
|
239
|
-
return None
|
240
|
-
return now().isoformat()
|
241
|
-
|
242
256
|
# given
|
243
|
-
mock_cache.
|
257
|
+
mock_cache.set(_KEY_LAST_REQUEST, now())
|
244
258
|
requests_mocker.register_uri(
|
245
|
-
"GET",
|
259
|
+
"GET", _ZKB_REDISQ_URL, status_code=200, json={"package": None}
|
246
260
|
)
|
247
261
|
# when
|
248
262
|
killmail = Killmail.create_from_zkb_redisq()
|
@@ -368,7 +382,7 @@ class TestCreateFromZkbApi(NoSocketsTestCase):
|
|
368
382
|
]
|
369
383
|
requests_mocker.register_uri(
|
370
384
|
"GET",
|
371
|
-
f"{
|
385
|
+
f"{_ZKB_API_URL}killID/{killmail_id}/",
|
372
386
|
status_code=200,
|
373
387
|
json=zkb_api_data,
|
374
388
|
)
|
@@ -410,11 +424,9 @@ class TestCreateFromZkbApi(NoSocketsTestCase):
|
|
410
424
|
self.assertFalse(killmail.zkb.is_awox)
|
411
425
|
|
412
426
|
|
427
|
+
@patch(MODULE_PATH + ".cache", new_callable=CacheFake)
|
413
428
|
class TestKillmailStorage(TestCase):
|
414
|
-
def
|
415
|
-
cache.clear()
|
416
|
-
|
417
|
-
def test_should_store_and_retrieve_killmail(self):
|
429
|
+
def test_should_store_and_retrieve_killmail(self, mock_cache):
|
418
430
|
# given
|
419
431
|
killmail_1 = KillmailFactory()
|
420
432
|
# when
|
@@ -423,12 +435,12 @@ class TestKillmailStorage(TestCase):
|
|
423
435
|
# then
|
424
436
|
self.assertEqual(killmail_1, killmail_2)
|
425
437
|
|
426
|
-
def test_should_raise_error_when_killmail_does_not_exist(self):
|
438
|
+
def test_should_raise_error_when_killmail_does_not_exist(self, mock_cache):
|
427
439
|
# when/then
|
428
440
|
with self.assertRaises(KillmailDoesNotExist):
|
429
441
|
Killmail.get(id=99)
|
430
442
|
|
431
|
-
def test_should_delete_killmail(self):
|
443
|
+
def test_should_delete_killmail(self, mock_cache):
|
432
444
|
# given
|
433
445
|
killmail = KillmailFactory()
|
434
446
|
killmail.save()
|
@@ -438,7 +450,7 @@ class TestKillmailStorage(TestCase):
|
|
438
450
|
with self.assertRaises(KillmailDoesNotExist):
|
439
451
|
Killmail.get(id=killmail.id)
|
440
452
|
|
441
|
-
def test_should_override_existing_killmail(self):
|
453
|
+
def test_should_override_existing_killmail(self, mock_cache):
|
442
454
|
# given
|
443
455
|
killmail_1 = KillmailFactory(zkb__points=1)
|
444
456
|
killmail_1.save()
|
@@ -19,8 +19,6 @@ from killtracker.tests.testdata.helpers import (
|
|
19
19
|
)
|
20
20
|
from killtracker.tests.testdata.load_eveuniverse import load_eveuniverse
|
21
21
|
|
22
|
-
MODELS_PATH = "killtracker.models.killmails"
|
23
|
-
|
24
22
|
|
25
23
|
class TestEveKillmailManager(LoadTestDataMixin, NoSocketsTestCase):
|
26
24
|
def test_create_from_killmail(self):
|
@@ -24,7 +24,7 @@ from app_utils.testdata_factories import (
|
|
24
24
|
from app_utils.testing import NoSocketsTestCase, add_character_to_user_2
|
25
25
|
|
26
26
|
from killtracker.constants import EveGroupId
|
27
|
-
from killtracker.core.
|
27
|
+
from killtracker.core.zkb import Killmail, _EntityCount
|
28
28
|
from killtracker.models import Tracker
|
29
29
|
from killtracker.tests.testdata.factories import (
|
30
30
|
EveFactionInfoFactory,
|
@@ -8,8 +8,8 @@ from eveuniverse.models import EveConstellation, EveRegion, EveSolarSystem, EveT
|
|
8
8
|
|
9
9
|
from app_utils.testing import NoSocketsTestCase
|
10
10
|
|
11
|
-
from killtracker.core.
|
12
|
-
from killtracker.core.
|
11
|
+
from killtracker.core.discord import DiscordMessage
|
12
|
+
from killtracker.core.zkb import Killmail
|
13
13
|
from killtracker.tests.testdata.factories import TrackerFactory
|
14
14
|
from killtracker.tests.testdata.helpers import LoadTestDataMixin, load_killmail
|
15
15
|
|
@@ -0,0 +1,63 @@
|
|
1
|
+
from django.test import TestCase
|
2
|
+
|
3
|
+
from killtracker.core.discord import DiscordMessage
|
4
|
+
from killtracker.models import Webhook
|
5
|
+
|
6
|
+
|
7
|
+
class TestWebhookQueue(TestCase):
|
8
|
+
@classmethod
|
9
|
+
def setUpClass(cls):
|
10
|
+
super().setUpClass()
|
11
|
+
cls.webhook_1 = Webhook.objects.create(
|
12
|
+
name="Webhook 1", url="http://www.example.com/webhook_1", is_enabled=True
|
13
|
+
)
|
14
|
+
|
15
|
+
def setUp(self) -> None:
|
16
|
+
self.webhook_1._main_queue.clear()
|
17
|
+
self.webhook_1._error_queue.clear()
|
18
|
+
|
19
|
+
def test_reset_failed_messages(self):
|
20
|
+
message = "Test message"
|
21
|
+
self.webhook_1._error_queue.enqueue(message)
|
22
|
+
self.webhook_1._error_queue.enqueue(message)
|
23
|
+
self.assertEqual(self.webhook_1._error_queue.size(), 2)
|
24
|
+
self.assertEqual(self.webhook_1._main_queue.size(), 0)
|
25
|
+
self.webhook_1.reset_failed_messages()
|
26
|
+
self.assertEqual(self.webhook_1._error_queue.size(), 0)
|
27
|
+
self.assertEqual(self.webhook_1._main_queue.size(), 2)
|
28
|
+
|
29
|
+
def test_should_enqueue_and_dequeue_message_from_main_queue(self):
|
30
|
+
m1 = DiscordMessage(content="content")
|
31
|
+
self.webhook_1.enqueue_message(m1)
|
32
|
+
m2 = self.webhook_1.dequeue_message()
|
33
|
+
self.assertEqual(m1, m2)
|
34
|
+
|
35
|
+
def test_should_enqueue_and_dequeue_message_from_error_queue(self):
|
36
|
+
m1 = DiscordMessage(content="content")
|
37
|
+
self.webhook_1.enqueue_message(m1, is_error=True)
|
38
|
+
m2 = self.webhook_1.dequeue_message(is_error=True)
|
39
|
+
self.assertEqual(m1, m2)
|
40
|
+
|
41
|
+
def test_should_return_size_of_main_queue(self):
|
42
|
+
m1 = DiscordMessage(content="content")
|
43
|
+
self.webhook_1.enqueue_message(m1)
|
44
|
+
self.assertEqual(self.webhook_1.messages_queued(), 1)
|
45
|
+
|
46
|
+
def test_should_return_size_of_error_queue(self):
|
47
|
+
m1 = DiscordMessage(content="content")
|
48
|
+
self.webhook_1.enqueue_message(m1, is_error=True)
|
49
|
+
self.assertEqual(self.webhook_1.messages_queued(is_error=True), 1)
|
50
|
+
|
51
|
+
def test_should_clear_main_queue(self):
|
52
|
+
m1 = DiscordMessage(content="content")
|
53
|
+
self.webhook_1.enqueue_message(m1)
|
54
|
+
self.assertEqual(self.webhook_1.messages_queued(), 1)
|
55
|
+
self.webhook_1.delete_queued_messages()
|
56
|
+
self.assertEqual(self.webhook_1.messages_queued(), 0)
|
57
|
+
|
58
|
+
def test_should_clear_error_queue(self):
|
59
|
+
m1 = DiscordMessage(content="content")
|
60
|
+
self.webhook_1.enqueue_message(m1, is_error=True)
|
61
|
+
self.assertEqual(self.webhook_1.messages_queued(is_error=True), 1)
|
62
|
+
self.webhook_1.delete_queued_messages(is_error=True)
|
63
|
+
self.assertEqual(self.webhook_1.messages_queued(is_error=True), 0)
|
@@ -3,44 +3,57 @@ from unittest.mock import patch
|
|
3
3
|
import dhooks_lite
|
4
4
|
import requests_mock
|
5
5
|
|
6
|
-
from django.
|
6
|
+
from django.core.cache import cache
|
7
7
|
from django.test.utils import override_settings
|
8
8
|
|
9
|
+
from app_utils.testing import NoSocketsTestCase
|
10
|
+
|
9
11
|
from killtracker import tasks
|
10
|
-
from killtracker.core.
|
12
|
+
from killtracker.core.zkb import _ZKB_REDISQ_URL
|
11
13
|
|
12
|
-
from .testdata.factories import TrackerFactory
|
13
|
-
from .testdata.helpers import
|
14
|
-
|
14
|
+
from .testdata.factories import TrackerFactory, WebhookFactory
|
15
|
+
from .testdata.helpers import (
|
16
|
+
killmails_data,
|
17
|
+
load_eve_corporations,
|
18
|
+
load_eve_entities,
|
19
|
+
load_eveuniverse,
|
20
|
+
)
|
15
21
|
|
16
22
|
PACKAGE_PATH = "killtracker"
|
17
23
|
|
18
24
|
|
19
25
|
@patch("celery.app.task.Context.called_directly", False) # make retry work with eager
|
20
26
|
@override_settings(CELERY_ALWAYS_EAGER=True)
|
21
|
-
@patch(PACKAGE_PATH + ".core.
|
27
|
+
@patch(PACKAGE_PATH + ".core.zkb.KILLTRACKER_QUEUE_ID", "dummy")
|
28
|
+
@patch(PACKAGE_PATH + ".tasks.workers.is_shutting_down", lambda x: False)
|
22
29
|
@patch(PACKAGE_PATH + ".tasks.is_esi_online", lambda: True)
|
23
|
-
@patch(PACKAGE_PATH + ".
|
30
|
+
@patch(PACKAGE_PATH + ".core.discord.dhooks_lite.Webhook.execute", spec=True)
|
24
31
|
@requests_mock.Mocker()
|
25
|
-
class TestTasksEnd2End(
|
32
|
+
class TestTasksEnd2End(NoSocketsTestCase):
|
26
33
|
@classmethod
|
27
34
|
def setUpClass(cls) -> None:
|
28
35
|
super().setUpClass()
|
29
|
-
|
30
|
-
|
36
|
+
load_eveuniverse()
|
37
|
+
load_eve_corporations()
|
38
|
+
load_eve_entities()
|
39
|
+
cls.webhook = WebhookFactory()
|
40
|
+
cls.tracker = TrackerFactory(
|
31
41
|
name="My Tracker",
|
32
42
|
exclude_null_sec=True,
|
33
43
|
exclude_w_space=True,
|
34
|
-
webhook=cls.
|
44
|
+
webhook=cls.webhook,
|
35
45
|
)
|
36
46
|
|
47
|
+
def setUp(self):
|
48
|
+
cache.clear()
|
49
|
+
|
37
50
|
@patch(PACKAGE_PATH + ".tasks.retry_task_if_esi_is_down", lambda x: None)
|
38
51
|
def test_normal_case(self, requests_mocker, mock_execute):
|
39
52
|
# given
|
40
53
|
mock_execute.return_value = dhooks_lite.WebhookResponse({}, status_code=200)
|
41
54
|
requests_mocker.register_uri(
|
42
55
|
"GET",
|
43
|
-
|
56
|
+
_ZKB_REDISQ_URL,
|
44
57
|
[
|
45
58
|
{"status_code": 200, "json": {"package": killmails_data()[10000001]}},
|
46
59
|
{"status_code": 200, "json": {"package": killmails_data()[10000002]}},
|
@@ -73,7 +86,7 @@ class TestTasksEnd2End(LoadTestDataMixin, TestCase):
|
|
73
86
|
mock_retry_task_if_esi_is_down.side_effect = my_retry_task_if_esi_is_down
|
74
87
|
requests_mocker.register_uri(
|
75
88
|
"GET",
|
76
|
-
|
89
|
+
_ZKB_REDISQ_URL,
|
77
90
|
[
|
78
91
|
{"status_code": 200, "json": {"package": killmails_data()[10000001]}},
|
79
92
|
{"status_code": 200, "json": {"package": None}},
|