|
| 1 | +# Copyright (c) 2021, VRAI Labs and/or its affiliates. All rights reserved. |
| 2 | +# |
| 3 | +# This software is licensed under the Apache License, Version 2.0 (the |
| 4 | +# "License") as published by the Apache Software Foundation. |
| 5 | +# |
| 6 | +# You may not use this file except in compliance with the License. You may |
| 7 | +# obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 11 | +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 12 | +# License for the specific language governing permissions and limitations |
| 13 | +# under the License. |
| 14 | +from fastapi import FastAPI |
| 15 | +import json |
| 16 | +from fastapi.testclient import TestClient |
| 17 | +from pytest import fixture, mark |
| 18 | +from supertokens_python import init |
| 19 | +from supertokens_python.framework.fastapi import get_middleware |
| 20 | +from supertokens_python.recipe import emailpassword, session |
| 21 | +from tests.utils import ( |
| 22 | + get_st_init_args, |
| 23 | + setup_function, |
| 24 | + start_st, |
| 25 | + teardown_function, |
| 26 | + sign_up_request, |
| 27 | +) |
| 28 | + |
| 29 | +_ = setup_function # type: ignore |
| 30 | +_ = teardown_function # type: ignore |
| 31 | + |
| 32 | +pytestmark = mark.asyncio |
| 33 | + |
| 34 | + |
| 35 | +@fixture(scope="function") |
| 36 | +async def app(): |
| 37 | + app = FastAPI() |
| 38 | + app.add_middleware(get_middleware()) |
| 39 | + |
| 40 | + return TestClient(app) |
| 41 | + |
| 42 | + |
| 43 | +async def test_field_error_on_existing_email_signup(app: TestClient): |
| 44 | + init_args = get_st_init_args([emailpassword.init(), session.init()]) |
| 45 | + init(**init_args) |
| 46 | + start_st() |
| 47 | + |
| 48 | + response = json. loads( sign_up_request( app, "[email protected]", "validpass123"). text) |
| 49 | + assert response["status"] == "OK" |
| 50 | + |
| 51 | + response = json. loads( sign_up_request( app, "[email protected]", "validpass123"). text) |
| 52 | + assert response == { |
| 53 | + "status": "FIELD_ERROR", |
| 54 | + "formFields": [ |
| 55 | + { |
| 56 | + "id": "email", |
| 57 | + "error": "This email already exists. Please sign in instead.", |
| 58 | + } |
| 59 | + ], |
| 60 | + } |
0 commit comments