def test_api_user_change_email():
    """Test that users can change their email via the API"""
    app = create_ctfd()
    with app.app_context():
        register_user(app)
        user = Users.query.filter_by(id=2).first()
        app.db.session.commit()
        with login_as_user(app) as client:
            # Test users can't submit null
            r = client.patch(
                "/api/v1/users/me", json={"email": None, "confirm": "password"}
            )
            resp = r.get_json()
            print(resp)
            assert r.status_code == 400
            assert resp["errors"]["email"] == ["Field may not be null."]

            # Test users can exercise the API
            r = client.patch(
                "/api/v1/users/me",
                json={"email": "new_email@email.com", "confirm": "password"},
            )
            assert r.status_code == 200
            resp = r.get_json()
            assert resp["data"]["email"] == "new_email@email.com"
            assert resp["success"] is True
            user = Users.query.filter_by(id=2).first()
            assert user.email == "new_email@email.com"
    destroy_ctfd(app)
Test that users can change their email via the API
tests/api/v1/test_users.py