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()
        )

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()
        )

Create a faked hook that does not try to read a live stats file
Create a faked hook that does not try to read a live stats file

  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"
-     entry_file = "assets/src/kolibri_core_app.js"
+     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",
-             TestHook().render_to_html()
+             self.test_hook.render_to_html()
          )
  
Create a faked hook that does not try to read a live stats file
## Code 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()
        )

## Instruction:
Create a faked hook that does not try to read a live stats file
## Code 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()
        )
