mirror of
https://github.com/ansible-collections/community.crypto.git
synced 2026-03-26 21:33:25 +00:00
Remove Python 2 specific code (#877)
* Get rid of Python 2 special handling. * Get rid of more Python 2 specific handling. * Stop using six. * ipaddress is part of the standard library since Python 3. * Add changelog. * Fix import. * Remove unneeded imports.
This commit is contained in:
@@ -7,7 +7,6 @@ from __future__ import annotations
|
||||
import base64
|
||||
import datetime
|
||||
import os
|
||||
import sys
|
||||
|
||||
from ansible_collections.community.crypto.plugins.module_utils.acme.backends import (
|
||||
CertificateInformation,
|
||||
@@ -154,34 +153,25 @@ TEST_PARSE_ACME_TIMESTAMP = cartesian_product(
|
||||
microsecond=333333,
|
||||
),
|
||||
),
|
||||
(
|
||||
"2024-01-01T00:11:22+0100",
|
||||
dict(year=2023, month=12, day=31, hour=23, minute=11, second=22),
|
||||
),
|
||||
(
|
||||
"2024-01-01T00:11:22.123+0100",
|
||||
dict(
|
||||
year=2023,
|
||||
month=12,
|
||||
day=31,
|
||||
hour=23,
|
||||
minute=11,
|
||||
second=22,
|
||||
microsecond=123000,
|
||||
),
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
if sys.version_info >= (3, 5):
|
||||
TEST_PARSE_ACME_TIMESTAMP.extend(
|
||||
cartesian_product(
|
||||
TIMEZONES,
|
||||
[
|
||||
(
|
||||
"2024-01-01T00:11:22+0100",
|
||||
dict(year=2023, month=12, day=31, hour=23, minute=11, second=22),
|
||||
),
|
||||
(
|
||||
"2024-01-01T00:11:22.123+0100",
|
||||
dict(
|
||||
year=2023,
|
||||
month=12,
|
||||
day=31,
|
||||
hour=23,
|
||||
minute=11,
|
||||
second=22,
|
||||
microsecond=123000,
|
||||
),
|
||||
),
|
||||
],
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
TEST_INTERPOLATE_TIMESTAMP = cartesian_product(
|
||||
TIMEZONES,
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import datetime
|
||||
import sys
|
||||
|
||||
import pytest
|
||||
from ansible.module_utils.common.collections import is_sequence
|
||||
@@ -47,6 +46,8 @@ def cartesian_product(list1, list2):
|
||||
return result
|
||||
|
||||
|
||||
ONE_HOUR_PLUS = datetime.timezone(datetime.timedelta(hours=1))
|
||||
|
||||
TEST_REMOVE_TIMEZONE = cartesian_product(
|
||||
TIMEZONES,
|
||||
[
|
||||
@@ -58,6 +59,10 @@ TEST_REMOVE_TIMEZONE = cartesian_product(
|
||||
datetime.datetime(2024, 1, 1, 0, 1, 2),
|
||||
datetime.datetime(2024, 1, 1, 0, 1, 2),
|
||||
),
|
||||
(
|
||||
datetime.datetime(2024, 1, 1, 0, 1, 2, tzinfo=ONE_HOUR_PLUS),
|
||||
datetime.datetime(2023, 12, 31, 23, 1, 2),
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -72,6 +77,10 @@ TEST_UTC_TIMEZONE = cartesian_product(
|
||||
datetime.datetime(2024, 1, 1, 0, 1, 2, tzinfo=UTC),
|
||||
datetime.datetime(2024, 1, 1, 0, 1, 2, tzinfo=UTC),
|
||||
),
|
||||
(
|
||||
datetime.datetime(2024, 1, 1, 0, 1, 2, tzinfo=ONE_HOUR_PLUS),
|
||||
datetime.datetime(2023, 12, 31, 23, 1, 2, tzinfo=UTC),
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -109,6 +118,10 @@ TEST_EPOCH_TO_SECONDS = cartesian_product(
|
||||
[
|
||||
(datetime.datetime(1970, 1, 1, 0, 1, 2, 0), 62),
|
||||
(datetime.datetime(1970, 1, 1, 0, 1, 2, 0, tzinfo=UTC), 62),
|
||||
(
|
||||
datetime.datetime(1970, 1, 1, 0, 1, 2, 0, tzinfo=ONE_HOUR_PLUS),
|
||||
62 - 3600,
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -221,87 +234,42 @@ TEST_GET_RELATIVE_TIME_OPTION = cartesian_product(
|
||||
datetime.datetime(2024, 1, 1, 0, 0, 0),
|
||||
datetime.datetime(2024, 1, 2, 4, 5, 0, tzinfo=UTC),
|
||||
),
|
||||
(
|
||||
"20240102040506+0100",
|
||||
"foo",
|
||||
"cryptography",
|
||||
False,
|
||||
datetime.datetime(2024, 1, 1, 0, 0, 0),
|
||||
datetime.datetime(2024, 1, 2, 3, 5, 6),
|
||||
),
|
||||
(
|
||||
"202401020405+0100",
|
||||
"foo",
|
||||
"cryptography",
|
||||
False,
|
||||
datetime.datetime(2024, 1, 1, 0, 0, 0),
|
||||
datetime.datetime(2024, 1, 2, 3, 5, 0),
|
||||
),
|
||||
(
|
||||
"20240102040506+0100",
|
||||
"foo",
|
||||
"cryptography",
|
||||
True,
|
||||
datetime.datetime(2024, 1, 1, 0, 0, 0),
|
||||
datetime.datetime(2024, 1, 2, 3, 5, 6, tzinfo=UTC),
|
||||
),
|
||||
(
|
||||
"202401020405+0100",
|
||||
"foo",
|
||||
"cryptography",
|
||||
True,
|
||||
datetime.datetime(2024, 1, 1, 0, 0, 0),
|
||||
datetime.datetime(2024, 1, 2, 3, 5, 0, tzinfo=UTC),
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
if sys.version_info >= (3, 5):
|
||||
ONE_HOUR_PLUS = datetime.timezone(datetime.timedelta(hours=1))
|
||||
|
||||
TEST_REMOVE_TIMEZONE.extend(
|
||||
cartesian_product(
|
||||
TIMEZONES,
|
||||
[
|
||||
(
|
||||
datetime.datetime(2024, 1, 1, 0, 1, 2, tzinfo=ONE_HOUR_PLUS),
|
||||
datetime.datetime(2023, 12, 31, 23, 1, 2),
|
||||
),
|
||||
],
|
||||
)
|
||||
)
|
||||
TEST_UTC_TIMEZONE.extend(
|
||||
cartesian_product(
|
||||
TIMEZONES,
|
||||
[
|
||||
(
|
||||
datetime.datetime(2024, 1, 1, 0, 1, 2, tzinfo=ONE_HOUR_PLUS),
|
||||
datetime.datetime(2023, 12, 31, 23, 1, 2, tzinfo=UTC),
|
||||
),
|
||||
],
|
||||
)
|
||||
)
|
||||
TEST_EPOCH_TO_SECONDS.extend(
|
||||
cartesian_product(
|
||||
TIMEZONES,
|
||||
[
|
||||
(
|
||||
datetime.datetime(1970, 1, 1, 0, 1, 2, 0, tzinfo=ONE_HOUR_PLUS),
|
||||
62 - 3600,
|
||||
),
|
||||
],
|
||||
)
|
||||
)
|
||||
TEST_GET_RELATIVE_TIME_OPTION.extend(
|
||||
cartesian_product(
|
||||
TIMEZONES,
|
||||
[
|
||||
(
|
||||
"20240102040506+0100",
|
||||
"foo",
|
||||
"cryptography",
|
||||
False,
|
||||
datetime.datetime(2024, 1, 1, 0, 0, 0),
|
||||
datetime.datetime(2024, 1, 2, 3, 5, 6),
|
||||
),
|
||||
(
|
||||
"202401020405+0100",
|
||||
"foo",
|
||||
"cryptography",
|
||||
False,
|
||||
datetime.datetime(2024, 1, 1, 0, 0, 0),
|
||||
datetime.datetime(2024, 1, 2, 3, 5, 0),
|
||||
),
|
||||
(
|
||||
"20240102040506+0100",
|
||||
"foo",
|
||||
"cryptography",
|
||||
True,
|
||||
datetime.datetime(2024, 1, 1, 0, 0, 0),
|
||||
datetime.datetime(2024, 1, 2, 3, 5, 6, tzinfo=UTC),
|
||||
),
|
||||
(
|
||||
"202401020405+0100",
|
||||
"foo",
|
||||
"cryptography",
|
||||
True,
|
||||
datetime.datetime(2024, 1, 1, 0, 0, 0),
|
||||
datetime.datetime(2024, 1, 2, 3, 5, 0, tzinfo=UTC),
|
||||
),
|
||||
],
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("timezone, input, expected", TEST_REMOVE_TIMEZONE)
|
||||
def test_remove_timezone(timezone, input, expected):
|
||||
with freeze_time("2024-02-03 04:05:06", tz_offset=timezone):
|
||||
|
||||
Reference in New Issue
Block a user