diff --git a/pyproject.toml b/pyproject.toml index 5d0bf09..b3b7b9d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,6 +2,11 @@ add-bounds = "major" exclude-newer = "P2W" +[tool.ruff] +exclude = [ + ".alembic" +] + [project] name = "cloud-api" version = "0.1.0" diff --git a/src/iam/router.py b/src/iam/router.py index ce0074e..016cebc 100644 --- a/src/iam/router.py +++ b/src/iam/router.py @@ -39,7 +39,7 @@ from src.iam.schemas import IAMGetGroupPermissionsResponse, IAMGetGroupUsersResp GroupSchema, IAMPostGroupResponse, IAMPutGroupPermissionRequest, IAMPutGroupPermissionResponse, \ IAMPutGroupUserRequest, IAMPutGroupUserResponse, IAMDeleteGroupPermissionRequest, IAMDeleteGroupPermissionResponse, \ IAMDeleteGroupUserRequest, IAMDeleteGroupUserResponse, IAMGetPermissionsResponse, IAMPostPermissionRequest, \ - IAMPostPermissionResponse, PermissionSchema, IAMDeletePermissionRequest, IAMGetPermissionsSearchRequest, IAMGetPermissionsSearchResponse + IAMPostPermissionResponse, IAMDeletePermissionRequest, IAMGetPermissionsSearchRequest, IAMGetPermissionsSearchResponse router = APIRouter( tags=["IAM"], @@ -195,7 +195,7 @@ async def delete_permission(db: db_dependency, su: super_admin_dependency, perm_ @router.post("/permissions/search", response_model=IAMGetPermissionsSearchResponse) -async def get_permissions(db: db_dependency, org_model: org_model_root_claim_body_dependency, request_model: IAMGetPermissionsSearchRequest): +async def post_permissions(db: db_dependency, org_model: org_model_root_claim_body_dependency, request_model: IAMGetPermissionsSearchRequest): permission_query = db.query(Perm) if request_model.service_id is not None: diff --git a/src/iam/service.py b/src/iam/service.py index d887bfd..c6a1030 100644 --- a/src/iam/service.py +++ b/src/iam/service.py @@ -11,7 +11,7 @@ from src.database import db_dependency from src.schemas import ResourceName from src.auth.exceptions import UnauthorizedException -from fastapi import HTTPException, status, Request, Depends +from fastapi import Request, Depends def valid_service_key(db: db_dependency, request: Request, rn: ResourceName) -> bool: diff --git a/src/organisation/router.py b/src/organisation/router.py index 8e8bd36..f4c2e34 100644 --- a/src/organisation/router.py +++ b/src/organisation/router.py @@ -22,7 +22,6 @@ from fastapi.params import Query from psycopg.errors import UniqueViolation from sqlalchemy.exc import IntegrityError -from src.auth.exceptions import UnauthorizedException from src.contact.schemas import ContactModel from src.exceptions import UnprocessableContentException, ConflictException from src.contact.models import Contact diff --git a/test/test_auth_approval.py b/test/test_auth_approval.py index d3df353..f395865 100644 --- a/test/test_auth_approval.py +++ b/test/test_auth_approval.py @@ -6,8 +6,6 @@ Delete endpoints are currently skipped because the testing system cannot use bod import pytest from httpx import AsyncClient -from .conftest import default_client - from src.organisation.models import Organisation as Org, OrgUsers from src.user.models import User from src.iam.models import Group @@ -83,7 +81,7 @@ async def test_get_org_groups_auth_approval(default_client: AsyncClient): @pytest.mark.anyio async def test_get_org_contact_auth_approval(default_client: AsyncClient): - resp = await default_client.get(f"/org/contact?org_id=1&contact_type=billing") + resp = await default_client.get("/org/contact?org_id=1&contact_type=billing") assert resp.status_code != 422 assert resp.status_code == 200 diff --git a/test/test_auth_general.py b/test/test_auth_general.py index 533307b..6aeba96 100644 --- a/test/test_auth_general.py +++ b/test/test_auth_general.py @@ -3,11 +3,8 @@ import pytest from httpx import AsyncClient -from .conftest import no_su_client - from src.organisation.models import Organisation as Org from src.user.models import User -from src.iam.models import Group @pytest.mark.anyio diff --git a/test/test_auth_root.py b/test/test_auth_root.py index ea7abd9..16e3afa 100644 --- a/test/test_auth_root.py +++ b/test/test_auth_root.py @@ -5,8 +5,6 @@ DELETE endpoints are not tested import pytest from httpx import AsyncClient -from .conftest import no_su_client - from src.organisation.models import Organisation as Org from src.user.models import User from src.iam.models import Group @@ -70,7 +68,7 @@ async def test_get_org_groups_auth_root(no_su_client: AsyncClient): @pytest.mark.anyio async def test_get_org_contact_auth_root(no_su_client: AsyncClient): - resp = await no_su_client.get(f"/org/contact?org_id=2&contact_type=billing") + resp = await no_su_client.get("/org/contact?org_id=2&contact_type=billing") assert resp.status_code != 422 assert resp.status_code == 401 assert "Must be the org's root user" in resp.json()["detail"] diff --git a/test/test_auth_user.py b/test/test_auth_user.py index c219dcb..6f1c655 100644 --- a/test/test_auth_user.py +++ b/test/test_auth_user.py @@ -4,8 +4,6 @@ This testing module removes the testing user override to verify that endpoints w import pytest from httpx import AsyncClient -from .conftest import no_user_client - @pytest.mark.anyio async def test_get_self_db_auth_user(no_user_client: AsyncClient): diff --git a/test/test_healthcheck.py b/test/test_healthcheck.py index 4435a18..6fdb9be 100644 --- a/test/test_healthcheck.py +++ b/test/test_healthcheck.py @@ -1,7 +1,6 @@ import pytest from httpx import AsyncClient -from .conftest import default_client @pytest.mark.anyio async def test_healthcheck(default_client: AsyncClient): diff --git a/test/test_iam.py b/test/test_iam.py index 70fbf6d..24a6478 100644 --- a/test/test_iam.py +++ b/test/test_iam.py @@ -7,7 +7,7 @@ from src.user.models import User from src.organisation.models import Organisation as Org from src.iam.models import Group -from .conftest import default_client, db_session, generate_query_and_status +from .conftest import generate_query_and_status @pytest.mark.anyio @@ -25,7 +25,7 @@ async def test_post_act_on_resource_endpoint_success(default_client: AsyncClient data = resp.json() assert resp.status_code == 200 - assert data == True + assert data is True @pytest.mark.parametrize( @@ -133,7 +133,7 @@ async def test_get_group_permissions_success(default_client: AsyncClient): assert resp.status_code == 200 assert "permissions" in data - assert type(data["permissions"]) == list + assert isinstance(data["permissions"], list) assert data["permissions"][0]["service_name"] == "Test Service" assert data["permissions"][0]["resource"] == "test_resource" assert data["permissions"][0]["action"] == "read" @@ -175,7 +175,7 @@ async def test_get_group_users_success(default_client: AsyncClient): assert resp.status_code == 200 assert "users" in data - assert type(data["users"]) == list + assert isinstance(data["users"], list) assert data["users"][0]["id"] == 1 assert data["users"][0]["first_name"] == "Admin" assert data["users"][0]["last_name"] == "Test" @@ -218,7 +218,7 @@ async def test_post_group_success(default_client: AsyncClient): assert resp.status_code == 200 assert "group" in data - assert type(data["group"]) == dict + assert isinstance(data["group"], dict) assert data["group"]["name"] == "New Group" assert data["group"]["id"] == 2 @@ -255,12 +255,12 @@ async def test_put_group_perm_success(default_client: AsyncClient, db_session): assert resp.status_code == 200 assert "group" in data - assert type(data["group"]) == dict + assert isinstance(data["group"], dict) assert data["group"]["name"] == "Test Group Two" assert data["group"]["id"] == 2 assert "permissions" in data - assert type(data["permissions"]) == list + assert isinstance(data["permissions"], list) assert data["permissions"][0]["service_name"] == "Test Service" assert data["permissions"][0]["resource"] == "test_resource" assert data["permissions"][0]["action"] == "read" @@ -316,7 +316,7 @@ async def test_put_group_perm_mismatch(default_client: AsyncClient, db_session, db_session.add(Org(name="Another Test Org", root_user_id=1, billing_contact_id=1, owner_contact_id=2, security_contact_id=3, status="approved")) db_session.add(Group(name="Another Test Group", org_id=2)) db_session.flush() - resp = await default_client.put(f"/iam/group/permission", json=body) + resp = await default_client.put("/iam/group/permission", json=body) assert resp.status_code == 401 assert resp.json()["detail"] == "Group does not belong to this organization" @@ -332,12 +332,12 @@ async def test_put_group_user_success(default_client: AsyncClient, db_session): assert resp.status_code == 200 assert "group" in data - assert type(data["group"]) == dict + assert isinstance(data["group"], dict) assert data["group"]["name"] == "Test Group" assert data["group"]["id"] == 1 assert "users" in data - assert type(data["users"]) == list + assert isinstance(data["users"], list) assert data["users"][1]["id"] == 2 assert data["users"][1]["first_name"] == "User" assert data["users"][1]["last_name"] == "Test" @@ -387,7 +387,7 @@ async def test_get_permissions_success(default_client: AsyncClient): assert resp.status_code == 200 assert "permissions" in data - assert type(data["permissions"]) == list + assert isinstance(data["permissions"], list) assert data["permissions"][0]["service_name"] == "Test Service" assert data["permissions"][0]["resource"] == "test_resource" assert data["permissions"][0]["action"] == "read" @@ -470,7 +470,7 @@ async def test_post_perm_search_success(default_client: AsyncClient, db_session, assert resp.status_code == 200 assert "permissions" in data - assert type(data["permissions"]) == list + assert isinstance(data["permissions"], list) assert data["permissions"][0]["service_name"] == "Test Service" assert data["permissions"][0]["resource"] == "test_resource" assert data["permissions"][0]["action"] == "read" diff --git a/test/test_organisation.py b/test/test_organisation.py index 8e697e7..4b60aa7 100644 --- a/test/test_organisation.py +++ b/test/test_organisation.py @@ -6,7 +6,7 @@ from httpx import AsyncClient from src.organisation.models import Organisation, OrgUsers from src.user.models import User -from .conftest import default_client, generate_query_and_status +from .conftest import generate_query_and_status @pytest.mark.anyio @@ -151,7 +151,7 @@ async def test_get_org_users_success(default_client: AsyncClient): assert resp.status_code == 200 assert "users" in data - assert type(data["users"]) == list + assert isinstance(data["users"], list) assert len(data["users"]) == 1 assert data["users"][0] == "admin@test.com" @@ -181,7 +181,7 @@ async def test_post_org_user_success(default_client: AsyncClient, db_session): assert resp.status_code == 200 assert "users" in data - assert type(data["users"]) == list + assert isinstance(data["users"], list) assert "user@test.org" in data["users"] @@ -264,7 +264,7 @@ async def test_get_org_groups_success(default_client: AsyncClient): assert resp.status_code == 200 assert "groups" in data - assert type(data["groups"]) == list + assert isinstance(data["groups"], list) assert "Test Group" in data["groups"] @@ -379,7 +379,7 @@ async def test_patch_org_contact_success(default_client: AsyncClient, key: str, ], ) @pytest.mark.anyio -async def test_patch_org_status_status_checks(default_client: AsyncClient, body: dict[str, str], expected_status: int): +async def test_patch_org_contact_status_checks(default_client: AsyncClient, body: dict[str, str], expected_status: int): resp = await default_client.patch("/org/contact", json=body) assert resp.status_code == expected_status diff --git a/test/test_service.py b/test/test_service.py index 5a1e7ad..c13eb80 100644 --- a/test/test_service.py +++ b/test/test_service.py @@ -4,7 +4,7 @@ import pytest from httpx import AsyncClient -from .conftest import default_client, generate_query_and_status +from .conftest import generate_query_and_status @pytest.mark.anyio @@ -38,7 +38,7 @@ async def test_post_service_success(default_client: AsyncClient): assert "service" in data assert data["service"]["name"] == "New Test Service" assert data["service"]["id"] == 2 - assert type(data["service"]["api_key"]) == str + assert isinstance(data["service"]["api_key"], str) @pytest.mark.parametrize( @@ -64,7 +64,7 @@ async def test_patch_service_success(default_client: AsyncClient): assert "service" in data assert data["service"]["name"] == "Test Service" assert data["service"]["id"] == 1 - assert type(data["service"]["api_key"]) == str + assert isinstance(data["service"]["api_key"], str) @pytest.mark.parametrize( diff --git a/test/test_user.py b/test/test_user.py index bdcd500..a50e654 100644 --- a/test/test_user.py +++ b/test/test_user.py @@ -6,7 +6,7 @@ import pytest from httpx import AsyncClient -from .conftest import default_client, generate_query_and_status +from .conftest import generate_query_and_status @pytest.mark.anyio async def test_get_self_db_success(default_client: AsyncClient):