Skip to content

Commit

Permalink
100% coverage again
Browse files Browse the repository at this point in the history
  • Loading branch information
owais committed Jan 1, 2016
1 parent 53a969f commit 92d1166
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ target/
# Editors and IDEs
.ropeproject/

.python-version

examples/**/ve/
examples/**/venv/
examples/**/node_modules/
Expand Down
28 changes: 21 additions & 7 deletions tests/app/tests/test_webpack.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import json
import os
import time
import json
from subprocess import call
from threading import Thread
from unittest import skipIf

import django
from django.conf import settings
from django.test import TestCase, RequestFactory
from django_jinja.builtins import DEFAULT_EXTENSIONS
from django.test import RequestFactory, TestCase
from django.views.generic.base import TemplateView

from webpack_loader.utils import get_assets, get_config, get_bundle, WebpackError

from django_jinja.builtins import DEFAULT_EXTENSIONS
from webpack_loader.utils import (WebpackError, WebpackLoaderBadStatsError,
get_assets, get_bundle, get_config)

BUNDLE_PATH = os.path.join(settings.BASE_DIR, 'assets/bundles/')
DEFAULT_CONFIG = 'DEFAULT'
Expand All @@ -34,7 +33,6 @@ def compile_bundles(self, config, wait=None):
@skipIf(django.VERSION < (1, 7),
'not supported in this django version')
def test_config_check(self):
from django.core.checks import Error
from webpack_loader.apps import webpack_cfg_check
from webpack_loader.errors import BAD_CONFIG_ERROR

Expand Down Expand Up @@ -163,6 +161,21 @@ def test_missing_stats_file(self):
expected = 'Error reading {}. Are you sure webpack has generated the file and the path is correct?'.format(settings.WEBPACK_LOADER[DEFAULT_CONFIG]['STATS_FILE'])
self.assertIn(expected, str(e))

def test_bad_status_in_production(self):
stats_file = open(
settings.WEBPACK_LOADER[DEFAULT_CONFIG]['STATS_FILE'], 'w'
)
stats_file.write(json.dumps({'status': 'unexpected-status'}))
stats_file.close()
try:
get_bundle('main', get_config(DEFAULT_CONFIG))
except WebpackLoaderBadStatsError as e:
self.assertIn((
"The stats file does not contain valid data. Make sure "
"webpack-bundle-tracker plugin is enabled and try to run"
" webpack again."
), str(e))

def test_request_blocking(self):
# FIXME: This will work 99% time but there is no garauntee with the
# 4 second thing. Need a better way to detect if request was blocked on
Expand Down Expand Up @@ -194,3 +207,4 @@ def test_request_blocking(self):
result.rendered_content
elapsed = time.time() - then
self.assertTrue(elapsed < wait_for)

0 comments on commit 92d1166

Please sign in to comment.