Skip to content

Commit

Permalink
exclude test fix + reverse.js file save test
Browse files Browse the repository at this point in the history
  • Loading branch information
krupin.dv committed Oct 14, 2014
1 parent 1f1b16b commit 948d02d
Showing 1 changed file with 30 additions and 14 deletions.
44 changes: 30 additions & 14 deletions django_js_reverse/tests/unit_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import os
from os.path import join, dirname
import sys
import warnings

Expand All @@ -17,26 +18,14 @@

from selenium.webdriver.phantomjs.webdriver import WebDriver

import django_js_reverse
from django_js_reverse import save_js_file

# Raise errors on DeprecationWarnings
warnings.simplefilter('error', DeprecationWarning)



class JSReverseNamespaceExcludeTest(TestCase):
urls = 'django_js_reverse.tests.test_urls'

def test_namespace_in_urls(self):
response = self.client.get('/jsreverse/')
self.assertContains(response, 'exclude_namespace', status_code=200)

@override_settings(JS_REVERSE_EXCLUDE_NAMESPACES=['exclude_namespace'])
def test_namespace_not_in_response(self):
response = self.client.get('/jsreverse/')
self.assertNotContains(response, 'exclude_namespace', status_code=200)



class JSReverseViewTestCaseMinified(TestCase):
client = None
urls = 'django_js_reverse.tests.test_urls'
Expand Down Expand Up @@ -111,6 +100,33 @@ def test_minification(self):
self.assertTrue(len(js_minified) < len(js_not_minified))



class JSReverseStaticFileSaveTest(JSReverseViewTestCaseMinified):
def test_reverse_js_file_save(self):
save_js_file()

package_path = dirname(django_js_reverse.__file__)
path = join(package_path, 'static', 'django_js_reverse', 'js', 'reverse.js')
f = open(path)
f_content = f.read()
print f_content
r2 = self.client.get('/jsreverse/')
self.assertEqual(f_content, r2.content, "Static file don't match http response content")



class JSReverseNamespaceExcludeTest(JSReverseViewTestCaseMinified):
def test_namespace_in_urls(self):
response = self.client.get('/jsreverse/')
self.assertContains(response, 'exclude_namespace', status_code=200)

@override_settings(JS_REVERSE_EXCLUDE_NAMESPACES=['exclude_namespace'])
def test_namespace_not_in_response(self):
response = self.client.get('/jsreverse/')
self.assertNotContains(response, 'exclude_namespace', status_code=200)



if __name__ == '__main__':
sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..') + os.sep)
unittest.main()

0 comments on commit 948d02d

Please sign in to comment.