test_user_info.py 812 B

1234567891011121314151617181920212223242526272829303132
  1. from flask import url_for
  2. from app.extensions import db
  3. from app.models import User, ApiKey, AliasUsedOn, GenEmail
  4. def test_success(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 == {"is_premium": False, "name": "Test User"}
  17. def test_wrong_api_key(flask_client):
  18. r = flask_client.get(
  19. url_for("api.user_info"), headers={"Authentication": "Invalid code"}
  20. )
  21. assert r.status_code == 401
  22. assert r.json == {"error": "Wrong api key"}