Skip to content
Newer
Older
100644 183 lines (160 sloc) 8.85 KB
1a777a1 @markpasc Use a range
markpasc authored Feb 8, 2010
1 # Copyright (c) 2009-2010 Six Apart Ltd.
ded09aa @markpasc Add copyright and license notices
markpasc authored Sep 24, 2009
2 # All rights reserved.
3 #
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are met:
6 #
7 # * Redistributions of source code must retain the above copyright notice,
8 # this list of conditions and the following disclaimer.
9 #
10 # * Redistributions in binary form must reproduce the above copyright notice,
11 # this list of conditions and the following disclaimer in the documentation
12 # and/or other materials provided with the distribution.
13 #
14 # * Neither the name of Six Apart Ltd. nor the names of its contributors may
15 # be used to endorse or promote products derived from this software without
16 # specific prior written permission.
17 #
18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 # POSSIBILITY OF SUCH DAMAGE.
29
e01334d Package up these apps
Mark Paschal authored May 12, 2009
30 import unittest
31
32 from django.db import models
6d92c50 Add template filter to autolink twitter tweets
Mark Paschal authored Aug 28, 2009
33 from django.template import Context, Template
34 from django.utils.safestring import mark_safe
e01334d Package up these apps
Mark Paschal authored May 12, 2009
35
36 from typepadapp.models.users import User
37
38
39 class ProfileTestCase(unittest.TestCase):
40
41 def setUp(self):
42 import typepadapp.models.profiles
b44e3ee @markpasc Complete renaming old supplementary profile field model to LocalProfile
markpasc authored Apr 5, 2010
43 class LocalProfile(typepadapp.models.profiles.LocalProfile):
e01334d Package up these apps
Mark Paschal authored May 12, 2009
44 hiphop_name = models.CharField(max_length=80)
45
46 import motion.models
b44e3ee @markpasc Complete renaming old supplementary profile field model to LocalProfile
markpasc authored Apr 5, 2010
47 motion.models.LocalProfile = LocalProfile
e01334d Package up these apps
Mark Paschal authored May 12, 2009
48
49 from django.conf import settings
b44e3ee @markpasc Complete renaming old supplementary profile field model to LocalProfile
markpasc authored Apr 5, 2010
50 settings.AUTH_PROFILE_MODULE = 'motion.LocalProfile'
e01334d Package up these apps
Mark Paschal authored May 12, 2009
51
52 from django.core import management
53 management.call_command('syncdb', verbosity=1, interactive=False)
54
f8f0d3e Use conventional spacing and method naming syntax for test classes
Mark Paschal authored Aug 13, 2009
55 def test_profile(self):
b44e3ee @markpasc Complete renaming old supplementary profile field model to LocalProfile
markpasc authored Apr 5, 2010
56 from motion.models import LocalProfile
57 p = LocalProfile(user_id='6paf37603c44724b3a',
e01334d Package up these apps
Mark Paschal authored May 12, 2009
58 hiphop_name='dj fred')
59 p.save()
60
61 u = User(id='6paf37603c44724b3a')
62
63 self.assertEquals(u.get_profile(), p)
6d92c50 Add template filter to autolink twitter tweets
Mark Paschal authored Aug 28, 2009
64
65
66 class TwittilizeTestCase(unittest.TestCase):
67
68 template = Template('{% load twittilize %}{{ testtext|twittilize }}')
69
70 def run_tests(self, *args):
71 for testtext, expected in args:
72 context = Context({'testtext': testtext})
73 result = self.template.render(context)
74 self.assertEquals(result, expected)
75
76 def test_basic(self):
77 self.run_tests(
78 ('', ''),
79 ('a', 'a'),
80 ('This is a test tweet.', 'This is a test tweet.'),
81 )
82
83 def test_links(self):
84 self.run_tests(
85 ('This ends with a link http://example.com/asfdasf',
86 'This ends with a link <a href="http://example.com/asfdasf" rel="nofollow">http://example.com/asfdasf</a>'),
87 ('This has a http://example.com/link in the middle',
88 'This has a <a href="http://example.com/link" rel="nofollow">http://example.com/link</a> in the middle'),
89 ('http://example.com/link at the start',
90 '<a href="http://example.com/link" rel="nofollow">http://example.com/link</a> at the start'),
91 )
92
93 def test_usernames(self):
94 self.run_tests(
95 ('homg can you believe that crazy @example',
96 'homg can you believe that crazy @<a href="http://twitter.com/example">example</a>'),
97 ('RT @example This is a test tweet.',
98 'RT @<a href="http://twitter.com/example">example</a> This is a test tweet.'),
99 ('@example homg so many test tweets D:',
100 '@<a href="http://twitter.com/example">example</a> homg so many test tweets D:'),
101 ('@somebody @whobody @thatbody',
102 '@<a href="http://twitter.com/somebody">somebody</a> '
103 '@<a href="http://twitter.com/whobody">whobody</a> '
104 '@<a href="http://twitter.com/thatbody">thatbody</a>'),
105 ("I really liked @somebody's tweet",
106 'I really liked @<a href="http://twitter.com/somebody">somebody</a>&#39;s tweet'),
107 )
108
109 def test_hashtags(self):
110 self.run_tests(
111 ('This is a tweet with a #hashtag',
fac9d1c Change hashtags to URI escaped in the search URL
Mark Paschal authored Aug 31, 2009
112 'This is a tweet with a <a href="http://twitter.com/search?q=%23hashtag">#hashtag</a>'),
6d92c50 Add template filter to autolink twitter tweets
Mark Paschal authored Aug 28, 2009
113 ('This is a #tweet with an inline tag',
fac9d1c Change hashtags to URI escaped in the search URL
Mark Paschal authored Aug 31, 2009
114 'This is a <a href="http://twitter.com/search?q=%23tweet">#tweet</a> with an inline tag'),
6d92c50 Add template filter to autolink twitter tweets
Mark Paschal authored Aug 28, 2009
115 ('#hashtags rarely come at the front',
fac9d1c Change hashtags to URI escaped in the search URL
Mark Paschal authored Aug 31, 2009
116 '<a href="http://twitter.com/search?q=%23hashtags">#hashtags</a> rarely come at the front'),
6d92c50 Add template filter to autolink twitter tweets
Mark Paschal authored Aug 28, 2009
117 ('Using #some-long-hashtag is fine #spaces--',
fac9d1c Change hashtags to URI escaped in the search URL
Mark Paschal authored Aug 31, 2009
118 'Using <a href="http://twitter.com/search?q=%23some-long-hashtag">'
6d92c50 Add template filter to autolink twitter tweets
Mark Paschal authored Aug 28, 2009
119 '#some-long-hashtag</a> is fine <a href="http://twitter.com/'
fac9d1c Change hashtags to URI escaped in the search URL
Mark Paschal authored Aug 31, 2009
120 'search?q=%23spaces">#spaces</a>--'),
6d92c50 Add template filter to autolink twitter tweets
Mark Paschal authored Aug 28, 2009
121 ('Hashtags have #fU77&!$$(!)!($!)%#&@(#&$)nny_syntax!',
fac9d1c Change hashtags to URI escaped in the search URL
Mark Paschal authored Aug 31, 2009
122 'Hashtags have <a href="http://twitter.com/search?q=%23fU77%26'
123 '%21%24%24%28%21%29%21%28%24%21%29%25%23%26%40%28%23%26%24'
124 '%29nny_syntax">#fU77&amp;!$$(!)!($!)%#&amp;@(#&amp;$)nny_'
125 'syntax</a>!'),
6d92c50 Add template filter to autolink twitter tweets
Mark Paschal authored Aug 28, 2009
126 ("#hashtags' syntax for #o'neill's stream",
fac9d1c Change hashtags to URI escaped in the search URL
Mark Paschal authored Aug 31, 2009
127 '<a href="http://twitter.com/search?q=%23hashtags">#hashtags</a>'
6d92c50 Add template filter to autolink twitter tweets
Mark Paschal authored Aug 28, 2009
128 '&#39; syntax for <a href="http://twitter.com/search?q='
fac9d1c Change hashtags to URI escaped in the search URL
Mark Paschal authored Aug 31, 2009
129 """%23o%27neill">#o&#39;neill</a>&#39;s stream"""),
6d92c50 Add template filter to autolink twitter tweets
Mark Paschal authored Aug 28, 2009
130 )
131
132 def test_complex(self):
133 self.run_tests(
134 ('RT @monkinetic Grease Alley continues to grow: http://bit.ly/nmpoK #lego #scifi',
135 'RT @<a href="http://twitter.com/monkinetic">monkinetic</a> '
136 'Grease Alley continues to grow: '
137 '<a href="http://bit.ly/nmpoK" rel="nofollow">http://bit.ly/nmpoK</a> '
fac9d1c Change hashtags to URI escaped in the search URL
Mark Paschal authored Aug 31, 2009
138 '<a href="http://twitter.com/search?q=%23lego">#lego</a> '
139 '<a href="http://twitter.com/search?q=%23scifi">#scifi</a>'),
6d92c50 Add template filter to autolink twitter tweets
Mark Paschal authored Aug 28, 2009
140 )
141
142 def test_futureproof(self):
143 """Checks that the auto-linking doesn't auto-link strings that are
144 already linked."""
145 self.run_tests(
146 (mark_safe('RT @<a href="http://twitter.com/monkinetic">monkinetic</a> '
147 'Grease Alley continues to grow: '
148 '<a href="http://bit.ly/nmpoK" rel="nofollow">http://bit.ly/nmpoK</a> '
149 '<a href="http://twitter.com/search?q=#lego">#lego</a> '
150 '<a href="http://twitter.com/search?q=#scifi">#scifi</a>'),
151 'RT @<a href="http://twitter.com/monkinetic">monkinetic</a> '
152 'Grease Alley continues to grow: '
153 '<a href="http://bit.ly/nmpoK" rel="nofollow">http://bit.ly/nmpoK</a> '
154 '<a href="http://twitter.com/search?q=#lego">#lego</a> '
155 '<a href="http://twitter.com/search?q=#scifi">#scifi</a>'),
1678259 Try including the @ inside the link (which happens to work)
Mark Paschal authored Aug 31, 2009
156 (mark_safe('RT <a href="http://twitter.com/monkinetic">@monkinetic</a> '
157 'Grease Alley continues to grow: '
158 '<a href="http://bit.ly/nmpoK" rel="nofollow">http://bit.ly/nmpoK</a> '
159 '<a href="http://twitter.com/search?q=#lego">#lego</a> '
160 '<a href="http://twitter.com/search?q=#scifi">#scifi</a>'),
161 'RT <a href="http://twitter.com/monkinetic">@monkinetic</a> '
162 'Grease Alley continues to grow: '
163 '<a href="http://bit.ly/nmpoK" rel="nofollow">http://bit.ly/nmpoK</a> '
164 '<a href="http://twitter.com/search?q=#lego">#lego</a> '
165 '<a href="http://twitter.com/search?q=#scifi">#scifi</a>'),
cec02bb @bradchoate Fixes to handle autolinked Twitter posts from TypePad.
bradchoate authored Dec 11, 2009
166 ('RT <a href="http://twitter.com/monkinetic">@monkinetic</a> '
167 'Grease Alley continues to grow: '
168 '<a href="http://bit.ly/nmpoK" rel="nofollow">http://bit.ly/nmpoK</a> '
169 '<a href="http://twitter.com/search?q=#lego">#lego</a> '
170 '<a href="http://twitter.com/search?q=#scifi">#scifi</a>',
171 'RT <a href="http://twitter.com/monkinetic">@monkinetic</a> '
172 'Grease Alley continues to grow: '
173 '<a href="http://bit.ly/nmpoK" rel="nofollow">http://bit.ly/nmpoK</a> '
174 '<a href="http://twitter.com/search?q=#lego">#lego</a> '
175 '<a href="http://twitter.com/search?q=#scifi">#scifi</a>'),
176 (mark_safe('&quot;quoted&quot;'),
177 '&quot;quoted&quot;'),
178 ('"quoted"',
179 '&quot;quoted&quot;'),
180 ('&quot;quoted&quot;',
181 '&quot;quoted&quot;'),
6d92c50 Add template filter to autolink twitter tweets
Mark Paschal authored Aug 28, 2009
182 )
Something went wrong with that request. Please try again.