Skip to content

Commit

Permalink
provided tzinfo=None and return filterwarnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Jibola committed Jan 16, 2024
1 parent 9c8df0b commit 4e21a1e
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion motor/aiohttp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ def _set_standard_headers(self, path, resp, gridout, checksum):

if cache_time > 0:
resp.headers["Expires"] = (
datetime.datetime.now(datetime.timezone.utc)
datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None)
+ datetime.timedelta(seconds=cache_time)
).strftime("%a, %d %b %Y %H:%M:%S GMT")

Expand Down
2 changes: 1 addition & 1 deletion motor/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ async def get(self, path, include_body=True):
if cache_time > 0:
self.set_header(
"Expires",
datetime.datetime.now(datetime.timezone.utc)
datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None)
+ datetime.timedelta(seconds=cache_time),
)
self.set_header("Cache-Control", "max-age=" + str(cache_time))
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ filterwarnings = [
"ignore: The fetch_next property is deprecated:DeprecationWarning",
"ignore:The next_object method is deprecated:DeprecationWarning",
"ignore:unclosed <ssl.SSLSocket:ResourceWarning",
"ignore:datetime.datetime.utcfromtimestamp:DeprecationWarning",
"ignore:datetime.datetime.utcnow:DeprecationWarning",
]

[tool.ruff]
Expand Down
8 changes: 4 additions & 4 deletions test/asyncio_tests/test_aiohttp_gridfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@ def setUpClass(cls):
cls.contents = b"Jesse" * 100 * 1024

# Record when we created the file, to check the Last-Modified header
cls.put_start = datetime.datetime.now(datetime.timezone.utc).replace(microsecond=0)
cls.put_start = datetime.datetime.now(datetime.timezone.utc).replace(microsecond=0, tzinfo=None)
file_id = "id"
cls.file_id = file_id
cls.fs.delete(cls.file_id)
cls.fs.put(cls.contents, _id=file_id, filename="foo", content_type="my type")
item = cls.fs.get(file_id)
cls.contents_hash = _hash_gridout(item)
cls.put_end = datetime.datetime.now(datetime.timezone.utc).replace(microsecond=0)
cls.put_end = datetime.datetime.now(datetime.timezone.utc).replace(microsecond=0, tzinfo=None)
cls.app = cls.srv = cls.app_handler = None

@classmethod
Expand Down Expand Up @@ -232,7 +232,7 @@ class AIOHTTPTZAwareGridFSHandlerTest(AIOHTTPGridFSHandlerTestBase):
async def test_tz_aware(self):
client = self.asyncio_client(tz_aware=True)
await self.start_app(AIOHTTPGridFS(client.motor_test))
now = datetime.datetime.now(datetime.timezone.utc)
now = datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None)
ago = now - datetime.timedelta(minutes=10)
hence = now + datetime.timedelta(minutes=10)

Expand Down Expand Up @@ -276,7 +276,7 @@ def extras(response, gridout):
self.assertRegex(cache_control, r"max-age=\d+")
self.assertEqual(10, int(cache_control.split("=")[1]))
expiration = parse_date(response.headers["Expires"])
now = datetime.datetime.now(datetime.timezone.utc)
now = datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None)

# It should expire about 10 seconds from now
self.assertTrue(
Expand Down
8 changes: 4 additions & 4 deletions test/tornado_tests/test_motor_web.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ def setUp(self):
self.contents = b"Jesse" * 100 * 1024

# Record when we created the file, to check the Last-Modified header
self.put_start = datetime.datetime.now(datetime.timezone.utc).replace(microsecond=0)
self.put_start = datetime.datetime.now(datetime.timezone.utc).replace(microsecond=0, tzinfo=None)
file_id = "id"
self.file_id = file_id
self.fs.delete(self.file_id)
self.fs.put(self.contents, _id=file_id, filename="foo", content_type="my type")

item = self.fs.get(file_id)
self.contents_hash = _hash_gridout(item)
self.put_end = datetime.datetime.now(datetime.timezone.utc).replace(microsecond=0)
self.put_end = datetime.datetime.now(datetime.timezone.utc).replace(microsecond=0, tzinfo=None)
self.assertTrue(self.fs.get_last_version("foo"))

def motor_db(self, **kwargs):
Expand Down Expand Up @@ -174,7 +174,7 @@ def motor_db(self):
return super().motor_db(tz_aware=True)

def test_tz_aware(self):
now = datetime.datetime.now(datetime.timezone.utc)
now = datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None)
ago = now - datetime.timedelta(minutes=10)
hence = now + datetime.timedelta(minutes=10)

Expand Down Expand Up @@ -219,7 +219,7 @@ def test_get_gridfs_file(self):
# It should expire about 10 seconds from now
self.assertTrue(
datetime.timedelta(seconds=8)
< expires - datetime.datetime.now(datetime.timezone.utc)
< expires - datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None)
< datetime.timedelta(seconds=12)
)

Expand Down

0 comments on commit 4e21a1e

Please sign in to comment.