Exemplo n.º 1
0
    def test_blog_posts(self):
        """Posts from the launchpad blog are shown when feature is enabled"""
        self.useFixture(FeatureFixture({'app.root_blog.enabled': True}))
        posts = [
            self._make_blog_post(1, "A post", "Post contents.", "2002"),
            self._make_blog_post(2, "Another post", "More contents.", "2003"),
        ]
        calls = []

        def _get_blog_posts():
            calls.append('called')
            return posts

        root = getUtility(ILaunchpadRoot)
        with anonymous_logged_in():
            view = create_initialized_view(root, 'index.html')
            view.getRecentBlogPosts = _get_blog_posts
            result = view()
        markup = BeautifulSoup(
            result, parse_only=SoupStrainer(id='homepage-blogposts'))
        self.assertEqual(['called'], calls)
        items = markup.findAll('li', 'news')
        # Notice about launchpad being opened is always added at the end
        self.assertEqual(3, len(items))
        a = items[-1].find("a")
        self.assertEqual("Launchpad now open source", a.string.strip())
        for post, item in zip(posts, items):
            a = item.find("a")
            self.assertEqual(post['link'], a["href"])
            self.assertEqual(post['title'], a.string)
Exemplo n.º 2
0
 def test_job_notifications_display_multiple_is_capped(self):
     jobs = [self.makeJob('package%d' % i) for i in range(7)]
     with person_logged_in(self.archive.owner):
         view = create_initialized_view(self.archive,
                                        "+packages",
                                        principal=self.archive.owner)
         soup = BeautifulSoup(view.render())
     self.assertEqual([],
                      soup.findAll('div',
                                   attrs={
                                       'class': 'pending-job',
                                       'job_id': jobs[-1].id
                                   }))
     showing_tags = soup.find_all('span', text=re.compile('Showing 5 of .'))
     self.assertEqual(['Showing 5 of 7'],
                      [tag.string for tag in showing_tags])
Exemplo n.º 3
0
    def test_blog_posts_with_memcache(self):
        self.useFixture(FeatureFixture({'app.root_blog.enabled': True}))
        posts = [
            self._make_blog_post(1, "A post", "Post contents.", "2002"),
            self._make_blog_post(2, "Another post", "More contents.", "2003"),
        ]
        key = '%s:homepage-blog-posts' % config.instance_name
        getUtility(IMemcacheClient).set(key, posts)

        root = getUtility(ILaunchpadRoot)
        with anonymous_logged_in():
            view = create_initialized_view(root, 'index.html')
            result = view()
        markup = BeautifulSoup(
            result, parse_only=SoupStrainer(id='homepage-blogposts'))
        items = markup.findAll('li', 'news')
        self.assertEqual(3, len(items))