fix error in gitignore

This commit is contained in:
2026-09-24 12:32:59 +03:30
commit 86c117ee2a
165 changed files with 5963 additions and 0 deletions
+56
View File
@@ -0,0 +1,56 @@
from django.contrib.auth import get_user_model
from rest_framework.test import APITestCase
from apps.rbac.models import Permission, Role
User = get_user_model()
class UserManagementApiTests(APITestCase):
def setUp(self):
self.admin = User.objects.create_superuser(username="root", password="***")
self.client.force_authenticate(self.admin)
self.role = Role.objects.create(name="Operator", slug="operator-t")
self.role.permissions.add(Permission.objects.create(code="processing.start"))
def test_create_user_with_role_ids(self):
response = self.client.post(
"/api/v1/users/",
{
"username": "newuser",
"email": "new@example.com",
"phone": "09120000000",
"password": "secret123",
"role_ids": [str(self.role.id)],
"is_active": True,
},
format="json",
)
self.assertEqual(response.status_code, 201, response.content)
user = User.objects.get(username="newuser")
self.assertTrue(user.check_password("secret123"))
self.assertTrue(user.user_roles.filter(role=self.role).exists())
def test_update_user_role_ids(self):
user = User.objects.create_user(username="someone", password="***")
response = self.client.patch(
f"/api/v1/users/{user.id}/", {"role_ids": [str(self.role.id)]}, format="json"
)
self.assertEqual(response.status_code, 200, response.content)
self.assertTrue(user.user_roles.filter(role=self.role).exists())
def test_ban_and_unban(self):
user = User.objects.create_user(username="toban", password="***")
response = self.client.patch(f"/api/v1/users/{user.id}/", {"is_active": False}, format="json")
self.assertEqual(response.status_code, 200, response.content)
user.refresh_from_db()
self.assertFalse(user.is_active)
def test_reset_password(self):
user = User.objects.create_user(username="pwuser", password="***")
response = self.client.post(
f"/api/v1/users/{user.id}/set-password/", {"new_password": "brandnew1"}, format="json"
)
self.assertEqual(response.status_code, 200, response.content)
user.refresh_from_db()
self.assertTrue(user.check_password("brandnew1"))