fix proton partner error when self host (#1255)
* fix proton partner error when self host * fix test * fix test * remove a@b.c
This commit is contained in:
parent
72256d935c
commit
f69c9583fb
|
@ -1,17 +1,17 @@
|
||||||
import base64
|
import base64
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
from flask import jsonify, g, request, make_response
|
from flask import jsonify, g, request, make_response
|
||||||
from flask_login import logout_user
|
from flask_login import logout_user
|
||||||
from typing import Optional
|
|
||||||
|
|
||||||
from app import s3
|
from app import s3, config
|
||||||
from app.api.base import api_bp, require_api_auth
|
from app.api.base import api_bp, require_api_auth
|
||||||
from app.config import SESSION_COOKIE_NAME
|
from app.config import SESSION_COOKIE_NAME
|
||||||
from app.db import Session
|
from app.db import Session
|
||||||
from app.models import ApiKey, File, PartnerUser, User
|
from app.models import ApiKey, File, PartnerUser, User
|
||||||
from app.utils import random_string
|
|
||||||
from app.proton.utils import get_proton_partner
|
from app.proton.utils import get_proton_partner
|
||||||
|
from app.utils import random_string
|
||||||
|
|
||||||
|
|
||||||
def get_connected_proton_address(user: User) -> Optional[str]:
|
def get_connected_proton_address(user: User) -> Optional[str]:
|
||||||
|
@ -29,9 +29,12 @@ def user_to_dict(user: User) -> dict:
|
||||||
"email": user.email,
|
"email": user.email,
|
||||||
"in_trial": user.in_trial(),
|
"in_trial": user.in_trial(),
|
||||||
"max_alias_free_plan": user.max_alias_for_free_account(),
|
"max_alias_free_plan": user.max_alias_for_free_account(),
|
||||||
"connected_proton_address": get_connected_proton_address(user),
|
"connected_proton_address": None,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if config.CONNECT_WITH_PROTON:
|
||||||
|
ret["connected_proton_address"] = get_connected_proton_address(user)
|
||||||
|
|
||||||
if user.profile_picture_id:
|
if user.profile_picture_id:
|
||||||
ret["profile_picture_url"] = user.profile_picture.get_url()
|
ret["profile_picture_url"] = user.profile_picture.get_url()
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -1,27 +1,17 @@
|
||||||
from flask import url_for
|
|
||||||
import arrow
|
import arrow
|
||||||
|
from flask import url_for
|
||||||
|
|
||||||
# Need to import directly from config to allow modification from the tests
|
# Need to import directly from config to allow modification from the tests
|
||||||
from app import config
|
from app import config
|
||||||
from app.db import Session
|
from app.db import Session
|
||||||
from app.email_utils import is_reverse_alias
|
from app.email_utils import is_reverse_alias
|
||||||
from app.models import User, ApiKey, Alias, Contact, EmailLog, Mailbox
|
from app.models import User, Alias, Contact, EmailLog, Mailbox
|
||||||
from tests.api.utils import get_new_user_and_api_key
|
from tests.api.utils import get_new_user_and_api_key
|
||||||
from tests.utils import login, random_domain
|
from tests.utils import login, random_domain
|
||||||
|
|
||||||
|
|
||||||
def test_get_aliases_error_without_pagination(flask_client):
|
def test_get_aliases_error_without_pagination(flask_client):
|
||||||
user = User.create(
|
user, api_key = get_new_user_and_api_key()
|
||||||
email="a@b.c",
|
|
||||||
password="password",
|
|
||||||
name="Test User",
|
|
||||||
activated=True,
|
|
||||||
commit=True,
|
|
||||||
)
|
|
||||||
|
|
||||||
# create api_key
|
|
||||||
api_key = ApiKey.create(user.id, "for test")
|
|
||||||
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}
|
||||||
|
@ -32,17 +22,7 @@ def test_get_aliases_error_without_pagination(flask_client):
|
||||||
|
|
||||||
|
|
||||||
def test_get_aliases_with_pagination(flask_client):
|
def test_get_aliases_with_pagination(flask_client):
|
||||||
user = User.create(
|
user, api_key = get_new_user_and_api_key()
|
||||||
email="a@b.c",
|
|
||||||
password="password",
|
|
||||||
name="Test User",
|
|
||||||
activated=True,
|
|
||||||
commit=True,
|
|
||||||
)
|
|
||||||
|
|
||||||
# create api_key
|
|
||||||
api_key = ApiKey.create(user.id, "for test")
|
|
||||||
Session.commit()
|
|
||||||
|
|
||||||
# create more aliases than config.PAGE_LIMIT
|
# create more aliases than config.PAGE_LIMIT
|
||||||
for _ in range(config.PAGE_LIMIT + 1):
|
for _ in range(config.PAGE_LIMIT + 1):
|
||||||
|
@ -79,14 +59,7 @@ def test_get_aliases_with_pagination(flask_client):
|
||||||
|
|
||||||
|
|
||||||
def test_get_aliases_query(flask_client):
|
def test_get_aliases_query(flask_client):
|
||||||
user = User.create(
|
user, api_key = get_new_user_and_api_key()
|
||||||
email="a@b.c", password="password", name="Test User", activated=True
|
|
||||||
)
|
|
||||||
Session.commit()
|
|
||||||
|
|
||||||
# create api_key
|
|
||||||
api_key = ApiKey.create(user.id, "for test")
|
|
||||||
Session.commit()
|
|
||||||
|
|
||||||
# create more aliases than config.PAGE_LIMIT
|
# create more aliases than config.PAGE_LIMIT
|
||||||
Alias.create_new(user, "prefix1")
|
Alias.create_new(user, "prefix1")
|
||||||
|
@ -491,14 +464,7 @@ def test_alias_contacts(flask_client):
|
||||||
|
|
||||||
|
|
||||||
def test_create_contact_route(flask_client):
|
def test_create_contact_route(flask_client):
|
||||||
user = User.create(
|
user, api_key = get_new_user_and_api_key()
|
||||||
email="a@b.c", password="password", name="Test User", activated=True
|
|
||||||
)
|
|
||||||
Session.commit()
|
|
||||||
|
|
||||||
# create api_key
|
|
||||||
api_key = ApiKey.create(user.id, "for test")
|
|
||||||
Session.commit()
|
|
||||||
|
|
||||||
alias = Alias.create_new_random(user)
|
alias = Alias.create_new_random(user)
|
||||||
Session.commit()
|
Session.commit()
|
||||||
|
|
|
@ -27,6 +27,7 @@ def test_user_in_trial(flask_client):
|
||||||
|
|
||||||
|
|
||||||
def test_user_linked_to_proton(flask_client):
|
def test_user_linked_to_proton(flask_client):
|
||||||
|
config.CONNECT_WITH_PROTON = True
|
||||||
user, api_key = get_new_user_and_api_key()
|
user, api_key = get_new_user_and_api_key()
|
||||||
partner = get_proton_partner()
|
partner = get_proton_partner()
|
||||||
partner_email = random_email()
|
partner_email = random_email()
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import random
|
||||||
from email.message import Message
|
from email.message import Message
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
@ -36,7 +37,7 @@ def prepare_complaint(
|
||||||
contact = Contact.create(
|
contact = Contact.create(
|
||||||
user_id=alias.user.id,
|
user_id=alias.user.id,
|
||||||
alias_id=alias.id,
|
alias_id=alias.id,
|
||||||
website_email="a@b.c",
|
website_email=f"contact{random.random()}@mailbox.test",
|
||||||
reply_email="d@e.f",
|
reply_email="d@e.f",
|
||||||
commit=True,
|
commit=True,
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue