Skip to content

Commit 92d1166

Browse files
committed
100% coverage again
1 parent 53a969f commit 92d1166

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ target/
5959
# Editors and IDEs
6060
.ropeproject/
6161

62+
.python-version
63+
6264
examples/**/ve/
6365
examples/**/venv/
6466
examples/**/node_modules/

tests/app/tests/test_webpack.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1+
import json
12
import os
23
import time
3-
import json
44
from subprocess import call
55
from threading import Thread
66
from unittest import skipIf
77

88
import django
99
from 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
1211
from 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

1716
BUNDLE_PATH = os.path.join(settings.BASE_DIR, 'assets/bundles/')
1817
DEFAULT_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

Comments
 (0)