test_user_info.py 869 B

12345678910111213141516171819202122232425262728293031323334353637
  1. from flask import url_for
  2. from app.extensions import db
  3. from app.models import User, ApiKey
  4. def test_user_in_trial(flask_client):
  5. user = User.create(
  6. email="a@b.c", password="password", name="Test User", activated=True
  7. )
  8. db.session.commit()
  9. # create api_key
  10. api_key = ApiKey.create(user.id, "for test")
  11. db.session.commit()
  12. r = flask_client.get(
  13. url_for("api.user_info"), headers={"Authentication": api_key.code}
  14. )
  15. assert r.status_code == 200
  16. assert r.json == {
  17. "is_premium": True,
  18. "name": "Test User",
  19. "email": "a@b.c",
  20. "in_trial": True,
  21. }
  22. def test_wrong_api_key(flask_client):
  23. r = flask_client.get(
  24. url_for("api.user_info"), headers={"Authentication": "Invalid code"}
  25. )
  26. assert r.status_code == 401
  27. assert r.json == {"error": "Wrong api key"}