Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 85 lines (76 sloc) 3.025 kb
6bae2cae »
2012-03-02 static image content
1 import re
e7c1f02b »
2012-02-26 caching works for the home page
2 import datetime
3 from django.core.urlresolvers import reverse
6bae2cae »
2012-03-02 static image content
4 from django.conf import settings
e7c1f02b »
2012-02-26 caching works for the home page
5 from django.test import TestCase
6 from apps.plog.models import BlogItem, BlogComment, Category
7 from apps.plog.utils import utc_now
43deed5a »
2012-03-01 re-org redisutils
8 from apps.redisutils import get_redis_connection
dd358522 »
2012-01-30 initial commit
9
10
e7c1f02b »
2012-02-26 caching works for the home page
11 class PlogTestCase(TestCase):
12 def setUp(self):
13 redis = get_redis_connection()
14 redis.flushdb()
15
16 def test_blog_post_caching(self):
17 blog = BlogItem.objects.create(
18 oid='some-longish-test-post',
19 title='TITLEX',
20 text='BLABLABLA',
21 display_format='structuredtext',
22 pub_date=utc_now() - datetime.timedelta(seconds=10),
23 )
24 url = reverse('blog_post', args=[blog.oid])
25
26 import apps.plog.views
27 old_render = apps.plog.views.render
28 from django.shortcuts import render as django_render
29 render_counts = []
30 def mocked_render(*a, **k):
31 render_counts.append(1)
32 return django_render(*a, **k)
33 apps.plog.views.render = mocked_render
34 try:
35 response = self.client.get(url)
36 self.assertTrue(blog.title in response.content)
37 assert '0 comments' in response.content
38 response = self.client.get(url)
39 assert '0 comments' in response.content
dd358522 »
2012-01-30 initial commit
40
e7c1f02b »
2012-02-26 caching works for the home page
41 comment1 = BlogComment.objects.create(
42 comment="textext",
43 blogitem=blog,
44 approved=True,
45 add_date=utc_now() + datetime.timedelta(seconds=1),
46 )
47 response = self.client.get(url)
48 assert '1 comment' in response.content
49 finally:
50 apps.plog.views.render = old_render
dd358522 »
2012-01-30 initial commit
51
e7c1f02b »
2012-02-26 caching works for the home page
52 assert len(render_counts) == 2
6bae2cae »
2012-03-02 static image content
53
54 def test_text_rendering_with_images(self):
55 blog = BlogItem.objects.create(
56 oid='myoid',
57 title='TITLEX',
58 text="""
59 "image.png":/plog/myoid/image.png
60 and *this*
61 """,
62 display_format='structuredtext',
63 pub_date=utc_now() - datetime.timedelta(seconds=10),
64 )
65 url = reverse('blog_post', args=[blog.oid])
66 response = self.client.get(url)
67 content = response.content.split('id="post"')[1].split('</section')[0]
68 self.assertTrue('<em>this</em>' in content)
69 regex_str = ('%sCACHE-\d+%s' %
70 (settings.STATIC_URL, re.escape('/plog/myoid/image.png')))
71
72 self.assertTrue(re.findall(regex_str, content))
73
74 old = settings.STATIC_URL
75 settings.STATIC_URL = '//some.cdn.com/'
76 try:
77 blog.text_rendered = ''
78 blog.save()
79 response = self.client.get(url)
80 content = response.content.split('id="post"')[1].split('</section')[0]
81 regex_str = ('%sCACHE-\d+%s' %
82 (settings.STATIC_URL, re.escape('/plog/myoid/image.png')))
83 self.assertTrue(re.findall(regex_str, content))
84 finally:
85 settings.STATIC_URL = old
Something went wrong with that request. Please try again.