-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Peter Bengtsson
committed
Apr 7, 2011
1 parent
3351ecf
commit c9b0f3f
Showing
11 changed files
with
411 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
* TESTS! | ||
|
||
* commenting on lines of code | ||
|
||
* Comments in HTML instead of AJAX (SEO) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from test_models import * | ||
from test_handlers import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import json | ||
from apps.main.tests.test_handlers import HandlersTestCase | ||
class GistsHandlersTestCase(HandlersTestCase): | ||
|
||
|
||
def test_commenting_on_gist(self): | ||
assert not self.db.Comment.find().count() | ||
peter = self.db.User() | ||
peter.login = u'peterbe' | ||
peter.email = u'' | ||
peter.company = u'' | ||
peter.name = u'Peter' | ||
peter.save() | ||
|
||
gist1 = self.db.Gist() | ||
gist1.user = peter | ||
gist1.gist_id = 1234 | ||
gist1.created_at = u'yesterday' | ||
gist1.files = [u'foo.py'] | ||
gist1.description = u'Testing the Atom feed' | ||
gist1.discussion = u"""Full `markdown` description: | ||
function foo(): | ||
return bar | ||
[peterbe](http://www.peterbe.com) | ||
""" | ||
gist1.save() | ||
|
||
comment_url = self.reverse_url('comments', 1234) | ||
response = self.client.get(comment_url) | ||
assert response.code == 200 | ||
struct = json.loads(response.body) | ||
self.assertEqual(struct, {'comments':[]}) | ||
|
||
post_data = { | ||
'comment':'I love `cheese`!', | ||
'file': 'foo.py', | ||
} | ||
response = self.client.post(comment_url, post_data) | ||
self.assertEqual(response.code, 403) | ||
|
||
self.client.login('peterbe') | ||
|
||
response = self.client.post(comment_url, post_data) | ||
self.assertEqual(response.code, 302) | ||
self.assertTrue(response.headers['Location'].startswith( | ||
self.reverse_url('view_gist', 1234))) | ||
|
||
assert self.db.Comment.find().count() | ||
comment = self.db.Comment.one() | ||
self.assertEqual(comment.user.login, 'peterbe') | ||
self.assertEqual(comment.comment, post_data['comment']) | ||
self.assertEqual(comment.file, post_data['file']) | ||
|
||
response = self.client.get(comment_url) | ||
assert response.code == 200 | ||
struct = json.loads(response.body) | ||
self.assertEqual(len(struct['comments']), 1) | ||
first = struct['comments'][0] | ||
|
||
self.assertTrue(first.get('ago')) | ||
self.assertTrue('<code>cheese</code>' in first['comment']) | ||
self.assertTrue(first.get('user')) | ||
self.assertTrue(first.get('id')) | ||
|
||
def test_preview_markdown(self): | ||
url = self.reverse_url('preview_markdown') | ||
post_data = {'text': | ||
"Test\nfoo `and` <script>alert('xsss')</script>"} | ||
response = self.client.post(url, post_data) | ||
assert response.code == 200 | ||
struct = json.loads(response.body) | ||
assert struct['html'] | ||
self.assertTrue('<code>and</code>' in struct['html']) | ||
self.assertTrue( | ||
"<script>alert('xsss')</script>" \ | ||
in struct['html']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
from mongokit import RequireFieldError, ValidationError | ||
import datetime | ||
#import sys; sys.path.insert(0, '..') | ||
from apps.main.tests.base import BaseModelsTestCase | ||
from apps.gists.models import Gist, Comment | ||
#from apps.main.models import User | ||
|
||
class ModelsTestCase(BaseModelsTestCase): | ||
|
||
def setUp(self): | ||
super(ModelsTestCase, self).setUp() | ||
self.con.register([Gist, Comment]) | ||
|
||
|
||
def test_gist(self): | ||
user = self.db.User() | ||
user.login = u'peterbe' | ||
user.save() | ||
|
||
gist = self.db.Gist() | ||
gist.user = user | ||
gist.gist_id = 1 | ||
gist.description = u'Description' | ||
gist.files = [u'foo.py', u'bar.js'] | ||
gist.save() | ||
|
||
assert gist.no_comments == 0 | ||
|
||
def test_comment(self): | ||
user = self.db.User() | ||
user.login = u'peterbe' | ||
user.save() | ||
|
||
gist = self.db.Gist() | ||
gist.user = user | ||
gist.gist_id = 1 | ||
gist.description = u'Description' | ||
gist.files = [u'foo.py', u'bar.js'] | ||
gist.save() | ||
|
||
comment = self.db.Comment() | ||
comment.gist = gist | ||
comment.user = user | ||
comment.comment = u"Works" | ||
comment.comment_format = u"markdown" | ||
comment.file = u'bar.js' | ||
comment.save() | ||
|
||
self.assertEqual(comment.file_index_number, 1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.