From e9686352a3b63429e91b632f42edf2319b4d8d32 Mon Sep 17 00:00:00 2001 From: link2xt Date: Wed, 6 Sep 2023 22:10:41 +0000 Subject: [PATCH] chore: fix ruff lint errors --- src/mailadm/bot.py | 2 +- src/mailadm/mailcow.py | 8 ++++---- tests/test_conn.py | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/mailadm/bot.py b/src/mailadm/bot.py index 4644988b..e30b60b0 100644 --- a/src/mailadm/bot.py +++ b/src/mailadm/bot.py @@ -269,7 +269,7 @@ def main(mailadm_db, admbot_db_path): while 1: for logmsg in prune(mailadm_db).get("message"): logging.info("%s", logmsg) - for _second in range(0, 600): + for _second in range(600): if not ac._event_thread.is_alive(): logging.error("dc core event thread died, exiting now") os._exit(1) diff --git a/src/mailadm/mailcow.py b/src/mailadm/mailcow.py index cc99c0f4..9696a966 100644 --- a/src/mailadm/mailcow.py +++ b/src/mailadm/mailcow.py @@ -38,7 +38,7 @@ def add_user_mailcow(self, addr, password, token, quota=0): "tags": ["mailadm:" + token], } result = r.post(url, json=payload, headers=self.auth, timeout=HTTP_TIMEOUT) - if type(result.json()) != list or result.json()[0].get("type") != "success": + if not isinstance(result.json(), list) or result.json()[0].get("type") != "success": raise MailcowError(result.json()) def del_user_mailcow(self, addr): @@ -59,12 +59,12 @@ def get_user(self, addr): json = result.json() if json == {}: return None - if type(json) == dict: + if isinstance(json, dict): if json.get("type") == "error": raise MailcowError(json) return MailcowUser(json) # some mailcow versions return all users, even if you only ask for a specific one: - if type(json) == list: + if isinstance(json, list): for user in [MailcowUser(user) for user in json]: if user.addr == addr: return user @@ -79,7 +79,7 @@ def get_user_list(self): json = result.json() if json == {}: return [] - if type(json) == dict: + if isinstance(json, dict): if json.get("type") == "error": raise MailcowError(json) return [MailcowUser(user) for user in json] diff --git a/tests/test_conn.py b/tests/test_conn.py index 1637a6c6..2305e3f7 100644 --- a/tests/test_conn.py +++ b/tests/test_conn.py @@ -166,7 +166,7 @@ def add_user_db(*args, **kwargs): auth = {"X-API-Key": conn.config.mailcow_token} result = requests.get(url, headers=auth) assert result.status_code == 200 - if result.json() is not {} and type(result.json()) == list: + if result.json() is not {} and not isinstance(result.json(), list): for user in result.json(): assert user["username"] != addr @@ -243,4 +243,4 @@ def test_delete_user_mailcow_missing(conn, mailcow, mailcow_domain): def test_db_version(conn): version = conn.get_dbversion() - assert type(version) == int + assert isinstance(version, int)