Ejemplo n.º 1
0
    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))
Ejemplo n.º 2
0
    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))
Ejemplo n.º 3
0
 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':
         post = Post()
         post.author = self.get_author()
         post.title = item.find('title').text
         if not post.title:
             post.title = 'ab origine' # Latin for 'from the source'
         post.content = item.find(content_ns + 'encoded').text
         if post.content:
             post.content = post.content.replace("\n", "<br />")
         post.teaser = item.find(self.excerpt_ns + 'encoded').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)
 
         except:
             sys.stderr.write("Error importing %s" % post.title)
             pass
Ejemplo n.º 4
0
    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)
Ejemplo n.º 5
0
    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)
Ejemplo n.º 6
0
    def test_published(self):
        '''Tests that only published posts are returned.'''
        actual = Post.objects.all().count()
        expected = 4 # 3 total posts of all status
        self.failUnlessEqual(expected, actual, 'Expected %s posts and returned %s!' % (expected, actual))

        actual = Post.objects.published().count()
        expected = 2 # Only one 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.published().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.published().count()
        expected = 2 # Should now be 1 with postdated pub_date.
        self.failUnlessEqual(expected, actual, 'Expected %s posts and returned %s!' % (expected, actual))