-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathconftest.py
More file actions
42 lines (33 loc) · 1.32 KB
/
conftest.py
File metadata and controls
42 lines (33 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import pytest
from django.contrib.auth.models import Permission
from django_sql_dashboard.models import Dashboard
def pytest_collection_modifyitems(items):
"""Add django_db marker with databases to tests that need database access."""
for item in items:
fixturenames = getattr(item, "fixturenames", ())
# Tests using client fixtures or dashboard_db need both databases
if any(f in fixturenames for f in ("admin_client", "client", "dashboard_db")):
item.add_marker(pytest.mark.django_db(databases=["default", "dashboard"]))
@pytest.fixture
def dashboard_db(settings):
settings.DATABASES["dashboard"]["OPTIONS"] = {
"options": "-c default_transaction_read_only=on -c statement_timeout=100"
}
@pytest.fixture
def execute_sql_permission():
return Permission.objects.get(
content_type__app_label="django_sql_dashboard",
content_type__model="dashboard",
codename="execute_sql",
)
@pytest.fixture
def saved_dashboard(dashboard_db):
dashboard = Dashboard.objects.create(
slug="test",
title="Test dashboard",
description="This [supports markdown](http://example.com/)",
view_policy="public",
)
dashboard.queries.create(sql="select 11 + 33")
dashboard.queries.create(sql="select 22 + 55")
return dashboard