2020-01-05 22:48:38 +01:00
|
|
|
from flask import url_for
|
|
|
|
|
|
|
|
from app.extensions import db
|
2020-03-17 11:51:40 +01:00
|
|
|
from app.models import User, ApiKey, AliasUsedOn, Alias
|
2020-01-05 22:48:38 +01:00
|
|
|
|
|
|
|
|
2020-01-30 07:20:32 +01:00
|
|
|
def test_user_in_trial(flask_client):
|
2020-01-05 22:48:38 +01:00
|
|
|
user = User.create(
|
|
|
|
email="a@b.c", password="password", name="Test User", activated=True
|
|
|
|
)
|
|
|
|
db.session.commit()
|
|
|
|
|
|
|
|
# create api_key
|
|
|
|
api_key = ApiKey.create(user.id, "for test")
|
|
|
|
db.session.commit()
|
|
|
|
|
|
|
|
r = flask_client.get(
|
|
|
|
url_for("api.user_info"), headers={"Authentication": api_key.code}
|
|
|
|
)
|
|
|
|
|
|
|
|
assert r.status_code == 200
|
2020-03-18 19:08:16 +01:00
|
|
|
assert r.json == {
|
|
|
|
"is_premium": True,
|
|
|
|
"name": "Test User",
|
|
|
|
"email": "a@b.c",
|
|
|
|
"in_trial": True,
|
|
|
|
}
|
2020-01-05 22:48:38 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_wrong_api_key(flask_client):
|
|
|
|
r = flask_client.get(
|
|
|
|
url_for("api.user_info"), headers={"Authentication": "Invalid code"}
|
|
|
|
)
|
|
|
|
|
|
|
|
assert r.status_code == 401
|
|
|
|
|
|
|
|
assert r.json == {"error": "Wrong api key"}
|