Skip to content

Commit 78512ca

Browse files
Basic template_tag test
1 parent 1a3adad commit 78512ca

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

async_include/templates/async_include/template_tag.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
document.addEventListener("DOMContentLoaded", function(event) {
23
const request_frequency = "{{request__frequency}}";
34

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{% load async_include %}
2+
3+
{% async_include "async_include/spinner.html" %}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# -*- coding: utf-8 -*-
2+
import unittest.mock
3+
4+
from django.template.loader import render_to_string
5+
from django.test import TestCase
6+
7+
8+
class TestViews(TestCase):
9+
@classmethod
10+
def setUpClass(cls):
11+
import os
12+
os.environ.setdefault(
13+
'DJANGO_SETTINGS_MODULE', 'async_include.tests.settings'
14+
)
15+
import django
16+
django.setup()
17+
super(TestViews, cls).setUpClass()
18+
19+
@unittest.mock.patch('async_include.templatetags.async_include.get_unique_template_id')
20+
@unittest.mock.patch('async_include.templatetags.async_include.slugify_template_path')
21+
def test_async_include(self, mock_slugify_template_path, mock_get_unique_template_id):
22+
mock_slugify_template_path.return_value = 'test_template_path'
23+
mock_get_unique_template_id.return_value = 'test_uuid'
24+
25+
test_async_include_html = render_to_string('test_async_include.html')
26+
27+
self.assertIn(
28+
'<script id="script_test_template_path__test_uuid" type="text/javascript">',
29+
test_async_include_html
30+
)
31+
self.assertIn(
32+
'make_request__test_template_path__test_uuid',
33+
test_async_include_html
34+
)
35+
self.assertIn(
36+
'const block_id = "test_template_path__test_uuid";',
37+
test_async_include_html
38+
)

0 commit comments

Comments
 (0)