浏览代码

black format

Son NK 5 年之前
父节点
当前提交
ca70d26285

+ 1 - 4
app/api/views/alias.py

@@ -155,7 +155,4 @@ def get_alias_activities(alias_id):
 
 
         activities.append(activity)
         activities.append(activity)
 
 
-    return (
-        jsonify(activities=activities),
-        200,
-    )
+    return (jsonify(activities=activities), 200)

+ 2 - 8
app/api/views/auth_login.py

@@ -9,10 +9,7 @@ from itsdangerous import Signer
 
 
 from app import email_utils
 from app import email_utils
 from app.api.base import api_bp
 from app.api.base import api_bp
-from app.config import (
-    FLASK_SECRET,
-    DISABLE_REGISTRATION,
-)
+from app.config import FLASK_SECRET, DISABLE_REGISTRATION
 from app.email_utils import (
 from app.email_utils import (
     can_be_used_as_personal_email,
     can_be_used_as_personal_email,
     email_already_used,
     email_already_used,
@@ -302,10 +299,7 @@ def auth_google():
 
 
 
 
 def auth_payload(user, device) -> dict:
 def auth_payload(user, device) -> dict:
-    ret = {
-        "name": user.name,
-        "mfa_enabled": user.enable_otp,
-    }
+    ret = {"name": user.name, "mfa_enabled": user.enable_otp}
 
 
     # do not give api_key, user can only obtain api_key after OTP verification
     # do not give api_key, user can only obtain api_key after OTP verification
     if user.enable_otp:
     if user.enable_otp:

+ 1 - 3
app/api/views/auth_mfa.py

@@ -55,9 +55,7 @@ def auth_mfa():
     if not totp.verify(mfa_token):
     if not totp.verify(mfa_token):
         return jsonify(error="Wrong TOTP Token"), 400
         return jsonify(error="Wrong TOTP Token"), 400
 
 
-    ret = {
-        "name": user.name,
-    }
+    ret = {"name": user.name}
 
 
     api_key = ApiKey.get_by(user_id=user.id, name=device)
     api_key = ApiKey.get_by(user_id=user.id, name=device)
     if not api_key:
     if not api_key:

+ 1 - 3
app/auth/views/facebook.py

@@ -113,9 +113,7 @@ def facebook_callback():
             return redirect(url_for("auth.login"))
             return redirect(url_for("auth.login"))
 
 
         if not can_be_used_as_personal_email(email) or email_already_used(email):
         if not can_be_used_as_personal_email(email) or email_already_used(email):
-            flash(
-                f"You cannot use {email} as your personal inbox.", "error",
-            )
+            flash(f"You cannot use {email} as your personal inbox.", "error")
             return redirect(url_for("auth.login"))
             return redirect(url_for("auth.login"))
 
 
         LOG.d("create facebook user with %s", facebook_user_data)
         LOG.d("create facebook user with %s", facebook_user_data)

+ 1 - 3
app/auth/views/github.py

@@ -91,9 +91,7 @@ def github_callback():
             return redirect(url_for("auth.login"))
             return redirect(url_for("auth.login"))
 
 
         if not can_be_used_as_personal_email(email) or email_already_used(email):
         if not can_be_used_as_personal_email(email) or email_already_used(email):
-            flash(
-                f"You cannot use {email} as your personal inbox.", "error",
-            )
+            flash(f"You cannot use {email} as your personal inbox.", "error")
             return redirect(url_for("auth.login"))
             return redirect(url_for("auth.login"))
 
 
         LOG.d("create github user")
         LOG.d("create github user")

+ 1 - 3
app/auth/views/google.py

@@ -98,9 +98,7 @@ def google_callback():
             return redirect(url_for("auth.login"))
             return redirect(url_for("auth.login"))
 
 
         if not can_be_used_as_personal_email(email) or email_already_used(email):
         if not can_be_used_as_personal_email(email) or email_already_used(email):
-            flash(
-                f"You cannot use {email} as your personal inbox.", "error",
-            )
+            flash(f"You cannot use {email} as your personal inbox.", "error")
             return redirect(url_for("auth.login"))
             return redirect(url_for("auth.login"))
 
 
         LOG.d("create google user with %s", google_user_data)
         LOG.d("create google user with %s", google_user_data)

+ 2 - 4
app/auth/views/register.py

@@ -37,15 +37,13 @@ def register():
     if form.validate_on_submit():
     if form.validate_on_submit():
         email = form.email.data.lower()
         email = form.email.data.lower()
         if not can_be_used_as_personal_email(email):
         if not can_be_used_as_personal_email(email):
-            flash(
-                "You cannot use this email address as your personal inbox.", "error",
-            )
+            flash("You cannot use this email address as your personal inbox.", "error")
         else:
         else:
             if email_already_used(email):
             if email_already_used(email):
                 flash(f"Email {email} already used", "error")
                 flash(f"Email {email} already used", "error")
             else:
             else:
                 LOG.debug("create user %s", form.email.data)
                 LOG.debug("create user %s", form.email.data)
-                user = User.create(email=email, name="", password=form.password.data,)
+                user = User.create(email=email, name="", password=form.password.data)
                 db.session.commit()
                 db.session.commit()
 
 
                 send_activation_email(user, next_url)
                 send_activation_email(user, next_url)

+ 1 - 4
app/dashboard/views/custom_alias.py

@@ -1,10 +1,7 @@
 from flask import render_template, redirect, url_for, flash, request
 from flask import render_template, redirect, url_for, flash, request
 from flask_login import login_required, current_user
 from flask_login import login_required, current_user
 
 
-from app.config import (
-    DISABLE_ALIAS_SUFFIX,
-    ALIAS_DOMAINS,
-)
+from app.config import DISABLE_ALIAS_SUFFIX, ALIAS_DOMAINS
 from app.dashboard.base import dashboard_bp
 from app.dashboard.base import dashboard_bp
 from app.email_utils import email_belongs_to_alias_domains, get_email_domain_part
 from app.email_utils import email_belongs_to_alias_domains, get_email_domain_part
 from app.extensions import db
 from app.extensions import db

+ 1 - 3
app/dashboard/views/mailbox.py

@@ -83,9 +83,7 @@ def mailbox_route():
                 if email_already_used(mailbox_email):
                 if email_already_used(mailbox_email):
                     flash(f"{mailbox_email} already used", "error")
                     flash(f"{mailbox_email} already used", "error")
                 elif not can_be_used_as_personal_email(mailbox_email):
                 elif not can_be_used_as_personal_email(mailbox_email):
-                    flash(
-                        f"You cannot use {mailbox_email}.", "error",
-                    )
+                    flash(f"You cannot use {mailbox_email}.", "error")
                 else:
                 else:
                     new_mailbox = Mailbox.create(
                     new_mailbox = Mailbox.create(
                         email=mailbox_email, user_id=current_user.id
                         email=mailbox_email, user_id=current_user.id

+ 5 - 15
app/dashboard/views/mailbox_detail.py

@@ -9,16 +9,10 @@ from app.config import MAILBOX_SECRET
 from app.config import URL
 from app.config import URL
 from app.dashboard.base import dashboard_bp
 from app.dashboard.base import dashboard_bp
 from app.email_utils import can_be_used_as_personal_email, email_already_used
 from app.email_utils import can_be_used_as_personal_email, email_already_used
-from app.email_utils import (
-    send_email,
-    render,
-)
+from app.email_utils import send_email, render
 from app.extensions import db
 from app.extensions import db
 from app.log import LOG
 from app.log import LOG
-from app.models import (
-    GenEmail,
-    DeletedAlias,
-)
+from app.models import GenEmail, DeletedAlias
 from app.models import Mailbox
 from app.models import Mailbox
 
 
 
 
@@ -54,9 +48,7 @@ def mailbox_detail_route(mailbox_id):
             ):
             ):
                 flash(f"Email {new_email} already used", "error")
                 flash(f"Email {new_email} already used", "error")
             elif not can_be_used_as_personal_email(new_email):
             elif not can_be_used_as_personal_email(new_email):
-                flash(
-                    "You cannot use this email address as your mailbox", "error",
-                )
+                flash("You cannot use this email address as your mailbox", "error")
             else:
             else:
                 mailbox.new_email = new_email
                 mailbox.new_email = new_email
                 db.session.commit()
                 db.session.commit()
@@ -96,7 +88,7 @@ def mailbox_detail_route(mailbox_id):
                     url_for("dashboard.mailbox_detail_route", mailbox_id=mailbox_id)
                     url_for("dashboard.mailbox_detail_route", mailbox_id=mailbox_id)
                 )
                 )
 
 
-    return render_template("dashboard/mailbox_detail.html", **locals(),)
+    return render_template("dashboard/mailbox_detail.html", **locals())
 
 
 
 
 @dashboard_bp.route(
 @dashboard_bp.route(
@@ -142,9 +134,7 @@ def mailbox_confirm_change_route():
         db.session.commit()
         db.session.commit()
 
 
         LOG.d("Mailbox change %s is verified", mailbox)
         LOG.d("Mailbox change %s is verified", mailbox)
-        flash(
-            f"The {mailbox.email} is updated", "success",
-        )
+        flash(f"The {mailbox.email} is updated", "success")
         return redirect(
         return redirect(
             url_for("dashboard.mailbox_detail_route", mailbox_id=mailbox.id)
             url_for("dashboard.mailbox_detail_route", mailbox_id=mailbox.id)
         )
         )

+ 2 - 8
job_runner.py

@@ -7,16 +7,10 @@ import time
 import arrow
 import arrow
 
 
 from app.config import JOB_ONBOARDING_1
 from app.config import JOB_ONBOARDING_1
-from app.email_utils import (
-    send_email,
-    render,
-)
+from app.email_utils import send_email, render
 from app.extensions import db
 from app.extensions import db
 from app.log import LOG
 from app.log import LOG
-from app.models import (
-    User,
-    Job,
-)
+from app.models import User, Job
 from server import create_app
 from server import create_app
 
 
 
 

+ 3 - 3
tests/api/test_alias.py

@@ -19,7 +19,7 @@ def test_error_without_pagination(flask_client):
     db.session.commit()
     db.session.commit()
 
 
     r = flask_client.get(
     r = flask_client.get(
-        url_for("api.get_aliases"), headers={"Authentication": api_key.code},
+        url_for("api.get_aliases"), headers={"Authentication": api_key.code}
     )
     )
 
 
     assert r.status_code == 400
     assert r.status_code == 400
@@ -43,7 +43,7 @@ def test_success_with_pagination(flask_client):
 
 
     # get aliases on the 1st page, should return PAGE_LIMIT aliases
     # get aliases on the 1st page, should return PAGE_LIMIT aliases
     r = flask_client.get(
     r = flask_client.get(
-        url_for("api.get_aliases", page_id=0), headers={"Authentication": api_key.code},
+        url_for("api.get_aliases", page_id=0), headers={"Authentication": api_key.code}
     )
     )
     assert r.status_code == 200
     assert r.status_code == 200
     assert len(r.json["aliases"]) == PAGE_LIMIT
     assert len(r.json["aliases"]) == PAGE_LIMIT
@@ -52,7 +52,7 @@ def test_success_with_pagination(flask_client):
     # as the total number of aliases is PAGE_LIMIT +2
     # as the total number of aliases is PAGE_LIMIT +2
     # 1 alias is created when user is created
     # 1 alias is created when user is created
     r = flask_client.get(
     r = flask_client.get(
-        url_for("api.get_aliases", page_id=1), headers={"Authentication": api_key.code},
+        url_for("api.get_aliases", page_id=1), headers={"Authentication": api_key.code}
     )
     )
     assert r.status_code == 200
     assert r.status_code == 200
     assert len(r.json["aliases"]) == 2
     assert len(r.json["aliases"]) == 2

+ 12 - 12
tests/api/test_auth_login.py

@@ -69,7 +69,7 @@ def test_auth_register_success(flask_client):
     assert AccountActivation.get(1) is None
     assert AccountActivation.get(1) is None
 
 
     r = flask_client.post(
     r = flask_client.post(
-        url_for("api.auth_register"), json={"email": "a@b.c", "password": "password"},
+        url_for("api.auth_register"), json={"email": "a@b.c", "password": "password"}
     )
     )
 
 
     assert r.status_code == 200
     assert r.status_code == 200
@@ -84,7 +84,7 @@ def test_auth_register_success(flask_client):
 
 
 def test_auth_register_too_short_password(flask_client):
 def test_auth_register_too_short_password(flask_client):
     r = flask_client.post(
     r = flask_client.post(
-        url_for("api.auth_register"), json={"email": "a@b.c", "password": "short"},
+        url_for("api.auth_register"), json={"email": "a@b.c", "password": "short"}
     )
     )
 
 
     assert r.status_code == 400
     assert r.status_code == 400
@@ -93,7 +93,7 @@ def test_auth_register_too_short_password(flask_client):
 
 
 def test_auth_activate_success(flask_client):
 def test_auth_activate_success(flask_client):
     r = flask_client.post(
     r = flask_client.post(
-        url_for("api.auth_register"), json={"email": "a@b.c", "password": "password"},
+        url_for("api.auth_register"), json={"email": "a@b.c", "password": "password"}
     )
     )
 
 
     assert r.status_code == 200
     assert r.status_code == 200
@@ -105,14 +105,14 @@ def test_auth_activate_success(flask_client):
     assert len(act_code.code) == 6
     assert len(act_code.code) == 6
 
 
     r = flask_client.post(
     r = flask_client.post(
-        url_for("api.auth_activate"), json={"email": "a@b.c", "code": act_code.code},
+        url_for("api.auth_activate"), json={"email": "a@b.c", "code": act_code.code}
     )
     )
     assert r.status_code == 200
     assert r.status_code == 200
 
 
 
 
 def test_auth_activate_wrong_email(flask_client):
 def test_auth_activate_wrong_email(flask_client):
     r = flask_client.post(
     r = flask_client.post(
-        url_for("api.auth_activate"), json={"email": "a@b.c", "code": "123456"},
+        url_for("api.auth_activate"), json={"email": "a@b.c", "code": "123456"}
     )
     )
     assert r.status_code == 400
     assert r.status_code == 400
 
 
@@ -122,14 +122,14 @@ def test_auth_activate_user_already_activated(flask_client):
     db.session.commit()
     db.session.commit()
 
 
     r = flask_client.post(
     r = flask_client.post(
-        url_for("api.auth_activate"), json={"email": "a@b.c", "code": "123456"},
+        url_for("api.auth_activate"), json={"email": "a@b.c", "code": "123456"}
     )
     )
     assert r.status_code == 400
     assert r.status_code == 400
 
 
 
 
 def test_auth_activate_wrong_code(flask_client):
 def test_auth_activate_wrong_code(flask_client):
     r = flask_client.post(
     r = flask_client.post(
-        url_for("api.auth_register"), json={"email": "a@b.c", "password": "password"},
+        url_for("api.auth_register"), json={"email": "a@b.c", "password": "password"}
     )
     )
 
 
     assert r.status_code == 200
     assert r.status_code == 200
@@ -145,7 +145,7 @@ def test_auth_activate_wrong_code(flask_client):
     wrong_code = act_code.code + "123"
     wrong_code = act_code.code + "123"
 
 
     r = flask_client.post(
     r = flask_client.post(
-        url_for("api.auth_activate"), json={"email": "a@b.c", "code": wrong_code},
+        url_for("api.auth_activate"), json={"email": "a@b.c", "code": wrong_code}
     )
     )
     assert r.status_code == 400
     assert r.status_code == 400
 
 
@@ -156,7 +156,7 @@ def test_auth_activate_wrong_code(flask_client):
 
 
 def test_auth_activate_too_many_wrong_code(flask_client):
 def test_auth_activate_too_many_wrong_code(flask_client):
     r = flask_client.post(
     r = flask_client.post(
-        url_for("api.auth_register"), json={"email": "a@b.c", "password": "password"},
+        url_for("api.auth_register"), json={"email": "a@b.c", "password": "password"}
     )
     )
 
 
     assert r.status_code == 200
     assert r.status_code == 200
@@ -173,13 +173,13 @@ def test_auth_activate_too_many_wrong_code(flask_client):
 
 
     for _ in range(2):
     for _ in range(2):
         r = flask_client.post(
         r = flask_client.post(
-            url_for("api.auth_activate"), json={"email": "a@b.c", "code": wrong_code},
+            url_for("api.auth_activate"), json={"email": "a@b.c", "code": wrong_code}
         )
         )
         assert r.status_code == 400
         assert r.status_code == 400
 
 
     # the activation code is deleted
     # the activation code is deleted
     r = flask_client.post(
     r = flask_client.post(
-        url_for("api.auth_activate"), json={"email": "a@b.c", "code": wrong_code},
+        url_for("api.auth_activate"), json={"email": "a@b.c", "code": wrong_code}
     )
     )
 
 
     assert r.status_code == 410
     assert r.status_code == 410
@@ -192,7 +192,7 @@ def test_auth_reactivate_success(flask_client):
     User.create(email="a@b.c", password="password", name="Test User")
     User.create(email="a@b.c", password="password", name="Test User")
     db.session.commit()
     db.session.commit()
 
 
-    r = flask_client.post(url_for("api.auth_reactivate"), json={"email": "a@b.c"},)
+    r = flask_client.post(url_for("api.auth_reactivate"), json={"email": "a@b.c"})
     assert r.status_code == 200
     assert r.status_code == 200
 
 
     # make sure an activation code is created
     # make sure an activation code is created

+ 1 - 1
tests/dashboard/test_custom_alias.py

@@ -36,7 +36,7 @@ def test_not_show_unverified_mailbox(flask_client):
     Mailbox.create(user_id=user.id, email="m2@example.com", verified=False)
     Mailbox.create(user_id=user.id, email="m2@example.com", verified=False)
     db.session.commit()
     db.session.commit()
 
 
-    r = flask_client.get(url_for("dashboard.custom_alias"),)
+    r = flask_client.get(url_for("dashboard.custom_alias"))
 
 
     assert "m1@example.com" in str(r.data)
     assert "m1@example.com" in str(r.data)
     assert "m2@example.com" not in str(r.data)
     assert "m2@example.com" not in str(r.data)