black format

This commit is contained in:
Son NK 2020-03-05 11:00:58 +01:00
parent a0372a15de
commit ca70d26285
14 changed files with 34 additions and 74 deletions

View file

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

View file

@ -9,10 +9,7 @@ from itsdangerous import Signer
from app import email_utils
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 (
can_be_used_as_personal_email,
email_already_used,
@ -302,10 +299,7 @@ def auth_google():
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
if user.enable_otp:

View file

@ -55,9 +55,7 @@ def auth_mfa():
if not totp.verify(mfa_token):
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)
if not api_key:

View file

@ -113,9 +113,7 @@ def facebook_callback():
return redirect(url_for("auth.login"))
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"))
LOG.d("create facebook user with %s", facebook_user_data)

View file

@ -91,9 +91,7 @@ def github_callback():
return redirect(url_for("auth.login"))
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"))
LOG.d("create github user")

View file

@ -98,9 +98,7 @@ def google_callback():
return redirect(url_for("auth.login"))
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"))
LOG.d("create google user with %s", google_user_data)

View file

@ -37,15 +37,13 @@ def register():
if form.validate_on_submit():
email = form.email.data.lower()
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:
if email_already_used(email):
flash(f"Email {email} already used", "error")
else:
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()
send_activation_email(user, next_url)

View file

@ -1,10 +1,7 @@
from flask import render_template, redirect, url_for, flash, request
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.email_utils import email_belongs_to_alias_domains, get_email_domain_part
from app.extensions import db

View file

@ -83,9 +83,7 @@ def mailbox_route():
if email_already_used(mailbox_email):
flash(f"{mailbox_email} already used", "error")
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:
new_mailbox = Mailbox.create(
email=mailbox_email, user_id=current_user.id

View file

@ -9,16 +9,10 @@ from app.config import MAILBOX_SECRET
from app.config import URL
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 (
send_email,
render,
)
from app.email_utils import send_email, render
from app.extensions import db
from app.log import LOG
from app.models import (
GenEmail,
DeletedAlias,
)
from app.models import GenEmail, DeletedAlias
from app.models import Mailbox
@ -54,9 +48,7 @@ def mailbox_detail_route(mailbox_id):
):
flash(f"Email {new_email} already used", "error")
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:
mailbox.new_email = new_email
db.session.commit()
@ -96,7 +88,7 @@ def mailbox_detail_route(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(
@ -142,9 +134,7 @@ def mailbox_confirm_change_route():
db.session.commit()
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(
url_for("dashboard.mailbox_detail_route", mailbox_id=mailbox.id)
)

View file

@ -7,16 +7,10 @@ import time
import arrow
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.log import LOG
from app.models import (
User,
Job,
)
from app.models import User, Job
from server import create_app

View file

@ -19,7 +19,7 @@ def test_error_without_pagination(flask_client):
db.session.commit()
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
@ -43,7 +43,7 @@ def test_success_with_pagination(flask_client):
# get aliases on the 1st page, should return PAGE_LIMIT aliases
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 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
# 1 alias is created when user is created
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 len(r.json["aliases"]) == 2

View file

@ -69,7 +69,7 @@ def test_auth_register_success(flask_client):
assert AccountActivation.get(1) is None
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
@ -84,7 +84,7 @@ def test_auth_register_success(flask_client):
def test_auth_register_too_short_password(flask_client):
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
@ -93,7 +93,7 @@ def test_auth_register_too_short_password(flask_client):
def test_auth_activate_success(flask_client):
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
@ -105,14 +105,14 @@ def test_auth_activate_success(flask_client):
assert len(act_code.code) == 6
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
def test_auth_activate_wrong_email(flask_client):
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
@ -122,14 +122,14 @@ def test_auth_activate_user_already_activated(flask_client):
db.session.commit()
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
def test_auth_activate_wrong_code(flask_client):
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
@ -145,7 +145,7 @@ def test_auth_activate_wrong_code(flask_client):
wrong_code = act_code.code + "123"
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
@ -156,7 +156,7 @@ def test_auth_activate_wrong_code(flask_client):
def test_auth_activate_too_many_wrong_code(flask_client):
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
@ -173,13 +173,13 @@ def test_auth_activate_too_many_wrong_code(flask_client):
for _ in range(2):
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
# the activation code is deleted
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
@ -192,7 +192,7 @@ def test_auth_reactivate_success(flask_client):
User.create(email="a@b.c", password="password", name="Test User")
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
# make sure an activation code is created

View file

@ -36,7 +36,7 @@ def test_not_show_unverified_mailbox(flask_client):
Mailbox.create(user_id=user.id, email="m2@example.com", verified=False)
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 "m2@example.com" not in str(r.data)