Skip to content

Fix testing and run it on GitHub actions #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Django CI

on: [push, pull_request]

jobs:
build:
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
django-version: ['3.2.*', '4.0.*', '4.1.*', '4.2.*', '5.0.*']
django-debug-toolbar-version: ['4.3.0', '3.8.1', '3.3.0']
exclude:
- django-version: '3.2.*'
python-version: '3.11'
- django-version: '3.2.*'
python-version: '3.12'

- django-version: '4.0.*'
python-version: '3.11'
- django-version: '4.0.*'
python-version: '3.12'

- django-version: '4.1.*'
python-version: '3.12'

- django-version: '5.0.*'
python-version: '3.8'
- django-version: '5.0.*'
python-version: '3.9'

steps:
- uses: actions/checkout@v2

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
pip install setuptools
pip install Django==${{ matrix.django-version }}
python setup.py install
pip install django-debug-toolbar==${{ matrix.django-debug-toolbar-version }}

- name: Run tests
run: python test_project/manage.py test
2 changes: 1 addition & 1 deletion template_profiler_panel/panels/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def _get_color(self, level):

def record(self, instance, start, end, level,
processing_timeline, **kwargs):
if not self.enabled:
if not self.is_enabled:
return

template_name = instance.name
Expand Down
7 changes: 3 additions & 4 deletions template_profiler_panel/tests/test_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@
class TemplateProfilerPanelTestCase(unittest.TestCase):
def setUp(self):
super(TemplateProfilerPanelTestCase, self).setUp()
self.panel = TemplateProfilerPanel(MagicMock())
self.panel = TemplateProfilerPanel(MagicMock(), get_response=MagicMock())
self.panel.record_stats = MagicMock()
self.template_rendered_receiver = MagicMock()
self.request = MagicMock()
self.response = MagicMock()
template_rendered.connect(self.template_rendered_receiver)

def tearDown(self):
Expand All @@ -40,7 +39,7 @@ def test_process_response_disabled_instrumentation(self):
t = Template('')
t.render(Context({}))

self.panel.process_response(self.request, self.response)
self.panel.process_request(self.request)

args = self.panel.record_stats.call_args[0][0]
self.assertEqual(len(args['templates']), 0)
Expand All @@ -52,7 +51,7 @@ def test_process_response_enabled_instrumentation(self):
t = Template('')
t.render(Context({}))

self.panel.process_response(self.request, self.response)
self.panel.process_request(self.request)
self.panel.disable_instrumentation()

args = self.panel.record_stats.call_args[0][0]
Expand Down
Binary file added test_project/.manage.py.swp
Binary file not shown.
Binary file added test_project/.settings.py.swp
Binary file not shown.
Empty file added test_project/__init__.py
Empty file.
10 changes: 10 additions & 0 deletions test_project/manage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env python
import os
import sys

if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")

from django.core.management import execute_from_command_line

execute_from_command_line(sys.argv)
36 changes: 36 additions & 0 deletions test_project/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import os

DEBUG = True
APPLICATION_DIR = os.path.dirname(globals()['__file__'])
SECRET_KEY = "foo"

TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [os.path.join(APPLICATION_DIR, "templates")],
"OPTIONS": {
"debug": DEBUG,
"loaders": [
(
"django.template.loaders.cached.Loader",
[
"django.template.loaders.filesystem.Loader",
"django.template.loaders.app_directories.Loader",
"admin_tools.template_loaders.Loader",
],
),
],
"context_processors": [
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
"django.template.context_processors.debug",
"django.template.context_processors.i18n",
"django.template.context_processors.media",
"django.template.context_processors.static",
"django.template.context_processors.csrf",
"django.template.context_processors.tz",
"django.template.context_processors.request",
],
},
}
]