示例#1
0
文件: web_ui.py 项目: jier38/TracSite
    def test_new_blog_post(self):
        PermissionSystem(self.env).grant_permission('user', 'BLOG_ADMIN')
        req = MockRequest(self.env,
                          method='POST',
                          path_info='/blog/create',
                          authname='user',
                          args={
                              'name': 'new_post',
                              'title': 'New post',
                              'author': 'user',
                              'body': 'The body',
                              'action': 'new',
                              'blog-save': ''
                          })

        module = FullBlogModule(self.env)
        self.assertTrue(module.match_request(req))
        self.assertRaises(RequestDone, module.process_request, req)
        self.assertEquals('http://example.org/trac.cgi/blog/new_post',
                          req.headers_sent['Location'])
        self.assertEquals([], req.chrome['warnings'])

        posts = get_blog_posts(self.env)
        self.assertEquals(1, len(posts))
        self.assertEquals('New post', posts[0][4])
    def test_new_blog_post(self):
        PermissionSystem(self.env).grant_permission('user', 'BLOG_ADMIN')
        redirects = []

        def redirect(r):
            redirects.append(r)
            raise (RequestDone)

        req = Mock(method='POST',
                   base_path='',
                   cgi_location='',
                   path_info='/blog/create',
                   href=Href('/trac'),
                   args={
                       'name': 'new_post',
                       'title': 'New post',
                       'author': 'admin',
                       'body': 'The body',
                       'action': 'new',
                       'blog-save': ''
                   },
                   chrome={'warnings': []},
                   perm=PermissionCache(self.env, 'user'),
                   authname='admin',
                   redirect=redirect)

        module = FullBlogModule(self.env)
        assert module.match_request(req)
        self.assertRaises(RequestDone, module.process_request, req)
        self.assertEquals(['/trac/blog/new_post'], redirects)
        self.assertEquals([], req.chrome['warnings'])

        posts = get_blog_posts(self.env)
        self.assertEquals(1, len(posts))
        self.assertEquals('New post', posts[0][4])
    def test_single_post(self):
        PermissionSystem(self.env).grant_permission('user', 'BLOG_VIEW')
        bp = BlogPost(self.env, 'first_post')
        bp.update_fields(fields={
            'title': 'First Post',
            'author': 'user',
            'body': 'First body'
        })
        self.assertEquals([], bp.save('user'))
        req = Mock(method='GET',
                   base_path='',
                   cgi_location='',
                   path_info='/blog',
                   href=Href('/trac'),
                   args={},
                   chrome={},
                   perm=PermissionCache(self.env, 'user'),
                   authname='user')

        module = FullBlogModule(self.env)
        assert module.match_request(req)
        template, data, _ = module.process_request(req)

        self.assertEqual(1, data['blog_total'])
        self.assertEqual(1, len(data['blog_post_list']))
        self.assertEqual('First Post', data['blog_post_list'][0].title)
示例#4
0
文件: web_ui.py 项目: jier38/TracSite
 def test_no_permission(self):
     req = MockRequest(self.env,
                       method='GET',
                       path_info='/blog',
                       authname='user')
     module = FullBlogModule(self.env)
     self.assertTrue(module.match_request(req))
     self.assertRaises(PermissionError, module.process_request, req)
示例#5
0
文件: web_ui.py 项目: jier38/TracSite
    def test_rss_no_posts(self):
        PermissionSystem(self.env).grant_permission('user', 'BLOG_VIEW')
        req = MockRequest(self.env,
                          method='GET',
                          path_info='/blog',
                          authname='user',
                          args={'format': 'rss'})

        module = FullBlogModule(self.env)
        self.assertTrue(module.match_request(req))
        template, data, _ = module.process_request(req)

        self.assertEquals('fullblog.rss', template)
示例#6
0
文件: web_ui.py 项目: jier38/TracSite
    def test_no_posts(self):
        PermissionSystem(self.env).grant_permission('user', 'BLOG_VIEW')
        req = MockRequest(self.env,
                          method='GET',
                          path_info='/blog',
                          authname='user')

        module = FullBlogModule(self.env)
        self.assertTrue(module.match_request(req))
        template, data, _ = module.process_request(req)

        self.assertEquals('fullblog_view.html', template)
        self.assertEqual([], data['blog_post_list'])
 def test_no_permission(self):
     req = Mock(method='GET',
                base_path='',
                cgi_location='',
                path_info='/blog',
                href=Href('/trac'),
                args={},
                chrome={},
                perm=PermissionCache(self.env, 'user'),
                authname='user')
     module = FullBlogModule(self.env)
     assert module.match_request(req)
     self.assertRaises(PermissionError, module.process_request, req)
    def test_rss_no_posts(self):
        PermissionSystem(self.env).grant_permission('user', 'BLOG_VIEW')
        req = Mock(method='GET',
                   base_path='',
                   cgi_location='',
                   path_info='/blog',
                   href=Href('/trac'),
                   abs_href=Href('http://domain/trac'),
                   args={'format': 'rss'},
                   chrome={},
                   perm=PermissionCache(self.env, 'user'),
                   authname='user')

        module = FullBlogModule(self.env)
        assert module.match_request(req)
        template, data, _ = module.process_request(req)

        self.assertEquals('fullblog.rss', template)
    def test_no_posts(self):
        PermissionSystem(self.env).grant_permission('user', 'BLOG_VIEW')
        req = Mock(method='GET',
                   base_path='',
                   cgi_location='',
                   path_info='/blog',
                   href=Href('/trac'),
                   args={},
                   chrome={},
                   perm=PermissionCache(self.env, 'user'),
                   authname='user')

        module = FullBlogModule(self.env)
        assert module.match_request(req)
        template, data, _ = module.process_request(req)

        self.assertEquals('fullblog_view.html', template)
        self.assertEqual([], data['blog_post_list'])
示例#10
0
文件: web_ui.py 项目: jier38/TracSite
    def test_single_post(self):
        PermissionSystem(self.env).grant_permission('user', 'BLOG_VIEW')
        bp = BlogPost(self.env, 'first_post')
        bp.update_fields(fields={
            'title': 'First Post',
            'author': 'user',
            'body': 'First body'
        })
        self.assertEquals([], bp.save('user'))
        req = MockRequest(self.env,
                          method='GET',
                          path_info='/blog',
                          authname='user')

        module = FullBlogModule(self.env)
        self.assertTrue(module.match_request(req))
        template, data, _ = module.process_request(req)

        self.assertEqual(1, data['blog_total'])
        self.assertEqual(1, len(data['blog_post_list']))
        self.assertEqual('First Post', data['blog_post_list'][0].title)