Пример #1
0
    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))
Пример #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))
Пример #3
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))
Пример #4
0
    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))
Пример #5
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))
Пример #6
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)
Пример #7
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)
Пример #8
0
    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()
        
        # Initially No Slug or pub_date should be assigned.
        self.failUnlessEqual(post1.slug, None, 'Post1 slug was %s when it should be None' % post1.slug)
        self.failUnless(not post1.pub_date, 'PubDate is not Null!')

        # Publishing it should give it a slug and pub_date automatically.
        post1.status = '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!')
 
        # Set the pub_date back to setup next test.
        new_date = datetime.now() - timedelta(days=1) - timedelta(hours=2)
        post1.pub_date = new_date
        post1.save()
        
        # Setup another post with old pubdate, then change to now to see what happens.
        # Test some slug collisions and such.
        p2 = p.copy()
        p2['status'] = 'P'
        post2 = Post(**p2)
        post2.save()
        
        # Test the slugify feature
        slug = 'test-title-1' 
        self.failUnlessEqual(slug, post2.slug, 'Post2 slug was %s but expected %s' % (post2.slug, slug))
 
        # Now change the pub_date to match p1 and see if it throws a validation error.
        post2.pub_date = datetime.now() - timedelta(days=1) - timedelta(hours=1)
        self.assertRaises(ValidationError, post2.save)
        
        # Test the auto-increment feature of the unique_slugify method.
        post2.slug = None
        post2.save()
        expected = 'test-title-1-2'
        self.failUnlessEqual(post2.slug, expected, 'Post2 slug was %s but expected %s' % (post2.slug, expected))
Пример #9
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