Restructured everything.
This commit is contained in:
0
apps/base/tests/__init__.py
Normal file
0
apps/base/tests/__init__.py
Normal file
76
apps/base/tests/test_templates.py
Normal file
76
apps/base/tests/test_templates.py
Normal file
@@ -0,0 +1,76 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
from django.conf import settings
|
||||
from django.template.context import Context
|
||||
from django.test import SimpleTestCase
|
||||
|
||||
|
||||
class BaseTemplateTestCase(SimpleTestCase):
|
||||
def assertInHTML_multi(self, response, needles, format_kwargs=None):
|
||||
content = response.content.decode('utf-8')
|
||||
for needle in needles:
|
||||
if format_kwargs is not None:
|
||||
needle = needle.format(**format_kwargs)
|
||||
self.assertInHTML(needle, content)
|
||||
|
||||
def setUp(self):
|
||||
super(BaseTemplateTestCase, self).setUp()
|
||||
self.response = self.client.get('/')
|
||||
self.static_url = settings.STATIC_URL
|
||||
self.base_prefix = 'base/'
|
||||
|
||||
def test_template_usage(self):
|
||||
response = self.response
|
||||
self.assertTemplateUsed(response, 'base/base.html')
|
||||
|
||||
def test_local_css_link(self):
|
||||
response = self.response
|
||||
|
||||
format_kwargs = {
|
||||
'static_url': self.static_url,
|
||||
'base_prefix': self.base_prefix,
|
||||
}
|
||||
|
||||
needles = (
|
||||
'<link type="text/css" href="{static_url}{base_prefix}css/local.css" rel="stylesheet" />',
|
||||
)
|
||||
|
||||
self.assertInHTML_multi(response, needles, format_kwargs)
|
||||
|
||||
def test_bootstrap_css_links(self):
|
||||
response = self.response
|
||||
|
||||
format_kwargs = {
|
||||
'static_url': self.static_url,
|
||||
'base_prefix': self.base_prefix,
|
||||
}
|
||||
|
||||
needles = (
|
||||
# bootstrap css
|
||||
'<link type="text/css" href="{static_url}{base_prefix}bootstrap/css/bootstrap.min.css"'
|
||||
' rel="stylesheet" />',
|
||||
# jquery.js file
|
||||
'<script type="text/javascript" src="{static_url}{base_prefix}js/jquery.min.js"></script>',
|
||||
# bootstrap js file
|
||||
'<script type="text/javascript" src="{static_url}{base_prefix}bootstrap/js/bootstrap.min.js"></script>',
|
||||
)
|
||||
|
||||
self.assertInHTML_multi(response, needles, format_kwargs)
|
||||
|
||||
def test_page_footer(self):
|
||||
response = self.response
|
||||
self.assertTemplateUsed(response, 'signum.html')
|
||||
for template in response.templates:
|
||||
if template.name == 'signum.html':
|
||||
signum = template.render(Context({}))
|
||||
break
|
||||
else: # pragma: no cover
|
||||
self.fail('Cannot find signum template.')
|
||||
|
||||
needle = """
|
||||
<div id="page-footer">
|
||||
<div class="signum">{signum}</div>
|
||||
</div>
|
||||
""".format(signum=signum)
|
||||
|
||||
self.assertInHTML(needle, response.content.decode('utf-8'))
|
||||
31
apps/base/tests/test_views.py
Normal file
31
apps/base/tests/test_views.py
Normal file
@@ -0,0 +1,31 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
import socket
|
||||
from django.test import SimpleTestCase
|
||||
|
||||
|
||||
class DjangoAdminTestCase(SimpleTestCase):
|
||||
def test_djangoadmin(self):
|
||||
response = self.client.get('/djangoadmin', follow=True)
|
||||
self.assertContains(response, 'Django administration')
|
||||
|
||||
|
||||
class RootTestCase(SimpleTestCase):
|
||||
def setUp(self):
|
||||
super(RootTestCase, self).setUp()
|
||||
self.response = self.client.get('/')
|
||||
|
||||
def test_root_template(self):
|
||||
response = self.response
|
||||
self.assertTemplateUsed(response, 'base/root.html')
|
||||
|
||||
def test_root_context(self):
|
||||
response = self.response
|
||||
self.assertIn('hostname', response.context)
|
||||
hostname = socket.gethostname()
|
||||
self.assertEqual(response.context['hostname'], hostname)
|
||||
|
||||
def test_root_content(self):
|
||||
response = self.response
|
||||
hostname = socket.gethostname().capitalize()
|
||||
self.assertContains(response, hostname)
|
||||
12
apps/base/tests/utils.py
Normal file
12
apps/base/tests/utils.py
Normal file
@@ -0,0 +1,12 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
import os
|
||||
from tempfile import mkdtemp as _mkdtmp
|
||||
|
||||
|
||||
def mkdtemp(prefix):
|
||||
dirname = os.path.dirname
|
||||
pkg_base_dir = dirname(dirname(dirname(__file__)))
|
||||
tmp_dir = os.path.join(pkg_base_dir, 'tmp')
|
||||
os.makedirs(tmp_dir, exist_ok=True)
|
||||
return _mkdtmp(prefix=prefix, dir=tmp_dir)
|
||||
Reference in New Issue
Block a user