📈(backend) capture an event when a document is imported

We want to capture an event when a file is imported. We add in the
properties the type of file imported and if it is in the
create-for-owner api call.
This commit is contained in:
Manuel Raynaud
2026-06-01 17:41:56 +02:00
parent d1476024a7
commit a05de21d14
7 changed files with 291 additions and 116 deletions
@@ -18,6 +18,7 @@ from rest_framework.test import APIClient
from core import factories, models
from core.services import mime_types
from core.utils.analytics import PosthogEventName
pytestmark = pytest.mark.django_db
@@ -283,13 +284,14 @@ def test_external_api_documents_create_with_markdown_file_success(
file = BytesIO(file_content)
file.name = "readme.md"
response = client.post(
"/external_api/v1.0/documents/",
{
"file": file,
},
format="multipart",
)
with patch("core.api.viewsets.posthog_capture") as mock_capture:
response = client.post(
"/external_api/v1.0/documents/",
{
"file": file,
},
format="multipart",
)
assert response.status_code == 201
@@ -307,6 +309,13 @@ def test_external_api_documents_create_with_markdown_file_success(
accept=mime_types.YJS,
)
# The successful conversion should be tracked in PostHog
mock_capture.assert_any_call(
PosthogEventName.DOC_IMPORTED,
user_specific_sub,
{"content_type": mime_types.MARKDOWN},
)
def test_external_api_documents_list_with_multiple_roles(
user_token, resource_server_backend, user_specific_sub