mirror of https://github.com/zulip/zulip.git
python: Prevent bare timedelta(), which defaults to days.
This commit is contained in:
parent
0f132cef4d
commit
82c08dd153
|
@ -266,3 +266,19 @@ rules:
|
||||||
message: "Replace functools.partial with returns.curry.partial for type safety"
|
message: "Replace functools.partial with returns.curry.partial for type safety"
|
||||||
languages: [python]
|
languages: [python]
|
||||||
severity: ERROR
|
severity: ERROR
|
||||||
|
|
||||||
|
- id: timedelta-positional-argument
|
||||||
|
patterns:
|
||||||
|
- pattern: timedelta(...)
|
||||||
|
- pattern-not: timedelta(0)
|
||||||
|
- pattern-not: timedelta(..., days=..., ...)
|
||||||
|
- pattern-not: timedelta(..., seconds=..., ...)
|
||||||
|
- pattern-not: timedelta(..., microseconds=..., ...)
|
||||||
|
- pattern-not: timedelta(..., milliseconds=..., ...)
|
||||||
|
- pattern-not: timedelta(..., minutes=..., ...)
|
||||||
|
- pattern-not: timedelta(..., hours=..., ...)
|
||||||
|
- pattern-not: timedelta(..., weeks=..., ...)
|
||||||
|
message: |
|
||||||
|
Specify timedelta with named arguments.
|
||||||
|
languages: [python]
|
||||||
|
severity: ERROR
|
||||||
|
|
|
@ -1709,7 +1709,7 @@ Output:
|
||||||
|
|
||||||
def set_age(user_name: str, age: int) -> None:
|
def set_age(user_name: str, age: int) -> None:
|
||||||
user = self.example_user(user_name)
|
user = self.example_user(user_name)
|
||||||
user.date_joined = timezone_now() - timedelta(age)
|
user.date_joined = timezone_now() - timedelta(days=age)
|
||||||
user.save()
|
user.save()
|
||||||
|
|
||||||
do_set_realm_property(realm, "waiting_period_threshold", 1000, acting_user=None)
|
do_set_realm_property(realm, "waiting_period_threshold", 1000, acting_user=None)
|
||||||
|
|
|
@ -172,7 +172,7 @@ class ArchiveMessagesTestingBase(RetentionTestingBase):
|
||||||
)
|
)
|
||||||
self._change_messages_date_sent(
|
self._change_messages_date_sent(
|
||||||
msg_ids,
|
msg_ids,
|
||||||
timezone_now() - timedelta(ZULIP_REALM_DAYS + 1),
|
timezone_now() - timedelta(days=ZULIP_REALM_DAYS + 1),
|
||||||
)
|
)
|
||||||
|
|
||||||
return msg_ids
|
return msg_ids
|
||||||
|
@ -240,7 +240,7 @@ class TestArchiveMessagesGeneral(ArchiveMessagesTestingBase):
|
||||||
)
|
)
|
||||||
self._change_messages_date_sent(
|
self._change_messages_date_sent(
|
||||||
expired_zulip_msg_ids,
|
expired_zulip_msg_ids,
|
||||||
timezone_now() - timedelta(ZULIP_REALM_DAYS + 1),
|
timezone_now() - timedelta(days=ZULIP_REALM_DAYS + 1),
|
||||||
)
|
)
|
||||||
|
|
||||||
expired_msg_ids = expired_mit_msg_ids + expired_zulip_msg_ids
|
expired_msg_ids = expired_mit_msg_ids + expired_zulip_msg_ids
|
||||||
|
@ -273,7 +273,7 @@ class TestArchiveMessagesGeneral(ArchiveMessagesTestingBase):
|
||||||
)
|
)
|
||||||
self._change_messages_date_sent(
|
self._change_messages_date_sent(
|
||||||
zulip_msg_ids,
|
zulip_msg_ids,
|
||||||
timezone_now() - timedelta(ZULIP_REALM_DAYS + 1),
|
timezone_now() - timedelta(days=ZULIP_REALM_DAYS + 1),
|
||||||
)
|
)
|
||||||
|
|
||||||
# Only MIT has a retention policy:
|
# Only MIT has a retention policy:
|
||||||
|
@ -323,7 +323,9 @@ class TestArchiveMessagesGeneral(ArchiveMessagesTestingBase):
|
||||||
msg_ids += [self._send_personal_message_to_cross_realm_bot() for i in range(1, 7)]
|
msg_ids += [self._send_personal_message_to_cross_realm_bot() for i in range(1, 7)]
|
||||||
usermsg_ids = self._get_usermessage_ids(msg_ids)
|
usermsg_ids = self._get_usermessage_ids(msg_ids)
|
||||||
# Make the message expired in the Zulip realm.:
|
# Make the message expired in the Zulip realm.:
|
||||||
self._change_messages_date_sent(msg_ids, timezone_now() - timedelta(ZULIP_REALM_DAYS + 1))
|
self._change_messages_date_sent(
|
||||||
|
msg_ids, timezone_now() - timedelta(days=ZULIP_REALM_DAYS + 1)
|
||||||
|
)
|
||||||
|
|
||||||
archive_messages()
|
archive_messages()
|
||||||
self._verify_archive_data(msg_ids, usermsg_ids)
|
self._verify_archive_data(msg_ids, usermsg_ids)
|
||||||
|
@ -376,7 +378,7 @@ class TestArchiveMessagesGeneral(ArchiveMessagesTestingBase):
|
||||||
# Make the message expired in the recipient's realm:
|
# Make the message expired in the recipient's realm:
|
||||||
self._change_messages_date_sent(
|
self._change_messages_date_sent(
|
||||||
[expired_crossrealm_msg_id],
|
[expired_crossrealm_msg_id],
|
||||||
timezone_now() - timedelta(ZULIP_REALM_DAYS + 1),
|
timezone_now() - timedelta(days=ZULIP_REALM_DAYS + 1),
|
||||||
)
|
)
|
||||||
|
|
||||||
expired_msg_ids = [*expired_mit_msg_ids, *expired_zulip_msg_ids, expired_crossrealm_msg_id]
|
expired_msg_ids = [*expired_mit_msg_ids, *expired_zulip_msg_ids, expired_crossrealm_msg_id]
|
||||||
|
|
Loading…
Reference in New Issue