Skip to content

Commit

Permalink
Add stacktrace and fix tests using templates
Browse files Browse the repository at this point in the history
  • Loading branch information
benoit-chabord-cdx committed Feb 22, 2022
1 parent 9bdcdd6 commit d8d0ef8
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 8 deletions.
3 changes: 3 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
3.1.0
* Add a stacktrace to the records to show where the searches were originated #13

3.0.2
* Just CI auto deploy fixes

Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ Django Elasticsearch Toolbar
============================

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

About
Expand Down
12 changes: 9 additions & 3 deletions elastic_panel/panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@
import json

from debug_toolbar.panels import Panel
from debug_toolbar.utils import ThreadCollector, get_stack, tidy_stacktrace, render_stacktrace, \
get_module_path, hidden_paths
from debug_toolbar.utils import (
ThreadCollector,
get_module_path,
get_stack,
hidden_paths,
render_stacktrace,
tidy_stacktrace,
)
from django.templatetags.static import static
from django.utils.translation import gettext_lazy as _
from elasticsearch.connection.base import Connection

# Patching og the orginal elasticsearch log_request
# Patching og the original elasticsearch log_request
old_log_request_success = Connection.log_request_success
collector = ThreadCollector()

Expand Down
3 changes: 3 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[pytest]
env =
DJANGO_SETTINGS_MODULE=tests.settings
2 changes: 2 additions & 0 deletions tests/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ django-debug-toolbar>=3.0
elasticsearch<8.0.0

pytest
pytest-env

isort
flake8
flake8-print # Forbid print statement in code use logging. instead
Expand Down
26 changes: 26 additions & 0 deletions tests/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import os

BASE_DIR = os.path.dirname(os.path.dirname(__file__))

INSTALLED_APPS = ["debug_toolbar", "elastic_panel"]

DEBUG_TOOLBAR_PANELS = [
"elastic_panel.panel.ElasticDebugPanel",
]
SECRET_KEY = "test"
DEBUG = True

DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": ":memory:",
},
}

TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [BASE_DIR + "/tests/templates"],
"APP_DIRS": True,
},
]
10 changes: 6 additions & 4 deletions tests/test_toolbar.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import unittest

from django.conf import settings
import django

django.setup()

settings.configure()

from debug_toolbar.toolbar import DebugToolbar # noqa: E402
from django.http import HttpResponse # noqa: E402
from django.test import RequestFactory # noqa: E402
from django.test import TestCase
from elasticsearch.connection import Connection # noqa: E402

from elastic_panel import panel # noqa: E402


class ImportTest(unittest.TestCase):
class ImportTest(TestCase):
def test_input(self):
panel.ElasticQueryInfo("GET", "asdasd", "asdasd", "{}", 200, "adssad", 1)
panel.ElasticQueryInfo("GET", "asdasd", "asdasd", "", 200, "adssad", 1)
Expand All @@ -21,7 +23,7 @@ def test_input(self):
panel.ElasticQueryInfo("GET", "asdasd", "asdasd", b"{'asddsa': 'asddasds'}", 200, "adssad", 1)


class PanelTests(unittest.TestCase):
class PanelTests(TestCase):
def setUp(self):
self.get_response = lambda request: HttpResponse()
self.request = RequestFactory().get("/")
Expand Down

0 comments on commit d8d0ef8

Please sign in to comment.