Fix admin API gaps for users, exchange checks, and parser logs
This commit is contained in:
@@ -18,6 +18,7 @@ class ExchangeViewsTest(APITestCase):
|
||||
self.user = UserFactory.create_user()
|
||||
self.admin = UserFactory.create_superuser()
|
||||
self.connections_url = reverse("api_v1:exchange:connections")
|
||||
self.test_connection_url = reverse("api_v1:exchange:connections-test")
|
||||
self.copy_url = reverse("api_v1:exchange:copy")
|
||||
|
||||
def test_connections_endpoint_admin_only(self):
|
||||
@@ -65,6 +66,47 @@ class ExchangeViewsTest(APITestCase):
|
||||
connection_mock.assert_called_once()
|
||||
validate_mock.assert_called_once()
|
||||
|
||||
@patch("apps.exchange.services.ExchangeConnectionService.test_connection_payload")
|
||||
def test_test_connection_success(self, test_connection_mock):
|
||||
payload = {
|
||||
"server": "127.0.0.1",
|
||||
"port": 5432,
|
||||
"username": "postgres",
|
||||
"password": "secret",
|
||||
"database_name": "target_db",
|
||||
"schema_name": "public",
|
||||
}
|
||||
test_connection_mock.return_value = {
|
||||
"status": "success",
|
||||
"message": "ok",
|
||||
}
|
||||
|
||||
self.client.force_authenticate(self.admin)
|
||||
response = self.client.post(self.test_connection_url, payload, format="json")
|
||||
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
self.assertEqual(response.data["data"]["status"], "success")
|
||||
self.assertEqual(ExchangeConnection.objects.count(), 0)
|
||||
test_connection_mock.assert_called_once_with(**payload)
|
||||
|
||||
@patch("apps.exchange.services.ExchangeConnectionService.test_connection_payload")
|
||||
def test_test_connection_failure_returns_400(self, test_connection_mock):
|
||||
payload = {
|
||||
"server": "127.0.0.1",
|
||||
"port": 5432,
|
||||
"username": "postgres",
|
||||
"password": "secret",
|
||||
"database_name": "target_db",
|
||||
"schema_name": "public",
|
||||
}
|
||||
test_connection_mock.side_effect = ExchangeServiceError("Connection refused")
|
||||
|
||||
self.client.force_authenticate(self.admin)
|
||||
response = self.client.post(self.test_connection_url, payload, format="json")
|
||||
|
||||
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
|
||||
self.assertEqual(ExchangeConnection.objects.count(), 0)
|
||||
|
||||
@patch("apps.exchange.services.ExchangeConnectionService.test_connection")
|
||||
def test_create_connection_fail_rolls_back_active(self, connection_mock):
|
||||
connection_mock.side_effect = ExchangeServiceError("Connection refused")
|
||||
|
||||
Reference in New Issue
Block a user