def test_delete_post(): tearDown() author = create_author(db) l = Lense(name = 'facebook', subdomain=SUBDOMAIN, db=db, author=author).save() assert len(l.feed.entries) == 0 assert len(author.feed.entries) == 0 post = Post(content='test this out', title='super awesome title', author = author, prefix=l.feed.url, db=db, lense=l).save() l.update() author.update() assert len(l.feed.entries) == 1 assert len(author.feed.entries) == 1 post.delete() l.update() author.update() assert len(l.feed.entries) == 0 assert len(author.feed.entries) == 0
def test_delete_post(): tearDown() author = create_author(db) l = Lense(name='facebook', subdomain=SUBDOMAIN, db=db, author=author).save() assert len(l.feed.entries) == 0 assert len(author.feed.entries) == 0 post = Post(content='test this out', title='super awesome title', author=author, prefix=l.feed.url, db=db, lense=l).save() l.update() author.update() assert len(l.feed.entries) == 1 assert len(author.feed.entries) == 1 post.delete() l.update() author.update() assert len(l.feed.entries) == 0 assert len(author.feed.entries) == 0
def test_post_title(): content = 'sweet content right here' title = 'awesome title' post = Post(content, prefix=prefix, author=author) assert post.title == '' post = Post(content, prefix=prefix, title=title, author=author) assert post.title == title
def test_post_filename(): content = 'some stuff in here' title = 'this is awesome' post = Post(content, prefix=prefix, author=author) expected = urllib.pathname2url( hashlib.sha256(content + post.meta['date']).digest()) assert post.filename == expected, 'filename is %s expected %s' % ( post.filename, expected) post = Post(content, prefix=prefix, title=title, author=author) assert post.filename == urllib.pathname2url(title.replace(' ', '-'))
def test_load_from_db(): ''' Make sure we can save and rehydrate a post instance from the database. ''' post = Post(content='test this out', title='super awesome title', author=author, prefix=prefix, db=db) post.save() saved = Post(db=db).load(post.url + '.json') assert saved == post
def test_post_save(): ''' saving a post should: 1. update feeds (tested in feed test module) 2. create a json entry at the url 3. create an html fragment entry at the url.html ''' content = 'check it' post = Post(content=content, prefix=prefix, db=db, author=author) post.save() newpost = Post(db=db).load(post.url + '.json') assert newpost == post assert post.fragment == db.get(post.url + '.html')
def test_load_from_db(): ''' Make sure we can save and rehydrate a post instance from the database. ''' post = Post(content='test this out', title='super awesome title', author = author, prefix=prefix, db=db) post.save() saved = Post(db=db).load(post.url + '.json') assert saved == post
def test_delete_feed(): f = Feed(url=prefix, author=author, db=db) p = Post('test this out', prefix=prefix, author=author, db=db).save() f.add_post(p) f.delete() assert_raises(Exception, db.get, f.url) assert_raises(Exception, db.get, p.url)
def test_bad_markdown(): ''' Make sure bad markup is removed. ''' post = Post('<script>alert("evil!")</script><p>cool beans</p>', db=db) expected = '<p>alert("evil!")</p><p>cool beans</p><p></p>' assert post.fragment == expected, 'cleansed fragment was %s expected %s' % ( post.fragment, expected)
def test_delete_post(): f = Feed(title='facebook', url=prefix, author=author, db=db) p = Post('test this out', prefix=prefix, author=author) f.add_post(p) assert len(f.entries) == 1 f.remove_post(p.url) assert len(f.entries) == 0 assert_raises(Exception, f.remove_post, p.url)
def test_new_post_updates(): #creating a new post updates lense #feed and author feed lense = test_create_lense() assert len(lense.feed.entries) == 0 assert len(lense.author.feed.entries) == 0 post = Post('test this shit out', prefix='/sean/public/%s/posts' % lense.name, author=lense.author, lense=lense) post.save(db=db) lense.update() assert len(lense.feed.entries) == 1 assert len(lense.author.feed.entries) == 1 post.delete() lense.update() assert len(lense.feed.entries) == 0 assert len(lense.author.feed.entries) == 0
def test_post_url(): content = 'this is a short post' ordinal = 734845 date = dt.fromordinal(ordinal) post = Post(content, prefix='sean', date=date, author=author) expected = 'sean/12/8/2012/' + urllib.pathname2url( hashlib.sha256(content + post.meta['date']).digest()) assert post.url == expected, 'url was %s expected %s' % (post.url, expected)
def test_post_json(): ''' Make sure json is in a format we expect. ''' content = 'check it' post = Post(content=content, title='title here', author=author, prefix=prefix) meta = json.loads(post.json) for key, value in meta.items(): assert post.meta[ key] == value, 'meta value for %s was %s expected %s.' % ( key, meta[key], value)
def test_feed_json(): now = dt.now() f = create_feed(now=now) p = Post('test this out\nright now') f.add_post(p) obj = json.loads(f.json) assert obj['title'] == 'pics' assert len(obj['links']) == 2 assert obj['links'][0]['href'] == 'http://www.google.com' assert obj['updated'] == strftime('%Y-%m-%d %H:%M:%S', now.utctimetuple()) assert len(obj['entries']) == 1 entry = obj['entries'][0] assert entry.has_key('title') assert len(entry['title']) == 0 assert entry['link'] == p.url assert entry['updated'] == strftime('%Y-%m-%d %H:%M:%S', p.date.utctimetuple()) assert obj['author']['subdomain'] == 'potter' assert obj['author']['email'] == '*****@*****.**'
def test_delete_author(): author = create_author(db) af = author.feed l = Lense(name='facebook', subdomain=SUBDOMAIN, db=db, author=author).save() post = Post(content='test this out', title='super awesome title', author=author, prefix=l.feed.url, db=db, lense=l).save() l.update() author.update() assert len(l.feed.entries) == 1 assert len(author.feed.entries) == 1 author.delete() assert_raises(Exception, db.get, author.url) assert_raises(Exception, db.get, l.url) assert_raises(Exception, db.get, post.url) assert_raises(Exception, db.get, af.url)
def test_add_post(): f = Feed(url=prefix, author=author, db=db) assert len(f.entries) == 0 f.add_post(Post('test this out', prefix=prefix, author=author)) assert len(f.entries) == 1