def test_save(self): """Tests the custom save method.""" user = User(username='******', password='******', email='*****@*****.**') user.save() user2 = User(username='******', password='******', email='*****@*****.**') user2.save() p = { 'title': 'Test Title (1)', 'author': user, 'content': 'some content', 'status': 'U' } post1 = Post(**p) post1.save() slugexp = 'test-title-1' slugact = post1.slug self.failUnlessEqual(slugexp, slugact, 'Slug was %s but expected %s' % (slugact, slugact)) self.failUnless(post1.pub_date, 'Post1 pub_date was not set!') # Test some slug collisions and such. p2 = p.copy() p2['status'] = 'P' post2 = Post(**p2) post2.save() expected = 'test-title-1-2' self.failUnlessEqual(post2.slug, expected, 'Post2 slug was %s but expected %s' % (post2.slug, expected))
def test_published(self): '''Tests that only published posts are returned.''' actual = Post.objects.raw().count() expected = 4 # 4 total posts of all status self.failUnlessEqual(expected, actual, 'Expected %s posts and returned %s!' % (expected, actual)) actual = Post.objects.all().count() expected = 2 # 2 are actually published. self.failUnlessEqual(expected, actual, 'Expected %s posts and returned %s!' % (expected, actual)) # Create a new post with a future publish date p = Post(title='test', content='test', status='P') p.author = self.author p.save() actual = Post.objects.all().count() expected = 3 # Pubdate defaults to now. self.failUnlessEqual(expected, actual, 'Expected %s posts and returned %s!' % (expected, actual)) p.pub_date = datetime.now() + timedelta(days=1) p.save() actual = Post.objects.all().count() expected = 2 # Should now be 1 with postdated pub_date. self.failUnlessEqual(expected, actual, 'Expected %s posts and returned %s!' % (expected, actual)) # Test alt filters to ensure they only return published posts. actual = Post.objects.filter(title__isnull=False).count() expected = 2 # 4 total posts of all status self.failUnlessEqual(expected, actual, 'Expected %s posts and returned %s!' % (expected, actual))
def _import_post(self, item): '''Creates a new Entry object from a post and saves it.''' wp_ns = self.wp_ns content_ns = self.content_ns if item.find(wp_ns + 'post_type').text == 'post': # These methods are only for scrubbing my crappy content. # @TODO remove after I run on my blog. item_title = item.find('title').text item_content = item.find(content_ns + 'encoded').text if item_title and re.search('From Twitter ', item_title): print "Skipping tittinisis post %s" % item_title return True # @TODO remove after I run on my blog. if item_content and re.search('LoudTwitter', item_content): print "Skipping loudtwitter post %s" % item.find('title').text return True post = Post() post.author = self.get_author() post.title = item_title if post.title and len(post.title) > 75: post.title = post.title[:75] if not post.title: post.title = 'ab origine' # Latin for 'from the source' post.content = item_content if post.content: post.content = post.content.replace("\n", "<br />") excerpt = item.find(self.excerpt_ns + 'encoded') if excerpt: post.teaser = excerpt.text # Parse wp:post_date in format 2002-02-27 13:39:00 postdate = datetime.strptime( item.find(wp_ns + 'post_date').text, "%Y-%m-%d %H:%M:%S") post.pub_date = postdate status = item.find(wp_ns + 'status').text if status == 'publish': post.status = 'P' else: post.status = 'U' #try: post.save() # modify date_created after save because autonow is on. post.date_created = postdate post.save() # Enrich the rest of the post. self._post_meta(post, item) self._catalog_post(post, item)