feat: migrate parser data to source records
Some checks failed
CI/CD Pipeline / Quality Gate (push) Failing after 14s
CI/CD Pipeline / Build and Push Images (push) Has been skipped
CI/CD Pipeline / Deploy Dev in Dokploy (push) Has been skipped
CI/CD Pipeline / Internal Notify (push) Successful in 0s

This commit is contained in:
2026-05-19 20:21:31 +02:00
parent 1c7c7238be
commit b8a18d6da4
46 changed files with 2689 additions and 6179 deletions

View File

@@ -134,10 +134,9 @@ class UserApiInventoryE2ETest(AuthenticatedApiMixin, APITestCase):
def setUp(self):
self.admin = UserFactory.create_superuser()
def test_auth_and_profile_endpoints(self):
def test_auth_endpoints_and_disabled_self_service_endpoints(self):
initial_password = fake.password(length=16, special_chars=False)
new_password = fake.password(length=18, special_chars=False)
register_payload = {
disabled_registration_payload = {
"email": fake.unique.email(),
"username": fake.unique.user_name(),
"password": initial_password,
@@ -147,19 +146,25 @@ class UserApiInventoryE2ETest(AuthenticatedApiMixin, APITestCase):
"middle_name": "Ivanovich",
"last_name": "Ivanov",
}
user = UserFactory.create_user(
username=fake.unique.user_name(),
password=initial_password,
)
register_response = self.client.post(
reverse("api_v1:user:register"),
register_payload,
disabled_registration_payload,
format="json",
)
self.assertEqual(register_response.status_code, status.HTTP_201_CREATED)
self.assertIn("tokens", register_response.data)
self.assertEqual(
register_response.status_code,
status.HTTP_405_METHOD_NOT_ALLOWED,
)
login_response = self.client.post(
reverse("api_v1:user:login"),
{
"username": register_payload["username"],
"username": user.username,
"password": initial_password,
},
format="json",
@@ -171,7 +176,10 @@ class UserApiInventoryE2ETest(AuthenticatedApiMixin, APITestCase):
{"token": login_response.data["access"]},
format="json",
)
self.assertEqual(verify_response.status_code, status.HTTP_200_OK)
self.assertEqual(
verify_response.status_code,
status.HTTP_405_METHOD_NOT_ALLOWED,
)
refresh_response = self.client.post(
reverse("api_v1:user:token_refresh"),
@@ -185,17 +193,23 @@ class UserApiInventoryE2ETest(AuthenticatedApiMixin, APITestCase):
me_response = self.client.get(reverse("api_v1:user:current_user"))
self.assertEqual(me_response.status_code, status.HTTP_200_OK)
self.assertEqual(me_response.data["username"], register_payload["username"])
self.assertEqual(me_response.data["username"], user.username)
me_update_response = self.client.patch(
reverse("api_v1:user:user_update"),
{"phone": f"+7{fake.numerify('##########')}"},
format="json",
)
self.assertEqual(me_update_response.status_code, status.HTTP_200_OK)
self.assertEqual(
me_update_response.status_code,
status.HTTP_405_METHOD_NOT_ALLOWED,
)
profile_response = self.client.get(reverse("api_v1:user:profile_detail"))
self.assertEqual(profile_response.status_code, status.HTTP_200_OK)
self.assertEqual(
profile_response.status_code,
status.HTTP_405_METHOD_NOT_ALLOWED,
)
profile_patch_response = self.client.patch(
reverse("api_v1:user:profile_detail"),
@@ -206,38 +220,31 @@ class UserApiInventoryE2ETest(AuthenticatedApiMixin, APITestCase):
},
format="json",
)
self.assertEqual(profile_patch_response.status_code, status.HTTP_200_OK)
self.assertEqual(
profile_patch_response.status_code,
status.HTTP_405_METHOD_NOT_ALLOWED,
)
profile_full_response = self.client.get(reverse("api_v1:user:profile_full"))
self.assertEqual(profile_full_response.status_code, status.HTTP_200_OK)
self.assertEqual(
profile_full_response.data["username"], register_payload["username"]
profile_full_response.status_code,
status.HTTP_405_METHOD_NOT_ALLOWED,
)
password_change_response = self.client.post(
reverse("api_v1:user:password_change"),
{
"old_password": initial_password,
"new_password": new_password,
"new_password_confirm": new_password,
"new_password": f"{initial_password}1",
"new_password_confirm": f"{initial_password}1",
},
format="json",
)
self.assertEqual(password_change_response.status_code, status.HTTP_200_OK)
relogin_response = self.client.post(
reverse("api_v1:user:login"),
{
"username": register_payload["username"],
"password": new_password,
},
format="json",
self.assertEqual(
password_change_response.status_code,
status.HTTP_405_METHOD_NOT_ALLOWED,
)
self.assertEqual(relogin_response.status_code, status.HTTP_200_OK)
self.client.credentials(
HTTP_AUTHORIZATION=f"Bearer {relogin_response.data['access']}"
)
logout_response = self.client.post(
reverse("api_v1:user:logout"),
{},
@@ -466,6 +473,11 @@ class ParsersApiInventoryE2ETest(AuthenticatedApiMixin, APITestCase):
self.assertEqual(sources_statuses.status_code, status.HTTP_200_OK)
self.assertEqual(source_detail.status_code, status.HTTP_200_OK)
main_dashboard = self.client.get(reverse("api_v1:stat:main-dashboard"))
self.assertEqual(main_dashboard.status_code, status.HTTP_200_OK)
self.assertIn("source_cards", main_dashboard.data["data"])
self.assertIn("organization_stats", main_dashboard.data["data"])
self.authenticate(self.admin)
parsing_url = reverse("api_v1:parsing:parsing-settings")
parsing_get = self.client.get(parsing_url)
@@ -600,12 +612,8 @@ class ExchangeApiInventoryE2ETest(AuthenticatedApiMixin, APITestCase):
@patch("apps.exchange.services.ExchangeConnectionService.prepare_target_structure")
@patch("apps.exchange.services.ExchangeConnectionService.test_connection")
@patch("apps.exchange.services.ExchangeConnectionService.test_connection_payload")
@patch("apps.exchange.views.copy_parsers_data_async")
@patch("apps.exchange.services.ExchangeConnectionService.get_active_connection")
def test_exchange_endpoints(
self,
get_active_connection_mock,
copy_task_mock,
test_connection_payload_mock,
_test_connection_mock,
_prepare_mock,
@@ -615,6 +623,7 @@ class ExchangeApiInventoryE2ETest(AuthenticatedApiMixin, APITestCase):
connections_url = reverse("api_v1:exchange:connections")
test_connection_url = reverse("api_v1:exchange:connections-test")
copy_url = reverse("api_v1:exchange:copy")
tables_url = reverse("api_v1:exchange:tables")
periodic_tasks_url = reverse("api_v1:exchange:periodic-tasks")
connection_payload = {
@@ -646,9 +655,8 @@ class ExchangeApiInventoryE2ETest(AuthenticatedApiMixin, APITestCase):
active_connection = ExchangeConnection.objects.get(
id=create_connection.data["id"]
)
get_active_connection_mock.return_value = active_connection
copy_task_mock.delay.return_value = SimpleNamespace(id="exchange-task-1")
copy_response = self.client.post(copy_url, {"mode": "all"}, format="json")
tables_response = self.client.get(tables_url)
list_periodic = self.client.get(periodic_tasks_url)
create_periodic = self.client.post(
@@ -682,10 +690,8 @@ class ExchangeApiInventoryE2ETest(AuthenticatedApiMixin, APITestCase):
list_connections,
create_connection,
connection_test,
copy_response,
list_periodic,
create_periodic,
detail_periodic,
patch_periodic,
):
self.assertIn(
@@ -693,10 +699,15 @@ class ExchangeApiInventoryE2ETest(AuthenticatedApiMixin, APITestCase):
{
status.HTTP_200_OK,
status.HTTP_201_CREATED,
status.HTTP_202_ACCEPTED,
},
)
self.assertEqual(copy_response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED)
self.assertEqual(tables_response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED)
self.assertEqual(
detail_periodic.status_code,
status.HTTP_405_METHOD_NOT_ALLOWED,
)
self.assertTrue(PeriodicTask.objects.filter(id=periodic_id).exists())
self.assertTrue(
ExchangeConnection.objects.filter(id=active_connection.id).exists()