| 1 |
from uuid import UUID |
| 2 |
from bs4 import BeautifulSoup |
| 3 |
from django.conf import settings |
| 4 |
from django.test import LiveServerTestCase, override_settings |
| 5 |
|
| 6 |
|
| 7 |
@override_settings(DEBUG=True) |
| 8 |
class DebugToolbarTestCase(LiveServerTestCase): |
| 9 |
databases = set(settings.DATABASES.keys()) |
| 10 |
|
| 11 |
def test_rendering(self): |
| 12 |
# |
| 13 |
# Rendering toolbar |
| 14 |
# |
| 15 |
response = self.client.get('/') |
| 16 |
self.assertEqual(response.status_code, 200) |
| 17 |
soup = BeautifulSoup(response.content.decode('utf-8'), 'html.parser') |
| 18 |
toolbar = soup.find(id='djDebug') |
| 19 |
self.assertIsNotNone(toolbar) |
| 20 |
# Support both old (store_id) and new (request_id) debug toolbar APIs |
| 21 |
if 'data-request-id' in toolbar.attrs: |
| 22 |
# django-debug-toolbar 6.x |
| 23 |
request_id = toolbar.attrs['data-request-id'] |
| 24 |
UUID(request_id) |
| 25 |
render_panel_url = toolbar.attrs['data-render-panel-url'] |
| 26 |
panel_id = soup.find(title='Cachalot')['class'][0] |
| 27 |
panel_url = f'{render_panel_url}?request_id={request_id}&panel_id={panel_id}' |
| 28 |
else: |
| 29 |
# django-debug-toolbar < 6.0 |
| 30 |
store_id = toolbar.attrs['data-store-id'] |
| 31 |
UUID(store_id) |
| 32 |
render_panel_url = toolbar.attrs['data-render-panel-url'] |
| 33 |
panel_id = soup.find(title='Cachalot')['class'][0] |
| 34 |
panel_url = f'{render_panel_url}?store_id={store_id}&panel_id={panel_id}' |
| 35 |
|
| 36 |
# |
| 37 |
# Rendering panel |
| 38 |
# |
| 39 |
panel_response = self.client.get(panel_url) |
| 40 |
self.assertEqual(panel_response.status_code, 200) |
| 41 |
# TODO: Check that the displayed data is correct. |