Skip to content

Commit

Permalink
fix: Also accept lowercase levels
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasfarias committed Nov 15, 2023
1 parent c5dd8b9 commit 0ef6511
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 5 deletions.
8 changes: 4 additions & 4 deletions posthog/api/test/batch_exports/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ def patch_batch_export(client, team_id, batch_export_id, new_batch_export_data):
)


def get_batch_export_log_entries(client: TestClient, team_id: int, batch_export_id: str):
return client.get(f"/api/projects/{team_id}/batch_exports/{batch_export_id}/logs")
def get_batch_export_log_entries(client: TestClient, team_id: int, batch_export_id: str, **extra):
return client.get(f"/api/projects/{team_id}/batch_exports/{batch_export_id}/logs", extra)


def get_batch_export_run_log_entries(client: TestClient, team_id: int, batch_export_id: str, run_id):
return client.get(f"/api/projects/{team_id}/batch_exports/{batch_export_id}/runs/{run_id}/logs")
def get_batch_export_run_log_entries(client: TestClient, team_id: int, batch_export_id: str, run_id, **extra):
return client.get(f"/api/projects/{team_id}/batch_exports/{batch_export_id}/runs/{run_id}/logs", extra)
40 changes: 40 additions & 0 deletions posthog/api/test/batch_exports/test_log_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,3 +248,43 @@ def test_batch_export_run_log_api(client, batch_export, team):
assert results[0]["message"] == "Test log. Much INFO."
assert results[0]["level"] == BatchExportLogEntryLevel.INFO
assert results[0]["batch_export_id"] == str(batch_export["id"])


@pytest.mark.django_db
def test_batch_export_run_log_api_with_level_filter(client, batch_export, team):
"""Test fetching batch export run log entries using the API."""
run_id = str(uuid.uuid4())

create_batch_export_log_entry(
team_id=team.pk,
batch_export_id=str(batch_export["id"]),
run_id=run_id,
message="Test log. Much INFO.",
level=BatchExportLogEntryLevel.INFO,
)

create_batch_export_log_entry(
team_id=team.pk,
batch_export_id=str(batch_export["id"]),
run_id=run_id,
message="Test log. Much DEBUG.",
level=BatchExportLogEntryLevel.DEBUG,
)

response = get_batch_export_run_log_entries(
client,
team_id=team.pk,
batch_export_id=batch_export["id"],
run_id=run_id,
level_filter="info",
)

json_response = response.json()
results = json_response["results"]

assert response.status_code == 200
assert json_response["count"] == 1
assert len(results) == 1
assert results[0]["message"] == "Test log. Much INFO."
assert results[0]["level"] == BatchExportLogEntryLevel.INFO
assert results[0]["batch_export_id"] == str(batch_export["id"])
2 changes: 1 addition & 1 deletion posthog/batch_exports/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ def get_queryset(self):
if before_raw is not None:
before = dt.datetime.fromisoformat(before_raw.replace("Z", "+00:00"))

level_filter = [BatchExportLogEntryLevel[t] for t in (self.request.GET.getlist("level_filter", []))]
level_filter = [BatchExportLogEntryLevel[t.upper()] for t in (self.request.GET.getlist("level_filter", []))]
return fetch_batch_export_log_entries(
team_id=self.parents_query_dict["team_id"],
batch_export_id=self.parents_query_dict["batch_export_id"],
Expand Down

0 comments on commit 0ef6511

Please sign in to comment.