Permalink
Browse files

changed tests to fulfill the new requirement 'post visibility'

  • Loading branch information...
1 parent f008147 commit 157b7d4bc7c16e57e62993d4b69876815485499d Eugen committed Sep 1, 2010
Showing with 87 additions and 19 deletions.
  1. +4 −4 TODO
  2. +3 −1 simblin/models.py
  3. +4 −1 test/test_models.py
  4. +76 −13 test/test_views.py
View
8 TODO
@@ -1,6 +1,6 @@
-* Pingback/Traceback (or does Disqus already do that?)
-** inform yourself what that is at all and how to link automatically to linked
- posts in a post
+* add "visible" field to blog posts to allow drafts
+* Posts in Category "Pages" are not shown on normal views
+ * update documentation
* Refactor(pyflakes/epydoc)/Tests/Document/Readme/Changelog
* get community feedback
@@ -20,7 +20,6 @@
* be able to rename categories
* Javascript Tag suggestion
* Put hardcoded Messages in config file (localisation?)
-* add "visible" field to blog posts to allow drafts
* make datetime field explicitly settable, both in the model
and on the compose page through a datetime widget
* set default to now but when updating load saved date
@@ -63,6 +62,7 @@
* use css3 spalten to make archives page more effectively use horizontal space
(e.g. 3 columns for months, 3 columns for categories, tag cloud and then
recent posts)
+* Pingback/Traceback (or does Disqus already do that?) / Look at Zine
* Refactor(pyflakes/epydoc)/Tests/Document/Readme/Changelog
-> v0.9
View
@@ -67,6 +67,7 @@ class Post(db.Model):
_markup = db.Column(db.Text)
_html = db.Column(db.Text)
comments_allowed = db.Column(db.Boolean)
+ visible = db.Column(db.Boolean)
datetime = db.Column(db.DateTime)
# Many to many Post <-> Tag
@@ -77,11 +78,12 @@ class Post(db.Model):
_categories = db.relationship('Category', secondary='post_categories',
backref=db.backref('posts', lazy='dynamic'))
- def __init__(self, title, markup='', comments_allowed=True):
+ def __init__(self, title, markup='', comments_allowed=True, visible=True):
self.title = title
self.markup = markup
self.datetime = datetime.now()
self.comments_allowed = comments_allowed;
+ self.visible = visible;
def _set_title(self, title):
"""Constrain title with slug so slug is never set directly"""
View
@@ -38,16 +38,19 @@ def test_post_creation(self):
assert_equal(post.title, title)
assert_equal(post.markup, markup)
assert_true(post.comments_allowed)
+ assert_true(post.visible)
assert_equal(post.slug, expected_slug)
assert expected_html in post.html
assert_equal(post.datetime.date(), expected_date)
assert_equal(sorted(tag.name for tag in post.tags), sorted(tags))
assert_equal([], post.categories)
# Add another post
- db.session.add(Post(title=title, markup=markup, comments_allowed=False))
+ db.session.add(Post(title=title, markup=markup, comments_allowed=False,
+ visible=False))
db.session.commit()
assert_false(Post.query.get(2).comments_allowed)
+ assert_false(Post.query.get(2).visible)
assert_equal(Post.query.count(), 2)
def test_slug_uniqueness(self):
View
@@ -47,8 +47,8 @@ def logout(self):
"""Helper function to logout"""
return self.client.get('/logout', follow_redirects=True)
- def add_post(self, title, markup='', comments_allowed=None, tags='',
- categories=[]):
+ def add_post(self, title, markup='', comments_allowed=None, visible=None,
+ tags='', categories=[]):
"""Helper functions to create a blog post"""
data=dict(
title=title,
@@ -57,14 +57,16 @@ def add_post(self, title, markup='', comments_allowed=None, tags='',
action='Publish',
)
if comments_allowed is not None:
- data['comments_allowed'] = comments_allowed
+ data['comments_allowed'] = True
+ if visible is not None:
+ data['visible'] = True
# Mimic select form fields
for i, category_id in enumerate(categories):
data['category-%d' % i] = category_id
return self.client.post('/compose', data=data, follow_redirects=True)
- def update_post(self, slug, title, markup, comments_allowed=None, tags=None,
- categories=[]):
+ def update_post(self, slug, title, markup='', comments_allowed=None,
+ visible=None, tags=None, categories=[]):
"""Helper functions to create a blog post"""
data=dict(
title=title,
@@ -73,7 +75,9 @@ def update_post(self, slug, title, markup, comments_allowed=None, tags=None,
action='Update',
)
if comments_allowed is not None:
- data['comments_allowed'] = comments_allowed
+ data['comments_allowed'] = True
+ if visible is not None:
+ data['visible'] = True
# Mimic select form fields
for i, category_id in enumerate(categories):
data['category-%d' % i] = category_id
@@ -189,6 +193,7 @@ def test_creation(self):
assert_equal(post.title, title)
assert_equal(post.markup, markup)
assert_false(post.comments_allowed)
+ assert_false(post.visible)
assert_equal(post.slug, 'my-post')
assert '<h1>Title</h1>' in post.html
assert_equal(post.datetime.date(), datetime.date.today())
@@ -204,11 +209,13 @@ def test_creation(self):
assert_equal(db.session.query(post_categories).count(), 2)
# Add another post
- self.add_post(title=post.title, tags=['django'], comments_allowed=True)
+ self.add_post(title=post.title, tags=['django'], comments_allowed=True,
+ visible=True)
post2 = Post.query.get(2)
assert_equal(post2.title, post.title)
assert_true(post2.comments_allowed)
+ assert_true(post2.visible)
assert_equal(post2.slug, post.slug + '-2')
assert_equal(post2.categories, [])
assert_equal(Tag.query.count(), 3)
@@ -223,12 +230,13 @@ def test_updating(self):
datetime = post.datetime
self.update_post(title='cool', markup='## Title', slug=post.slug,
- tags=['django'], comments_allowed=True)
+ tags=['django'], comments_allowed=True, visible=True)
updated_post = Post.query.get(1)
assert_equal(updated_post.title, 'cool')
assert_equal(updated_post.markup, '## Title')
assert_true(updated_post.comments_allowed)
+ assert_true(updated_post.visible)
assert_equal(updated_post.slug, 'cool')
assert '<h2>Title</h2>' in updated_post.html
assert_equal(updated_post.datetime, datetime)
@@ -275,15 +283,44 @@ def test_deletion(self):
assert_equal(len(posts), 0)
assert_equal(len(tags), 0)
- def test_view(self):
+ def test_singleview(self):
"""Test the displaying of one blog post"""
self.clear_db()
self.register_and_login('barney', 'abc')
- self.add_post(title='Title', markup='', tags='')
+ self.add_post(title='Title', markup='', visible=True)
rv = self.client.get('/post/title')
self.assert_200(rv)
assert 'Title' in rv.data
+
+ self.add_post(title='Title2', visible=None)
+ rv = self.client.get('/post/title2')
+ self.assert_200(rv)
+ assert 'Title2' in rv.data
+
+ self.logout()
+
+ rv = self.client.get('/post/title')
+ self.assert_200(rv)
+ assert 'Title' in rv.data
+
+ rv = self.client.get('/post/title2')
+ self.assert_404(rv)
+
+ def test_multipleview(self):
+ """Test the displaying of multiple blog posts on home page"""
+ self.clear_db()
+ self.register_and_login('barney', 'abc')
+
+ self.add_post(title='Title', markup='', visible=True)
+ self.add_post(title='Title2', visible=None)
+
+ self.logout()
+
+ rv = self.client.get('/')
+ self.assert_200(rv)
+ assert 'Title' in rv.data
+ assert 'Title2' not in rv.data
class TestArchives(ViewTestCase):
@@ -297,7 +334,8 @@ def test_archives_page(self):
def test_month_view(self):
"""Test the displaying of the month view"""
self.clear_db()
- post = Post('the chronic 2001')
+ self.register_and_login('barney', 'abc')
+ post = Post('the chronic 2001', visible=False)
post.datetime = datetime.datetime(1999, 11, 16)
db.session.add(post)
db.session.commit()
@@ -308,45 +346,70 @@ def test_month_view(self):
assert 'No entries here so far' in rv.data
rv = self.client.get('/1999/14/')
self.assert_404(rv)
+
+ self.logout()
+ rv = self.client.get('/1999/11/')
+ self.assert_200(rv)
+ assert 'No entries here so far' in rv.data
class TestTag(ViewTestCase):
def test_view(self):
"""Test the displaying of the tag view"""
self.clear_db()
+ self.register_and_login('barney', 'abc')
tag = Tag('drdre')
db.session.add(tag)
db.session.commit()
- post = Post('the chronic 2001')
+ post = Post('the chronic 2001', visible=True)
+ post2 = Post('the chronic 2002', visible=False)
post._tags = [tag]
+ post2._tags = [tag]
db.session.add(post)
+ db.session.add(post2)
db.session.commit()
rv = self.client.get('/tag/drdre/')
self.assert_200(rv)
assert 'the chronic 2001' in rv.data
rv = self.client.get('/tag/bobbybrown/')
self.assert_404(rv)
+ self.logout()
+ rv = self.client.get('/tag/drdre/')
+ self.assert_200(rv)
+ assert 'the chronic 2001' in rv.data
+ assert 'the chronic 2002' not in rv.data
+
class TestCategory(ViewTestCase):
def test_view(self):
"""Test the displaying of the category view"""
self.clear_db()
+ self.register_and_login('barney', 'abc')
category = Category('drdre')
db.session.add(category)
db.session.commit()
- post = Post('the chronic')
+ post = Post('the chronic', visible=True)
+ post2 = Post('the chrinoc', visible=False)
post._categories = [category]
+ post2._categories = [category]
db.session.add(post)
+ db.session.add(post2)
db.session.commit()
rv = self.client.get('/category/drdre/')
self.assert_200(rv)
assert 'the chronic' in rv.data
rv = self.client.get('/category/sugeknight/')
self.assert_404(rv)
+ self.logout()
+ rv = self.client.get('/category/drdre/')
+ self.assert_200(rv)
+ assert 'the chronic' in rv.data
+ assert 'the chrinoc' not in rv.data
+
rv = self.client.get('/uncategorized/')
self.assert_200(rv)
assert 'Uncategorized posts' in rv.data

0 comments on commit 157b7d4

Please sign in to comment.