mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-02 13:45:10 -05:00
Enable ruff FBT check and fix resulting complaints
This commit is contained in:
parent
4ebed423a8
commit
8e08ef5746
@ -32,8 +32,7 @@ extend-select = [
|
||||
"RUF", # https://docs.astral.sh/ruff/rules/#ruff-specific-rules-ruf
|
||||
"FLY", # https://docs.astral.sh/ruff/rules/#flynt-fly
|
||||
"PTH", # https://docs.astral.sh/ruff/rules/#flake8-use-pathlib-pth
|
||||
"FBT002", # https://docs.astral.sh/ruff/rules/#flake8-boolean-trap-fbt
|
||||
"FBT001", # https://docs.astral.sh/ruff/rules/#flake8-boolean-trap-fbt
|
||||
"FBT", # https://docs.astral.sh/ruff/rules/#flake8-boolean-trap-fbt
|
||||
]
|
||||
ignore = ["DJ001", "SIM105", "RUF012"]
|
||||
|
||||
|
@ -425,7 +425,7 @@ def autocomplete(
|
||||
|
||||
|
||||
def get_permissions_criterias(user: User | None = None) -> list:
|
||||
user_criterias = [query.Term("has_owner", False)]
|
||||
user_criterias = [query.Term("has_owner", text=False)]
|
||||
if user is not None:
|
||||
if user.is_superuser: # superusers see all docs
|
||||
user_criterias = []
|
||||
|
@ -10,7 +10,7 @@ class TestDelayedQuery(TestCase):
|
||||
super().setUp()
|
||||
# all tests run without permission criteria, so has_no_owner query will always
|
||||
# be appended.
|
||||
self.has_no_owner = query.Or([query.Term("has_owner", False)])
|
||||
self.has_no_owner = query.Or([query.Term("has_owner", text=False)])
|
||||
|
||||
def _get_testset__id__in(self, param, field):
|
||||
return (
|
||||
@ -43,12 +43,12 @@ class TestDelayedQuery(TestCase):
|
||||
def test_get_permission_criteria(self):
|
||||
# tests contains tuples of user instances and the expected filter
|
||||
tests = (
|
||||
(None, [query.Term("has_owner", False)]),
|
||||
(None, [query.Term("has_owner", text=False)]),
|
||||
(User(42, username="foo", is_superuser=True), []),
|
||||
(
|
||||
User(42, username="foo", is_superuser=False),
|
||||
[
|
||||
query.Term("has_owner", False),
|
||||
query.Term("has_owner", text=False),
|
||||
query.Term("owner_id", 42),
|
||||
query.Term("viewer_id", "42"),
|
||||
],
|
||||
|
@ -148,7 +148,7 @@ class UserViewSet(ModelViewSet):
|
||||
).first()
|
||||
if authenticator is not None:
|
||||
delete_and_cleanup(request, authenticator)
|
||||
return Response(True)
|
||||
return Response(data=True)
|
||||
else:
|
||||
return HttpResponseNotFound("TOTP not found")
|
||||
|
||||
@ -262,7 +262,7 @@ class TOTPView(GenericAPIView):
|
||||
).first()
|
||||
if authenticator is not None:
|
||||
delete_and_cleanup(request, authenticator)
|
||||
return Response(True)
|
||||
return Response(data=True)
|
||||
else:
|
||||
return HttpResponseNotFound("TOTP not found")
|
||||
|
||||
|
@ -121,7 +121,7 @@ class MarkReadMailAction(BaseMailAction):
|
||||
return {"seen": False}
|
||||
|
||||
def post_consume(self, M: MailBox, message_uid: str, parameter: str):
|
||||
M.flag(message_uid, [MailMessageFlags.SEEN], True)
|
||||
M.flag(message_uid, [MailMessageFlags.SEEN], value=True)
|
||||
|
||||
|
||||
class MoveMailAction(BaseMailAction):
|
||||
@ -142,7 +142,7 @@ class FlagMailAction(BaseMailAction):
|
||||
return {"flagged": False}
|
||||
|
||||
def post_consume(self, M: MailBox, message_uid: str, parameter: str):
|
||||
M.flag(message_uid, [MailMessageFlags.FLAGGED], True)
|
||||
M.flag(message_uid, [MailMessageFlags.FLAGGED], value=True)
|
||||
|
||||
|
||||
class TagMailAction(BaseMailAction):
|
||||
@ -188,19 +188,19 @@ class TagMailAction(BaseMailAction):
|
||||
M.flag(
|
||||
message_uid,
|
||||
set(itertools.chain(*APPLE_MAIL_TAG_COLORS.values())),
|
||||
False,
|
||||
value=False,
|
||||
)
|
||||
|
||||
# Set new $MailFlagBits
|
||||
M.flag(message_uid, APPLE_MAIL_TAG_COLORS.get(self.color), True)
|
||||
M.flag(message_uid, APPLE_MAIL_TAG_COLORS.get(self.color), value=True)
|
||||
|
||||
# Set the general \Flagged
|
||||
# This defaults to the "red" flag in AppleMail and
|
||||
# "stars" in Thunderbird or GMail
|
||||
M.flag(message_uid, [MailMessageFlags.FLAGGED], True)
|
||||
M.flag(message_uid, [MailMessageFlags.FLAGGED], value=True)
|
||||
|
||||
elif self.keyword:
|
||||
M.flag(message_uid, [self.keyword], True)
|
||||
M.flag(message_uid, [self.keyword], value=True)
|
||||
|
||||
else:
|
||||
raise MailError("No keyword specified.")
|
||||
|
@ -784,12 +784,18 @@ class TestMail(
|
||||
)
|
||||
|
||||
self.assertEqual(len(self.mailMocker.bogus_mailbox.messages), 3)
|
||||
self.assertEqual(len(self.mailMocker.bogus_mailbox.fetch("UNSEEN", False)), 2)
|
||||
self.assertEqual(
|
||||
len(self.mailMocker.bogus_mailbox.fetch("UNSEEN", mark_seen=False)),
|
||||
2,
|
||||
)
|
||||
|
||||
self.mail_account_handler.handle_mail_account(account)
|
||||
self.mailMocker.apply_mail_actions()
|
||||
|
||||
self.assertEqual(len(self.mailMocker.bogus_mailbox.fetch("UNSEEN", False)), 0)
|
||||
self.assertEqual(
|
||||
len(self.mailMocker.bogus_mailbox.fetch("UNSEEN", mark_seen=False)),
|
||||
0,
|
||||
)
|
||||
self.assertEqual(len(self.mailMocker.bogus_mailbox.messages), 3)
|
||||
|
||||
def test_handle_mail_account_delete(self):
|
||||
@ -854,7 +860,7 @@ class TestMail(
|
||||
|
||||
self.assertEqual(len(self.mailMocker.bogus_mailbox.messages), 3)
|
||||
self.assertEqual(
|
||||
len(self.mailMocker.bogus_mailbox.fetch("UNFLAGGED", False)),
|
||||
len(self.mailMocker.bogus_mailbox.fetch("UNFLAGGED", mark_seen=False)),
|
||||
2,
|
||||
)
|
||||
|
||||
@ -862,7 +868,7 @@ class TestMail(
|
||||
self.mailMocker.apply_mail_actions()
|
||||
|
||||
self.assertEqual(
|
||||
len(self.mailMocker.bogus_mailbox.fetch("UNFLAGGED", False)),
|
||||
len(self.mailMocker.bogus_mailbox.fetch("UNFLAGGED", mark_seen=False)),
|
||||
1,
|
||||
)
|
||||
self.assertEqual(len(self.mailMocker.bogus_mailbox.messages), 3)
|
||||
@ -935,7 +941,12 @@ class TestMail(
|
||||
|
||||
self.assertEqual(len(self.mailMocker.bogus_mailbox.messages), 3)
|
||||
self.assertEqual(
|
||||
len(self.mailMocker.bogus_mailbox.fetch("UNKEYWORD processed", False)),
|
||||
len(
|
||||
self.mailMocker.bogus_mailbox.fetch(
|
||||
"UNKEYWORD processed",
|
||||
mark_seen=False,
|
||||
),
|
||||
),
|
||||
2,
|
||||
)
|
||||
|
||||
@ -944,7 +955,12 @@ class TestMail(
|
||||
|
||||
self.assertEqual(len(self.mailMocker.bogus_mailbox.messages), 3)
|
||||
self.assertEqual(
|
||||
len(self.mailMocker.bogus_mailbox.fetch("UNKEYWORD processed", False)),
|
||||
len(
|
||||
self.mailMocker.bogus_mailbox.fetch(
|
||||
"UNKEYWORD processed",
|
||||
mark_seen=False,
|
||||
),
|
||||
),
|
||||
0,
|
||||
)
|
||||
|
||||
@ -968,12 +984,18 @@ class TestMail(
|
||||
|
||||
self.assertEqual(len(self.mailMocker.bogus_mailbox.messages), 3)
|
||||
criteria = NOT(gmail_label="processed")
|
||||
self.assertEqual(len(self.mailMocker.bogus_mailbox.fetch(criteria, False)), 2)
|
||||
self.assertEqual(
|
||||
len(self.mailMocker.bogus_mailbox.fetch(criteria, mark_seen=False)),
|
||||
2,
|
||||
)
|
||||
|
||||
self.mail_account_handler.handle_mail_account(account)
|
||||
self.mailMocker.apply_mail_actions()
|
||||
|
||||
self.assertEqual(len(self.mailMocker.bogus_mailbox.fetch(criteria, False)), 0)
|
||||
self.assertEqual(
|
||||
len(self.mailMocker.bogus_mailbox.fetch(criteria, mark_seen=False)),
|
||||
0,
|
||||
)
|
||||
self.assertEqual(len(self.mailMocker.bogus_mailbox.messages), 3)
|
||||
|
||||
def test_tag_mail_action_applemail_wrong_input(self):
|
||||
@ -1003,7 +1025,7 @@ class TestMail(
|
||||
|
||||
self.assertEqual(len(self.mailMocker.bogus_mailbox.messages), 3)
|
||||
self.assertEqual(
|
||||
len(self.mailMocker.bogus_mailbox.fetch("UNFLAGGED", False)),
|
||||
len(self.mailMocker.bogus_mailbox.fetch("UNFLAGGED", mark_seen=False)),
|
||||
2,
|
||||
)
|
||||
|
||||
@ -1011,7 +1033,7 @@ class TestMail(
|
||||
self.mailMocker.apply_mail_actions()
|
||||
|
||||
self.assertEqual(
|
||||
len(self.mailMocker.bogus_mailbox.fetch("UNFLAGGED", False)),
|
||||
len(self.mailMocker.bogus_mailbox.fetch("UNFLAGGED", mark_seen=False)),
|
||||
0,
|
||||
)
|
||||
self.assertEqual(len(self.mailMocker.bogus_mailbox.messages), 3)
|
||||
@ -1325,13 +1347,19 @@ class TestMail(
|
||||
|
||||
self.assertEqual(len(self.mailMocker.bogus_mailbox.messages), 3)
|
||||
self.mailMocker._queue_consumption_tasks_mock.assert_not_called()
|
||||
self.assertEqual(len(self.mailMocker.bogus_mailbox.fetch("UNSEEN", False)), 2)
|
||||
self.assertEqual(
|
||||
len(self.mailMocker.bogus_mailbox.fetch("UNSEEN", mark_seen=False)),
|
||||
2,
|
||||
)
|
||||
|
||||
self.mail_account_handler.handle_mail_account(account)
|
||||
self.mailMocker.apply_mail_actions()
|
||||
|
||||
self.assertEqual(self.mailMocker._queue_consumption_tasks_mock.call_count, 2)
|
||||
self.assertEqual(len(self.mailMocker.bogus_mailbox.fetch("UNSEEN", False)), 0)
|
||||
self.assertEqual(
|
||||
len(self.mailMocker.bogus_mailbox.fetch("UNSEEN", mark_seen=False)),
|
||||
0,
|
||||
)
|
||||
self.assertEqual(len(self.mailMocker.bogus_mailbox.messages), 3)
|
||||
|
||||
def test_auth_plain_fallback_fails_still(self):
|
||||
@ -1391,13 +1419,19 @@ class TestMail(
|
||||
|
||||
self.assertEqual(len(self.mailMocker.bogus_mailbox.messages), 3)
|
||||
self.assertEqual(self.mailMocker._queue_consumption_tasks_mock.call_count, 0)
|
||||
self.assertEqual(len(self.mailMocker.bogus_mailbox.fetch("UNSEEN", False)), 2)
|
||||
self.assertEqual(
|
||||
len(self.mailMocker.bogus_mailbox.fetch("UNSEEN", mark_seen=False)),
|
||||
2,
|
||||
)
|
||||
|
||||
self.mail_account_handler.handle_mail_account(account)
|
||||
self.mailMocker.apply_mail_actions()
|
||||
|
||||
self.assertEqual(self.mailMocker._queue_consumption_tasks_mock.call_count, 2)
|
||||
self.assertEqual(len(self.mailMocker.bogus_mailbox.fetch("UNSEEN", False)), 0)
|
||||
self.assertEqual(
|
||||
len(self.mailMocker.bogus_mailbox.fetch("UNSEEN", mark_seen=False)),
|
||||
0,
|
||||
)
|
||||
self.assertEqual(len(self.mailMocker.bogus_mailbox.messages), 3)
|
||||
|
||||
def test_disabled_rule(self):
|
||||
@ -1426,12 +1460,15 @@ class TestMail(
|
||||
self.mailMocker.apply_mail_actions()
|
||||
|
||||
self.assertEqual(len(self.mailMocker.bogus_mailbox.messages), 3)
|
||||
self.assertEqual(len(self.mailMocker.bogus_mailbox.fetch("UNSEEN", False)), 2)
|
||||
self.assertEqual(
|
||||
len(self.mailMocker.bogus_mailbox.fetch("UNSEEN", mark_seen=False)),
|
||||
2,
|
||||
)
|
||||
|
||||
self.mail_account_handler.handle_mail_account(account)
|
||||
self.mailMocker.apply_mail_actions()
|
||||
self.assertEqual(
|
||||
len(self.mailMocker.bogus_mailbox.fetch("UNSEEN", False)),
|
||||
len(self.mailMocker.bogus_mailbox.fetch("UNSEEN", mark_seen=False)),
|
||||
2,
|
||||
) # still 2
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user