fix(lint): resolve ruff errors in tests and run_tests.py
- Fix import sorting (I001) - Remove unused imports and variables (F401, F841) - Add noqa for test code (S106 hardcoded passwords, S314 XML parsing) - Auto-format with ruff format
This commit is contained in:
@@ -187,7 +187,7 @@ class BackgroundJobServiceTest(TestCase):
|
||||
def test_get_user_jobs_with_status_filter(self):
|
||||
"""Тест фильтрации по статусу."""
|
||||
user_id = 456
|
||||
job1 = BackgroundJobService.create_job(
|
||||
BackgroundJobService.create_job(
|
||||
task_id="task-pending",
|
||||
task_name="test.task",
|
||||
user_id=user_id,
|
||||
@@ -212,7 +212,7 @@ class BackgroundJobServiceTest(TestCase):
|
||||
def test_get_active_jobs(self):
|
||||
"""Тест получения активных задач."""
|
||||
# Создаём задачи с разными статусами
|
||||
job_pending = BackgroundJobService.create_job(
|
||||
BackgroundJobService.create_job(
|
||||
task_id="job-active-pending",
|
||||
task_name="test.task",
|
||||
)
|
||||
|
||||
@@ -71,6 +71,7 @@ class BulkOperationsIntegrationTest(TestCase):
|
||||
|
||||
def test_bulk_create_chunked(self):
|
||||
"""Тест массового создания чанками."""
|
||||
|
||||
# Создаём тестовый сервис с BulkOperationsMixin
|
||||
class TestService(BulkOperationsMixin):
|
||||
model = BackgroundJob
|
||||
@@ -88,10 +89,13 @@ class BulkOperationsIntegrationTest(TestCase):
|
||||
self.assertEqual(count, 10)
|
||||
|
||||
# Проверяем что все созданы
|
||||
self.assertEqual(BackgroundJob.objects.filter(task_name="test.bulk.task").count(), 10)
|
||||
self.assertEqual(
|
||||
BackgroundJob.objects.filter(task_name="test.bulk.task").count(), 10
|
||||
)
|
||||
|
||||
def test_bulk_delete(self):
|
||||
"""Тест массового удаления."""
|
||||
|
||||
class TestService(BulkOperationsMixin):
|
||||
model = BackgroundJob
|
||||
|
||||
@@ -109,10 +113,13 @@ class BulkOperationsIntegrationTest(TestCase):
|
||||
deleted = TestService.bulk_delete(ids_to_delete)
|
||||
|
||||
self.assertEqual(deleted, 3)
|
||||
self.assertEqual(BackgroundJob.objects.filter(task_name="test.delete.task").count(), 2)
|
||||
self.assertEqual(
|
||||
BackgroundJob.objects.filter(task_name="test.delete.task").count(), 2
|
||||
)
|
||||
|
||||
def test_bulk_update_fields(self):
|
||||
"""Тест массового обновления полей."""
|
||||
|
||||
class TestService(BulkOperationsMixin):
|
||||
model = BackgroundJob
|
||||
|
||||
@@ -138,6 +145,7 @@ class BulkOperationsIntegrationTest(TestCase):
|
||||
|
||||
def test_bulk_update_or_create_creates(self):
|
||||
"""Тест upsert - создание новых."""
|
||||
|
||||
class TestService(BulkOperationsMixin):
|
||||
model = BackgroundJob
|
||||
|
||||
@@ -157,6 +165,7 @@ class BulkOperationsIntegrationTest(TestCase):
|
||||
|
||||
def test_bulk_update_or_create_updates(self):
|
||||
"""Тест upsert - обновление существующих."""
|
||||
|
||||
class TestService(BulkOperationsMixin):
|
||||
model = BackgroundJob
|
||||
|
||||
|
||||
@@ -101,9 +101,7 @@ class APIPaginatedResponseTest(TestCase):
|
||||
def test_paginated_response(self):
|
||||
"""Test paginated response with correct metadata"""
|
||||
data = [{"id": 1}, {"id": 2}]
|
||||
response = api_paginated_response(
|
||||
data, page=1, page_size=10, total_count=25
|
||||
)
|
||||
response = api_paginated_response(data, page=1, page_size=10, total_count=25)
|
||||
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
self.assertEqual(response.data["data"], data)
|
||||
|
||||
@@ -21,7 +21,7 @@ class BaseServiceTest(TestCase):
|
||||
self.user = User.objects.create_user(
|
||||
username="testuser",
|
||||
email="test@example.com",
|
||||
password="testpass123",
|
||||
password="testpass123", # noqa: S106
|
||||
)
|
||||
|
||||
def test_get_by_id_success(self):
|
||||
@@ -53,7 +53,7 @@ class BaseServiceTest(TestCase):
|
||||
User.objects.create_user(
|
||||
username="testuser2",
|
||||
email="test2@example.com",
|
||||
password="testpass123",
|
||||
password="testpass123", # noqa: S106
|
||||
)
|
||||
|
||||
result = UserTestService.get_all()
|
||||
|
||||
@@ -88,7 +88,7 @@ class SignalDispatcherTest(TestCase):
|
||||
self.dispatcher.connect_all()
|
||||
|
||||
# Create user to trigger signal
|
||||
user = UserFactory.create_user()
|
||||
UserFactory.create_user()
|
||||
|
||||
self.assertTrue(handler_called["value"])
|
||||
|
||||
@@ -114,7 +114,7 @@ class SignalDispatcherTest(TestCase):
|
||||
|
||||
# Create user - handler should not be called
|
||||
handler_called["value"] = False
|
||||
user = UserFactory.create_user()
|
||||
UserFactory.create_user()
|
||||
|
||||
self.assertFalse(handler_called["value"])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user