Add a name on every route #762 (#774)

* Names for urls added

* Tests for Login/Logout Names

* Register Name Test

* tests/test_router_reset.py

* Tests to verify url names in users router

* Test Verify Router Names

* oauth routes updated with prefix

* Test for authorize.  Didn't right test for callback as covered under other tests
This commit is contained in:
Brandon H. Goding
2021-11-02 03:12:43 -04:00
committed by GitHub
parent e0e8dfbc3b
commit 0c45cbc179
12 changed files with 137 additions and 11 deletions

View File

@@ -157,6 +157,16 @@ class TestLogin:
data = cast(Dict[str, Any], response.json())
assert data["detail"] == ErrorCode.LOGIN_BAD_CREDENTIALS
async def test_login_namespace(
self,
path,
app_factory
):
split_url = app_factory(True).url_path_for("auth:login").split("/")
assert split_url[len(split_url) - 1] in path
@pytest.mark.router
@pytest.mark.parametrize("path", ["/mock/logout", "/mock-bis/logout"])
@@ -199,3 +209,11 @@ class TestLogout:
path, headers={"Authorization": f"Bearer {verified_user.id}"}
)
assert response.status_code == status.HTTP_200_OK
async def test_logout_namespace(
self,
path,
app_factory
):
split_url = app_factory(True).url_path_for("auth:logout").split("/")
assert split_url[len(split_url) - 1] in path

View File

@@ -272,3 +272,31 @@ class TestCallback:
data = cast(Dict[str, Any], response.json())
assert data["token"] == str(user_oauth.id)
@pytest.mark.asyncio
async def test_oauth_authorize_namespace(
secret,
get_user_manager_oauth,
mock_authentication,
oauth_client,
get_test_client,
redirect_url: str = None,
):
mock_authentication_bis = MockAuthentication(name="mock-bis")
authenticator = Authenticator(
[mock_authentication, mock_authentication_bis], get_user_manager_oauth
)
app = FastAPI()
app.include_router(
get_oauth_router(
oauth_client,
get_user_manager_oauth,
authenticator,
secret,
redirect_url,
)
)
assert app.url_path_for("oauth:authorize") == "/authorize"

View File

@@ -102,3 +102,18 @@ class TestRegister:
data = cast(Dict[str, Any], response.json())
assert data["is_active"] is True
@pytest.mark.asyncio
async def test_register_namespace(
get_user_manager
):
app = FastAPI()
app.include_router(
get_register_router(
get_user_manager,
User,
UserCreate,
)
)
assert app.url_path_for("register:register") == "/register"

View File

@@ -148,3 +148,25 @@ class TestResetPassword:
json = {"token": "foo", "password": "guinevere"}
response = await test_app_client.post("/reset-password", json=json)
assert response.status_code == status.HTTP_200_OK
@pytest.mark.asyncio
async def test_forgot_password_namespace(
get_user_manager
):
app = FastAPI()
app.include_router(
get_reset_password_router(get_user_manager)
)
assert app.url_path_for("reset:forgot_password") == "/forgot-password"
@pytest.mark.asyncio
async def test_reset_password_namespace(
get_user_manager
):
app = FastAPI()
app.include_router(
get_reset_password_router(get_user_manager)
)
assert app.url_path_for("reset:reset_password") == "/reset-password"

View File

@@ -98,6 +98,12 @@ class TestMe:
assert data["id"] == str(verified_user.id)
assert data["email"] == verified_user.email
async def test_current_user_namespace(
self,
app_factory
):
assert app_factory(True).url_path_for("users:current_user") == "/me"
@pytest.mark.router
@pytest.mark.asyncio
@@ -465,6 +471,13 @@ class TestGetUser:
assert data["id"] == str(user.id)
assert "hashed_password" not in data
async def test_get_user_namespace(
self,
app_factory,
user: UserDB
):
assert app_factory(True).url_path_for("users:user", id=user.id) == f"/{user.id}"
@pytest.mark.router
@pytest.mark.asyncio

View File

@@ -104,6 +104,19 @@ class TestVerifyTokenRequest:
response = await test_app_client.post("/request-verify-token", json=json)
assert response.status_code == status.HTTP_202_ACCEPTED
async def test_token_namespace(
self,
get_user_manager,
):
verify_router = get_verify_router(
get_user_manager,
User,
)
app = FastAPI()
app.include_router(verify_router)
assert app.url_path_for("verify:request-token") == "/request-verify-token"
@pytest.mark.router
@pytest.mark.asyncio
@@ -166,3 +179,16 @@ class TestVerify:
assert response.status_code == status.HTTP_200_OK
data = cast(Dict[str, Any], response.json())
assert data["id"] == str(user.id)
async def test_verify_namespace(
self,
get_user_manager,
):
verify_router = get_verify_router(
get_user_manager,
User,
)
app = FastAPI()
app.include_router(verify_router)
assert app.url_path_for("verify:verify") == "/verify"