django-esi 8.0.0a4__py3-none-any.whl → 8.0.0b1__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.

Potentially problematic release.


This version of django-esi might be problematic. Click here for more details.

esi/tests/test_openapi.py CHANGED
@@ -5,9 +5,10 @@ from django.test import TestCase
5
5
  from datetime import date, timedelta
6
6
 
7
7
  from esi.openapi_clients import ESIClientProvider
8
+ from django.core.cache import cache
8
9
  from django.utils import timezone
9
10
  from httpx import RequestError, HTTPStatusError
10
- from esi.exceptions import ESIErrorLimitException
11
+ from esi.exceptions import ESIErrorLimitException, HTTPNotModified
11
12
  from esi import app_settings
12
13
  from esi import __title__, __url__, __version__
13
14
  import httpx
@@ -69,28 +70,80 @@ class TestClientFunctions(TestCase):
69
70
 
70
71
 
71
72
  class BuildUserAgentTests(TestCase):
72
- app_name = "TestsApp"
73
+ app_name = "TestApp"
73
74
  app_ver = "1.2.3"
74
75
  app_url = "https://tests.pass"
75
76
 
76
77
  def test_build_user_agent_with_url(self):
77
78
  ua = oc._build_user_agent(self.app_name, self.app_ver, self.app_url)
79
+
80
+ expected_app_name = "TestApp"
81
+ expected_title = 'DjangoEsi'
82
+
78
83
  self.assertEqual(
79
84
  (
80
- f"{self.app_name}/{self.app_ver} "
85
+ f"{expected_app_name}/{self.app_ver} "
81
86
  f"({app_settings.ESI_USER_CONTACT_EMAIL}{f'; +{self.app_url})'} "
82
- f"{__title__}/{__version__} (+{__url__})"
87
+ f"{expected_title}/{__version__} (+{__url__})"
88
+ ),
89
+ ua
90
+ )
91
+
92
+ def test_enforce_pascal_case_for_ua_appname_with_space(self):
93
+ """
94
+ Test that the application name is converted to PascalCase in the User-Agent string when it contains spaces.
95
+
96
+ :return:
97
+ :rtype:
98
+ """
99
+
100
+ ua = oc._build_user_agent("test app", self.app_ver, self.app_url)
101
+
102
+ expected_app_name = "TestApp"
103
+ expected_title = 'DjangoEsi'
104
+
105
+ self.assertEqual(
106
+ (
107
+ f"{expected_app_name}/{self.app_ver} "
108
+ f"({app_settings.ESI_USER_CONTACT_EMAIL}{f'; +{self.app_url})'} "
109
+ f"{expected_title}/{__version__} (+{__url__})"
110
+ ),
111
+ ua
112
+ )
113
+
114
+ def test_enforce_pascal_case_for_ua_appname_with_hyphen(self):
115
+ """
116
+ Test that the application name is converted to PascalCase in the User-Agent string when it contains hyphens.
117
+
118
+ :return:
119
+ :rtype:
120
+ """
121
+
122
+ ua = oc._build_user_agent("test-app", self.app_ver, self.app_url)
123
+
124
+ expected_app_name = "TestApp"
125
+ expected_title = 'DjangoEsi'
126
+
127
+ self.assertEqual(
128
+ (
129
+ f"{expected_app_name}/{self.app_ver} "
130
+ f"({app_settings.ESI_USER_CONTACT_EMAIL}{f'; +{self.app_url})'} "
131
+ f"{expected_title}/{__version__} (+{__url__})"
83
132
  ),
84
133
  ua
85
134
  )
86
135
 
87
136
  def test_build_user_agent_without_url(self):
88
137
  ua = oc._build_user_agent(self.app_name, self.app_ver)
138
+
139
+ expected_app_name = "TestApp"
140
+ expected_title = 'DjangoEsi'
141
+
89
142
  self.assertEqual(
90
143
  (
91
- f"{self.app_name}/{self.app_ver} "
144
+ f"{expected_app_name}/{self.app_ver} "
92
145
  f"({app_settings.ESI_USER_CONTACT_EMAIL}) "
93
- f"{__title__}/{__version__} (+{__url__})"
146
+ f"{expected_title}/{__version__} (+{__url__})"
94
147
  ),
95
148
  ua
96
149
  )
@@ -235,8 +288,10 @@ class TestOpenapiClientProvider(TestCase):
235
288
  ua_url=app_url,
236
289
  ua_version=app_ver,
237
290
  compatibility_date="2020-01-01",
291
+ tags=["Status"],
238
292
  spec_file=SPEC_PATH
239
293
  )
294
+ cache.clear()
240
295
 
241
296
  send.return_value = httpx.Response(
242
297
  200,
@@ -250,12 +305,111 @@ class TestOpenapiClientProvider(TestCase):
250
305
 
251
306
  status = esi.client.Status.GetStatus().result()
252
307
  call_args, call_kwargs = send.call_args
308
+
309
+ expected_app_name = "TestsApp"
310
+ expected_title = 'DjangoEsi'
311
+
253
312
  self.assertEqual(
254
313
  call_args[0].headers["user-agent"],
255
314
  (
256
- f"{app_name}/{app_ver} "
315
+ f"{expected_app_name}/{app_ver} "
257
316
  f"({app_settings.ESI_USER_CONTACT_EMAIL}{f'; +{app_url})'} "
258
- f"{__title__}/{__version__} (+{__url__})"
317
+ f"{expected_title}/{__version__} (+{__url__})"
259
318
  )
260
319
  )
261
320
  self.assertEqual(status.players, 1234)
321
+
322
+ @patch.object(httpx.Client, "send")
323
+ def test_etag_hit_cached(self, send: MagicMock):
324
+ app_name = "TestsApp"
325
+ app_ver = "1.2.3"
326
+ app_url = "https://tests.pass"
327
+ etag = "'123456789abcdef123456789abcdef'"
328
+ esi = ESIClientProvider(
329
+ ua_appname=app_name,
330
+ ua_url=app_url,
331
+ ua_version=app_ver,
332
+ compatibility_date="2020-01-01",
333
+ tags=["Status"],
334
+ spec_file=SPEC_PATH
335
+ )
336
+ cache.clear()
337
+
338
+ expires = (
339
+ timezone.now() + timedelta(minutes=5)
340
+ ).strftime('%a, %d %b %Y %H:%M:%S %Z')
341
+
342
+ send.return_value = httpx.Response(
343
+ 200,
344
+ json={
345
+ "players": 1234,
346
+ "server_version": "1234",
347
+ "start_time": "2029-09-19T11:02:08Z"
348
+ },
349
+ headers={
350
+ "etag": etag,
351
+ "expires": expires
352
+ },
353
+ request=httpx.Request(
354
+ "GET",
355
+ "test",
356
+ ),
357
+ )
358
+
359
+ esi.client.Status.GetStatus().result()
360
+
361
+ with self.assertRaises(HTTPNotModified):
362
+ esi.client.Status.GetStatus().result()
363
+
364
+ @patch.object(httpx.Client, "send")
365
+ def test_etag_hit_external(self, send: MagicMock):
366
+ app_name = "TestsApp"
367
+ app_ver = "1.2.3"
368
+ app_url = "https://tests.pass"
369
+ etag = "'123456789abcdef123456789abcdef'"
370
+ esi = ESIClientProvider(
371
+ ua_appname=app_name,
372
+ ua_url=app_url,
373
+ ua_version=app_ver,
374
+ compatibility_date="2020-01-01",
375
+ tags=["Status"],
376
+ spec_file=SPEC_PATH
377
+ )
378
+ cache.clear()
379
+ expires = (
380
+ timezone.now() + timedelta(minutes=5)
381
+ ).strftime('%a, %d %b %Y %H:%M:%S %Z')
382
+
383
+ send.return_value = httpx.Response(
384
+ 200,
385
+ json={
386
+ "players": 1234,
387
+ "server_version": "1234",
388
+ "start_time": "2029-09-19T11:02:08Z"
389
+ },
390
+ headers={
391
+ "etag": etag,
392
+ "expires": expires
393
+ },
394
+ request=httpx.Request(
395
+ "GET",
396
+ "test",
397
+ ),
398
+ )
399
+ esi.client.Status.GetStatus().result()
400
+
401
+ cache.delete(esi.client.Status.GetStatus()._cache_key())
402
+
403
+ send.return_value = httpx.Response(
404
+ 304,
405
+ headers={
406
+ "etag": etag,
407
+ "expires": expires
408
+ },
409
+ request=httpx.Request(
410
+ "GET",
411
+ "test",
412
+ ),
413
+ )
414
+ with self.assertRaises(HTTPNotModified):
415
+ esi.client.Status.GetStatus().result()