Skip to content

Commit d8d0ef8

Browse files
Add stacktrace and fix tests using templates
1 parent 9bdcdd6 commit d8d0ef8

File tree

7 files changed

+49
-8
lines changed

7 files changed

+49
-8
lines changed

CHANGES

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
3.1.0
2+
* Add a stacktrace to the records to show where the searches were originated #13
3+
14
3.0.2
25
* Just CI auto deploy fixes
36

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ Django Elasticsearch Toolbar
22
============================
33

44
A Django Debug Toolbar panel for Elasticsearch
5-
[![Build Status](https://travis-ci.org/Benoss/django-elasticsearch-debug-toolbar.svg?branch=master)](https://travis-ci.org/Benoss/django-elasticsearch-debug-toolbar)
65
[![PyPI version](https://badge.fury.io/py/django-elasticsearch-debug-toolbar.svg)](https://badge.fury.io/py/django-elasticsearch-debug-toolbar)
76

87
About

elastic_panel/panel.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,19 @@
22
import json
33

44
from debug_toolbar.panels import Panel
5-
from debug_toolbar.utils import ThreadCollector, get_stack, tidy_stacktrace, render_stacktrace, \
6-
get_module_path, hidden_paths
5+
from debug_toolbar.utils import (
6+
ThreadCollector,
7+
get_module_path,
8+
get_stack,
9+
hidden_paths,
10+
render_stacktrace,
11+
tidy_stacktrace,
12+
)
713
from django.templatetags.static import static
814
from django.utils.translation import gettext_lazy as _
915
from elasticsearch.connection.base import Connection
1016

11-
# Patching og the orginal elasticsearch log_request
17+
# Patching og the original elasticsearch log_request
1218
old_log_request_success = Connection.log_request_success
1319
collector = ThreadCollector()
1420

pytest.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[pytest]
2+
env =
3+
DJANGO_SETTINGS_MODULE=tests.settings

tests/requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ django-debug-toolbar>=3.0
22
elasticsearch<8.0.0
33

44
pytest
5+
pytest-env
6+
57
isort
68
flake8
79
flake8-print # Forbid print statement in code use logging. instead

tests/settings.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import os
2+
3+
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
4+
5+
INSTALLED_APPS = ["debug_toolbar", "elastic_panel"]
6+
7+
DEBUG_TOOLBAR_PANELS = [
8+
"elastic_panel.panel.ElasticDebugPanel",
9+
]
10+
SECRET_KEY = "test"
11+
DEBUG = True
12+
13+
DATABASES = {
14+
"default": {
15+
"ENGINE": "django.db.backends.sqlite3",
16+
"NAME": ":memory:",
17+
},
18+
}
19+
20+
TEMPLATES = [
21+
{
22+
"BACKEND": "django.template.backends.django.DjangoTemplates",
23+
"DIRS": [BASE_DIR + "/tests/templates"],
24+
"APP_DIRS": True,
25+
},
26+
]

tests/test_toolbar.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
import unittest
22

3-
from django.conf import settings
3+
import django
4+
5+
django.setup()
46

5-
settings.configure()
67

78
from debug_toolbar.toolbar import DebugToolbar # noqa: E402
89
from django.http import HttpResponse # noqa: E402
910
from django.test import RequestFactory # noqa: E402
11+
from django.test import TestCase
1012
from elasticsearch.connection import Connection # noqa: E402
1113

1214
from elastic_panel import panel # noqa: E402
1315

1416

15-
class ImportTest(unittest.TestCase):
17+
class ImportTest(TestCase):
1618
def test_input(self):
1719
panel.ElasticQueryInfo("GET", "asdasd", "asdasd", "{}", 200, "adssad", 1)
1820
panel.ElasticQueryInfo("GET", "asdasd", "asdasd", "", 200, "adssad", 1)
@@ -21,7 +23,7 @@ def test_input(self):
2123
panel.ElasticQueryInfo("GET", "asdasd", "asdasd", b"{'asddsa': 'asddasds'}", 200, "adssad", 1)
2224

2325

24-
class PanelTests(unittest.TestCase):
26+
class PanelTests(TestCase):
2527
def setUp(self):
2628
self.get_response = lambda request: HttpResponse()
2729
self.request = RequestFactory().get("/")

0 commit comments

Comments
 (0)