forked from python/pythondotorg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.py
30 lines (23 loc) · 929 Bytes
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import logging
from django import template
from django.test import TestCase, override_settings
from .models import Box
logging.disable(logging.CRITICAL)
class BaseTestCase(TestCase):
def setUp(self):
self.box = Box.objects.create(label='test', content='test content')
class TemplateTagTests(BaseTestCase):
def render(self, tmpl, **context):
t = template.Template(tmpl)
return t.render(template.Context(context))
def test_tag(self):
r = self.render('{% load boxes %}{% box "test" %}')
self.assertEqual(r, self.box.content.rendered)
def test_tag_invalid_label(self):
r = self.render('{% load boxes %}{% box "missing" %}')
self.assertEqual(r, '')
class ViewTests(BaseTestCase):
@override_settings(ROOT_URLCONF='boxes.urls')
def test_box_view(self):
r = self.client.get('/test/')
self.assertContains(r, self.box.content.rendered)