forked from getsentry/sentry
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(metrics_extraction): Share create_widget usage (getsentry#65247)
- Loading branch information
Showing
3 changed files
with
66 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
from collections.abc import Sequence | ||
|
||
from sentry.models.dashboard import Dashboard | ||
from sentry.models.dashboard_widget import ( | ||
DashboardWidget, | ||
DashboardWidgetDisplayTypes, | ||
DashboardWidgetQuery, | ||
DashboardWidgetTypes, | ||
) | ||
from sentry.models.project import Project | ||
|
||
|
||
def create_widget( | ||
aggregates: Sequence[str], | ||
query: str, | ||
project: Project, | ||
title: str = "Dashboard", | ||
id: int | None = None, | ||
columns: Sequence[str] | None = None, | ||
dashboard: Dashboard | None = None, | ||
widget: DashboardWidget | None = None, | ||
) -> tuple[DashboardWidgetQuery, DashboardWidget, Dashboard]: | ||
columns = columns or [] | ||
dashboard = dashboard or Dashboard.objects.create( | ||
organization=project.organization, | ||
created_by_id=1, | ||
title=title, | ||
) | ||
order = (id or 1) - 1 | ||
widget = widget or DashboardWidget.objects.create( | ||
dashboard=dashboard, | ||
order=order, | ||
widget_type=DashboardWidgetTypes.DISCOVER, | ||
display_type=DashboardWidgetDisplayTypes.LINE_CHART, | ||
) | ||
|
||
if id: | ||
widget_query = DashboardWidgetQuery.objects.create( | ||
id=id, | ||
aggregates=aggregates, | ||
conditions=query, | ||
columns=columns, | ||
order=order, | ||
widget=widget, | ||
) | ||
else: | ||
widget_query = DashboardWidgetQuery.objects.create( | ||
aggregates=aggregates, | ||
conditions=query, | ||
columns=columns, | ||
order=order, | ||
widget=widget, | ||
) | ||
|
||
return widget_query, widget, dashboard |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters