<commit_before>from __future__ import absolute_import, print_function, unicode_literals
from django.test import TestCase


from ..hooks import WebpackBundleHook


class TestHook(WebpackBundleHook):
    unique_slug = "non_default_frontend"
    entry_file = "assets/src/kolibri_core_app.js"


class KolibriTagNavigationTestCase(TestCase):

    def test_frontend_tag(self):
        self.assertIn(
            "non_default_frontend",
            TestHook().render_to_html()
        )<commit_msg>Create a faked hook that does not try to read a live stats file<commit_after>from __future__ import absolute_import, print_function, unicode_literals

import json
import tempfile

from django.test import TestCase


from ..hooks import WebpackBundleHook


TEST_STATS_FILE = None


class TestHook(WebpackBundleHook):
    unique_slug = "non_default_frontend"
    src_file = "assets/src/kolibri_core_app.js"

    @property
    def stats_file(self):
        return TEST_STATS_FILE.name


class KolibriTagNavigationTestCase(TestCase):

    def setUp(self):
        global TEST_STATS_FILE
        TestCase.setUp(self)
        TEST_STATS_FILE = tempfile.NamedTemporaryFile(mode='w+', delete=False)
        self.test_hook = TestHook()
        json.dump(
            {
                "status": "done",
                "chunks": {
                    "non_default_frontend": [
                        {
                            "name": "non_default_frontend-2c4fb3d6a29238b06f84.js",
                            "publicPath": "non_default_frontend/non_default_frontend-2c4fb3d6a29238b06f84.js",
                            "path": "kolibri/core/static/non_default_frontend/non_default_frontend-2c4fb3d6a29238b06f84.js"
                        }
                    ]
                },
                "publicPath": "default_frontend/"
            },
            TEST_STATS_FILE
        )
        TEST_STATS_FILE.close()

    def test_frontend_tag(self):
        self.assertIn(
            "non_default_frontend",
            self.test_hook.render_to_html()
        )
{'fraction_non_alphanumeric': 0.07849829351535836, 'fraction_numerical': 0.01901511457825451, 'mean_word_length': 2.272727272727273, 'pattern_counts': {'":': 7, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1361481', 'n_tokens_mistral': 649, 'n_tokens_neox': 617, 'n_words': 103}