chore(): switched all fields in contract to snake_case and linting improvements

This commit is contained in:
ITQ
2026-02-12 22:17:55 +03:00
parent 102f425259
commit 362398d56b
32 changed files with 401 additions and 353 deletions
+1 -1
View File
@@ -38,7 +38,7 @@ router = Router(tags=["users"])
def list_users(
request: HttpRequest,
role: str | None = None,
is_active: bool | None = None,
is_active: bool | None = None, # noqa: FBT001
search: str | None = None,
limit: int = 50,
offset: int = 0,
+1 -7
View File
@@ -7,8 +7,7 @@ from apps.users.models import User
class UserOut(ModelSchema):
first_name: str = Field("", alias="firstName")
last_name: str = Field("", alias="lastName")
is_active: bool
class Meta:
@@ -52,13 +51,11 @@ class UserCreateIn(Schema):
)
first_name: str = Field(
"",
alias="firstName",
max_length=150,
description="First name.",
)
last_name: str = Field(
"",
alias="lastName",
max_length=150,
description="Last name.",
)
@@ -91,19 +88,16 @@ class UserUpdateIn(Schema):
)
first_name: str | None = Field(
None,
alias="firstName",
max_length=150,
description="New first name.",
)
last_name: str | None = Field(
None,
alias="lastName",
max_length=150,
description="New last name.",
)
is_active: bool | None = Field(
None,
alias="isActive",
description="Set active/inactive status.",
)
+8 -5
View File
@@ -1,23 +1,26 @@
from typing import override
from django.test import Client, TestCase
from apps.users.models import User, UserRole
from apps.users.tests._helpers import _auth_header, _make_user
from apps.users.tests.helpers import auth_header, make_user
class BaseUsersAPITest(TestCase):
@override
def setUp(self) -> None:
self.client = Client()
self.admin: User = _make_user(
self.admin: User = make_user(
username="mgmt_admin",
email="mgmt_admin@x.com",
password="adminpass1",
role=UserRole.ADMIN,
)
self.viewer: User = _make_user(
self.viewer: User = make_user(
username="mgmt_viewer",
email="mgmt_viewer@x.com",
password="viewerpass",
role=UserRole.VIEWER,
)
self.admin_auth: str = _auth_header(self.admin)
self.viewer_auth: str = _auth_header(self.viewer)
self.admin_auth: str = auth_header(self.admin)
self.viewer_auth: str = auth_header(self.viewer)
@@ -4,14 +4,14 @@ import uuid
from django.urls import reverse
from apps.users.models import User, UserRole
from apps.users.tests._helpers import _make_user
from apps.users.tests.helpers import make_user
from ._crud_base import BaseUsersAPITest
class UsersAPIDeleteAssignRoleTest(BaseUsersAPITest):
def test_delete_user_admin(self) -> None:
target: User = _make_user(
target: User = make_user(
username="to_delete",
email="del@lotty.local",
role=UserRole.VIEWER,
@@ -66,8 +66,8 @@ class UsersAPIListCreateTest(BaseUsersAPITest):
"email": "new@lotty.local",
"password": "newpass123",
"role": "experimenter",
"firstName": "New",
"lastName": "User",
"first_name": "New",
"last_name": "User",
}
),
content_type="application/json",
@@ -51,7 +51,7 @@ class UsersAPIReadUpdateTest(BaseUsersAPITest):
reverse(
"api-1:update_user", kwargs={"user_id": str(self.viewer.pk)}
),
data=json.dumps({"firstName": "Updated"}),
data=json.dumps({"first_name": "Updated"}),
content_type="application/json",
HTTP_AUTHORIZATION=self.admin_auth,
)
@@ -75,7 +75,7 @@ class UsersAPIReadUpdateTest(BaseUsersAPITest):
reverse(
"api-1:update_user", kwargs={"user_id": str(self.admin.pk)}
),
data=json.dumps({"firstName": "Hacked"}),
data=json.dumps({"first_name": "Hacked"}),
content_type="application/json",
HTTP_AUTHORIZATION=self.viewer_auth,
)
@@ -86,7 +86,7 @@ class UsersAPIReadUpdateTest(BaseUsersAPITest):
reverse(
"api-1:update_user", kwargs={"user_id": str(uuid.uuid4())}
),
data=json.dumps({"firstName": "Ghost"}),
data=json.dumps({"first_name": "Ghost"}),
content_type="application/json",
HTTP_AUTHORIZATION=self.admin_auth,
)
+6 -4
View File
@@ -1,13 +1,15 @@
import json
from typing import override
from django.test import Client, TestCase
from django.urls import reverse
from apps.users.models import User, UserRole
from apps.users.tests._helpers import _auth_header, _make_user
from apps.users.tests.helpers import auth_header, make_user
class RoleBasedAccessControlTest(TestCase):
@override
def setUp(self) -> None:
self.client = Client()
self.roles = {}
@@ -17,7 +19,7 @@ class RoleBasedAccessControlTest(TestCase):
UserRole.APPROVER,
UserRole.VIEWER,
]:
user: User = _make_user(
user: User = make_user(
username=f"rbac_{role_val}",
email=f"rbac_{role_val}@x.com",
password="password1",
@@ -25,7 +27,7 @@ class RoleBasedAccessControlTest(TestCase):
)
self.roles[role_val] = {
"user": user,
"auth": _auth_header(user),
"auth": auth_header(user),
}
def test_admin_can_list(self) -> None:
@@ -93,7 +95,7 @@ class RoleBasedAccessControlTest(TestCase):
target = self.roles[UserRole.VIEWER]["user"]
resp = self.client.patch(
reverse("api-1:update_user", kwargs={"user_id": str(target.pk)}),
data=json.dumps({"firstName": "Nope"}),
data=json.dumps({"first_name": "Nope"}),
content_type="application/json",
HTTP_AUTHORIZATION=self.roles[UserRole.EXPERIMENTER]["auth"],
)