1+ import json
12import os
23import time
3- import json
44from subprocess import call
55from threading import Thread
66from unittest import skipIf
77
88import django
99from django .conf import settings
10- from django .test import TestCase , RequestFactory
11- from django_jinja .builtins import DEFAULT_EXTENSIONS
10+ from django .test import RequestFactory , TestCase
1211from django .views .generic .base import TemplateView
13-
14- from webpack_loader .utils import get_assets , get_config , get_bundle , WebpackError
15-
12+ from django_jinja . builtins import DEFAULT_EXTENSIONS
13+ from webpack_loader .utils import ( WebpackError , WebpackLoaderBadStatsError ,
14+ get_assets , get_bundle , get_config )
1615
1716BUNDLE_PATH = os .path .join (settings .BASE_DIR , 'assets/bundles/' )
1817DEFAULT_CONFIG = 'DEFAULT'
@@ -34,7 +33,6 @@ def compile_bundles(self, config, wait=None):
3433 @skipIf (django .VERSION < (1 , 7 ),
3534 'not supported in this django version' )
3635 def test_config_check (self ):
37- from django .core .checks import Error
3836 from webpack_loader .apps import webpack_cfg_check
3937 from webpack_loader .errors import BAD_CONFIG_ERROR
4038
@@ -163,6 +161,21 @@ def test_missing_stats_file(self):
163161 expected = 'Error reading {}. Are you sure webpack has generated the file and the path is correct?' .format (settings .WEBPACK_LOADER [DEFAULT_CONFIG ]['STATS_FILE' ])
164162 self .assertIn (expected , str (e ))
165163
164+ def test_bad_status_in_production (self ):
165+ stats_file = open (
166+ settings .WEBPACK_LOADER [DEFAULT_CONFIG ]['STATS_FILE' ], 'w'
167+ )
168+ stats_file .write (json .dumps ({'status' : 'unexpected-status' }))
169+ stats_file .close ()
170+ try :
171+ get_bundle ('main' , get_config (DEFAULT_CONFIG ))
172+ except WebpackLoaderBadStatsError as e :
173+ self .assertIn ((
174+ "The stats file does not contain valid data. Make sure "
175+ "webpack-bundle-tracker plugin is enabled and try to run"
176+ " webpack again."
177+ ), str (e ))
178+
166179 def test_request_blocking (self ):
167180 # FIXME: This will work 99% time but there is no garauntee with the
168181 # 4 second thing. Need a better way to detect if request was blocked on
@@ -194,3 +207,4 @@ def test_request_blocking(self):
194207 result .rendered_content
195208 elapsed = time .time () - then
196209 self .assertTrue (elapsed < wait_for )
210+
0 commit comments