Exemplo n.º 1
0
 def test_upate(self):
     self.add_mess()
     rec = MWiki.get_by_wiki(self.wiki_title)
     p_d = {
         'title': 'bibibobo',
         'cnt_md': 'dd25d5fd6d',
         }
     MWiki.update(self.uid,p_d)
     now=MWiki.get_by_wiki(p_d['title'])
     assert rec.uid==now.uid
     assert now.uid==self.uid
     self.tearDown()
Exemplo n.º 2
0
    def test_upate_by_view_count(self):
        self.add_mess()
        rec = MWiki.get_by_wiki(self.wiki_title)

        viewcount0 = rec.view_count
        assert viewcount0 >= 2
        for x in range(100):
            MWiki.update_view_count_by_uid(rec.uid)

        viewcount1 = MWiki.get_by_wiki(self.wiki_title).view_count
        assert viewcount1 >= 103

        self.tearDown()
Exemplo n.º 3
0
    def add(self, title=''):
        '''
        Add wiki
        '''

        post_data = self.get_post_data()

        if title == '':
            pass
        else:
            post_data['title'] = title

        post_data['user_name'] = self.get_current_user()

        if len(post_data['title'].strip()) < 2:
            kwd = {
                'info': 'Title cannot be less than 2 characters',
                'link': '/'
            }
            self.render('misc/html/404.html', userinfo=self.userinfo, kwd=kwd)

        if MWiki.get_by_wiki(post_data['title']):
            pass
        else:
            MWiki.create_wiki(post_data)

        tornado.ioloop.IOLoop.instance().add_callback(self.cele_gen_whoosh)
        # cele_gen_whoosh.delay()

        self.redirect('/wiki/{0}'.format(
            tornado.escape.url_escape(post_data['title'])))
Exemplo n.º 4
0
 def add_wiki(self):
     p_d = {
         'title': self.title,
         'cnt_md': '## adslkfjasdf\n lasdfkjsadf',
         'user_name': self.username,
     }
     MWiki.create_wiki(p_d)
     aa = MWiki.get_by_wiki(self.title)
     self.wiki_uid = aa.uid
Exemplo n.º 5
0
 def view_or_add(self, title):
     postinfo = MWiki.get_by_wiki(title)
     if postinfo:
         if postinfo.kind == self.kind:
             self.view(postinfo)
         else:
             return False
     else:
         self.to_add(title)
Exemplo n.º 6
0
    def test_upate_by_view_count(self):

        post_data = {
            'title': self.wiki_title,
            'cnt_md': '## adslkfjasdf\n lasdfkjsadf',
            'user_name': 'Tome',
        }
        if MWiki.create_wiki(post_data):

            rec = MWiki.get_by_wiki(self.wiki_title)

            viewcount0 = rec.view_count
            assert viewcount0 == 2
            for x in range(100):
                MWiki.update_view_count_by_uid(rec.uid)

            viewcount1 = MWiki.get_by_wiki(self.wiki_title).view_count
            assert viewcount1 == 103
Exemplo n.º 7
0
    def test_insert(self):
        raw_count = MWiki.get_counts()
        self.add_mess()
        new_count = MWiki.get_counts()

        tt = MWiki.get_by_wiki(self.wiki_title)

        assert tt.title == self.wiki_title
        assert raw_count + 1 <= new_count
        self.tearDown()
Exemplo n.º 8
0
    def add_mess(self,**kwargs):
        p_d = {
            'title': self.wiki_title,
            'cnt_md': '## adslkfjasdf\n lasdfkjsadf',
            'user_name': 'Tome',

        }
        MWiki.create_wiki(p_d)
        aa = MWiki.get_by_wiki(self.wiki_title)
        self.uid = aa.uid
Exemplo n.º 9
0
 def view_or_add(self, title):
     '''
     To judge if there is a post of the title.
     Then, to show, or to add.
     '''
     postinfo = MWiki.get_by_wiki(title)
     if postinfo:
         if postinfo.kind == self.kind:
             self.view(postinfo)
         else:
             return False
     else:
         self.to_add(title)
Exemplo n.º 10
0
    def test_insert(self):
        raw_count = MWiki.get_counts()
        post_data = {
            'title': self.wiki_title,
            'cnt_md': '## adslkfjasdf\n lasdfkjsadf',
            'user_name': 'Tome',
        }
        if MWiki.create_wiki(post_data):
            new_count = MWiki.get_counts()

            tt = MWiki.get_by_wiki(self.wiki_title)

            assert tt.title == post_data['title']
            assert tt.cnt_md == tornado.escape.xhtml_unescape(post_data['cnt_md'])
            assert raw_count + 1 == new_count
Exemplo n.º 11
0
    def add(self, title=''):
        '''
        Add wiki
        '''

        post_data = self.get_post_data()

        if title == '':
            pass
        else:
            post_data['title'] = title
        post_data['user_name'] = self.get_current_user()
        if MWiki.get_by_wiki(post_data['title']):
            pass
        else:
            MWiki.create_wiki(post_data)

        tornado.ioloop.IOLoop.instance().add_callback(self.cele_gen_whoosh)
        # cele_gen_whoosh.delay()

        self.redirect('/wiki/{0}'.format(tornado.escape.url_escape(post_data['title'])))
Exemplo n.º 12
0
 def tearDown(self):
     print ("function teardown")
     tt = MWiki.get_by_wiki(self.wiki_title)
     if tt:
         MWiki.delete(tt.uid)
Exemplo n.º 13
0
class WikiHandler(BaseHandler):
    def initialize(self):
        self.init()
        self.mwiki = MWiki()
        self.mwiki_hist = MWikiHist()

    def get(self, url_str=''):
        url_arr = self.parse_url(url_str)

        if url_str == 'recent':
            self.recent()
        elif url_arr[0] == 'ajax_count_plus':
            self.ajax_count_plus(url_arr[1])
        elif url_str == 'refresh':
            self.refresh()
        elif url_arr[0] == 'edit':
            self.to_modify(url_arr[1])
        elif len(url_arr) == 1:
            self.wiki(url_str)
        else:
            kwd = {
                'info': '页面未找到',
            }
            self.render('html/404.html', kwd=kwd)

    def post(self, url_str=''):
        url_arr = self.parse_url(url_str)
        if url_arr[0] == 'edit':
            self.update(url_arr[1])
        elif url_arr[0] == 'add':
            self.wikinsert()
        else:
            self.redirect('html/404.html')

    def recent(self):
        kwd = {
            'pager': '',
            'unescape': tornado.escape.xhtml_unescape,
            'title': '最近文档',
        }
        self.render(
            'doc/wiki/wiki_list.html',
            view=self.mwiki.query_recent(),
            format_date=tools.format_date,
            cfg=config.cfg,
            kwd=kwd,
            userinfo=self.userinfo,
        )

    def refresh(self):
        kwd = {
            'pager': '',
            'unescape': tornado.escape.xhtml_unescape,
            'title': '最近文档',
        }
        self.render(
            'doc/wiki/wiki_list.html',
            view=self.mwiki.query_dated(16),
            format_date=tools.format_date,
            kwd=kwd,
            cfg=config.cfg,
            userinfo=self.userinfo,
        )

    def wiki(self, title):
        dbdate = self.mwiki.get_by_wiki(title)
        if dbdate:
            self.viewit(dbdate)
        else:
            self.to_add(title)

    @tornado.web.authenticated
    def to_add(self, title):
        if self.check_doc_priv(self.userinfo)['ADD']:
            pass
        else:
            return False

        kwd = {
            'title': title,
            'pager': '',
        }
        self.render(
            'doc/wiki/wiki_add.html',
            kwd=kwd,
            cfg=config.cfg,
            userinfo=self.userinfo,
        )

    @tornado.web.authenticated
    def update(self, uid):

        raw_data = self.mwiki.get_by_id(uid)
        if self.check_doc_priv(
                self.userinfo
        )['EDIT'] or raw_data.user_name == self.get_current_user():
            pass
        else:
            return False
        post_data = {}
        for key in self.request.arguments:
            post_data[key] = self.get_arguments(key)
        post_data['user_name'] = self.get_current_user()
        self.mwiki.update(uid, post_data)
        self.mwiki_hist.insert_data(raw_data)
        self.redirect('/wiki/{0}'.format(
            tornado.escape.url_escape(post_data['title'][0])))

    @tornado.web.authenticated
    def to_modify(self, id_rec):
        wiki_rec = self.mwiki.get_by_id(id_rec)
        # 用户具有管理权限,或文章是用户自己发布的。
        if self.check_doc_priv(
                self.userinfo
        )['EDIT'] or wiki_rec.user_name == self.get_current_user():
            pass
        else:
            return False

        kwd = {
            'pager': '',
        }
        self.render(
            'doc/wiki/wiki_edit.html',
            kwd=kwd,
            unescape=tornado.escape.xhtml_unescape,
            dbrec=wiki_rec,
            cfg=config.cfg,
            userinfo=self.userinfo,
        )

    def viewit(self, view):
        kwd = {
            'pager': '',
            'editable': self.editable(),
        }
        self.render(
            'doc/wiki/wiki_view.html',
            view=view,
            unescape=tornado.escape.xhtml_unescape,
            kwd=kwd,
            userinfo=self.userinfo,
            cfg=config.cfg,
        )

    def ajax_count_plus(self, slug):
        output = {
            'status': 1 if self.mwiki.update_view_count(slug) else 0,
        }

        return json.dump(output, self)

    @tornado.web.authenticated
    def wikinsert(self):
        if self.check_doc_priv(self.userinfo)['ADD']:
            pass
        else:
            return False
        post_data = {}
        for key in self.request.arguments:
            post_data[key] = self.get_arguments(key)

        post_data['user_name'] = self.get_current_user()
        if self.mwiki.get_by_wiki(post_data['title'][0]):
            pass
        else:
            self.mwiki.insert_data(post_data)

        self.redirect('/wiki/{0}'.format(
            tornado.escape.url_escape(post_data['title'][0])))
Exemplo n.º 14
0
class TestWiki():
    def setup(self):
        print('setup 方法执行于本类中每条用例之前')
        self.uu = MWiki()
        self.raw_count = self.uu.get_counts()
        self.wiki_title = 'lkablkjcdefg'

    def test_insert(self):
        raw_count = self.uu.get_counts()
        post_data = {
            'title': self.wiki_title,
            'cnt_md': '## adslkfjasdf\n lasdfkjsadf',
            'user_name': 'Tome',
        }
        if self.uu.insert_data(post_data):
            new_count = self.uu.get_counts()

            tt = self.uu.get_by_wiki(self.wiki_title)

            assert tt.title == post_data['title']
            assert tt.cnt_md == tornado.escape.xhtml_unescape(
                post_data['cnt_md'])
            assert raw_count + 1 == new_count

    def test_insert_2(self):
        '''Wiki insert: Test invalid title'''
        post_data = {
            'title': '',
            'cnt_md': '## adslkfjasdf\n lasdfkjsadf',
            'user_name': 'Tome',
        }
        uu = self.uu.insert_data(post_data)
        assert uu == False

        post_data = {
            'title': '1',
            'cnt_md': '## adslkfjasdf\n lasdfkjsadf',
            'user_name': 'Tome',
        }
        uu = self.uu.insert_data(post_data)
        assert uu == False

        post_data = {
            'title': '天',
            'cnt_md': '## adslkfjasdf\n lasdfkjsadf',
            'user_name': 'Tome',
        }
        uu = self.uu.insert_data(post_data)
        assert uu == False

    def test_get_by_title(self):
        post_data = {
            'title': self.wiki_title,
            'cnt_md': '## adslkfjasdf\n lasdfkjsadf',
            'user_name': 'Tome',
        }
        uid = self.uu.insert_data(post_data)

        ss = self.uu.get_by_uid(uid)
        assert ss.title == post_data['title']

        tt = self.uu.get_by_title(self.wiki_title)
        assert tt.title == post_data['title']

    def test_get_by_title2(self):
        '''Test Wiki title with SPACE'''
        post_data = {
            'title': '  ' + self.wiki_title + '  ',
            'cnt_md': '## adslkfjasdf\n lasdfkjsadf',
            'user_name': 'Tome',
        }
        uid = self.uu.insert_data(post_data)

        ss = self.uu.get_by_uid(uid)
        assert ss.title == self.wiki_title

        tt = self.uu.get_by_title(self.wiki_title)
        assert tt.title == post_data['title'].strip()

    def test_upate_by_view_count(self):

        post_data = {
            'title': self.wiki_title,
            'cnt_md': '## adslkfjasdf\n lasdfkjsadf',
            'user_name': 'Tome',
        }
        if self.uu.insert_data(post_data):

            rec = self.uu.get_by_wiki(self.wiki_title)

            viewcount0 = rec.view_count
            assert viewcount0 == 2
            for x in range(100):
                self.uu.update_view_count_by_uid(rec.uid)

            viewcount1 = self.uu.get_by_wiki(self.wiki_title).view_count
            assert viewcount1 == 103

    def test_upate(self):
        assert True

    def tearDown(self):
        print("function teardown")
        tt = self.uu.get_by_wiki(self.wiki_title)
        if tt:
            self.uu.delete(tt.uid)
Exemplo n.º 15
0
 def test_get_by_wiki(self):
     self.add_mess()
     aa = MWiki.get_by_wiki(self.wiki_title)
     assert aa.uid == self.uid
     self.tearDown()
Exemplo n.º 16
0
class WikiHandler(BaseHandler):
    def initialize(self):
        self.init()
        self.mwiki = MWiki()
        self.mwiki_hist = MWikiHist()
        self.kind = '1'

    def get(self, url_str=''):
        url_arr = self.parse_url(url_str)

        if url_str == 'recent':
            self.recent()
        elif url_arr[0] == 'ajax_count_plus':
            self.ajax_count_plus(url_arr[1])
        elif url_str == 'refresh':
            self.refresh()
        elif url_arr[0] == 'edit':
            self.to_modify(url_arr[1])
        elif len(url_arr) == 1:
            self.wiki(url_str)
        else:
            kwd = {
                'info': '页面未找到',
            }
            self.render('html/404.html', kwd=kwd)

    def post(self, url_str=''):
        url_arr = self.parse_url(url_str)
        if url_arr[0] == 'edit':
            self.update(url_arr[1])
        elif url_arr[0] == 'add':
            self.wikinsert()
        else:
            self.redirect('html/404.html')

    def recent(self):
        kwd = {
            'pager': '',
            'unescape': tornado.escape.xhtml_unescape,
            'title': '最近文档',
        }
        self.render(
            'doc/wiki/wiki_list.html',
            view=self.mwiki.query_recent(),
            format_date=tools.format_date,
            # cfg=cfg, # Todo: Should delete.
            kwd=kwd,
            userinfo=self.userinfo,
        )

    def refresh(self):
        kwd = {
            'pager': '',
            'unescape': tornado.escape.xhtml_unescape,
            'title': '最近文档',
        }
        self.render(
            'doc/wiki/wiki_list.html',
            view=self.mwiki.query_dated(16),
            format_date=tools.format_date,
            kwd=kwd,
            # cfg=cfg, # Todo: Should delete
            userinfo=self.userinfo,
        )

    def wiki(self, title):
        postinfo = self.mwiki.get_by_wiki(title)
        if postinfo:
            if postinfo.kind == self.kind:
                self.viewit(postinfo)
            else:
                return False
        else:
            self.to_add(title)

    @tornado.web.authenticated
    def update(self, uid):

        raw_data = self.mwiki.get_by_id(uid)
        if self.check_post_role(
                self.userinfo
        )['EDIT'] or raw_data.user_name == self.get_current_user():
            pass
        else:
            return False
        post_data = self.get_post_data()

        post_data['user_name'] = self.get_current_user()
        self.mwiki.update(uid, post_data)
        self.mwiki_hist.insert_data(raw_data)
        self.redirect('/wiki/{0}'.format(
            tornado.escape.url_escape(post_data['title'])))

    @tornado.web.authenticated
    def to_modify(self, id_rec):
        wiki_rec = self.mwiki.get_by_id(id_rec)
        # 用户具有管理权限,或文章是用户自己发布的。
        if self.check_post_role(
                self.userinfo
        )['EDIT'] or wiki_rec.user_name == self.get_current_user():
            pass
        else:
            return False

        kwd = {
            'pager': '',
        }
        self.render(
            'doc/wiki/wiki_edit.html',
            kwd=kwd,
            unescape=tornado.escape.xhtml_unescape,
            dbrec=wiki_rec,  # Deprecated.
            postinfo=wiki_rec,
            # cfg=cfg, # Todo: Should delete
            userinfo=self.userinfo,
        )

    def viewit(self, view):
        kwd = {
            'pager': '',
            'editable': self.editable(),
        }
        self.render(
            'doc/wiki/wiki_view.html',
            view=view,  # Deprecated
            postinfo=view,
            unescape=tornado.escape.xhtml_unescape,
            kwd=kwd,
            userinfo=self.userinfo,
            # cfg=cfg, # Todo: Should delete
        )

    def ajax_count_plus(self, slug):
        output = {
            'status': 1 if self.mwiki.update_view_count(slug) else 0,
        }

        return json.dump(output, self)

    def to_add(self, title):
        kwd = {
            'title': title,
            'pager': '',
        }
        if self.userinfo and self.userinfo.role[0] > '0':
            tmpl = 'doc/wiki/wiki_add.html'
        else:
            tmpl = 'doc/wiki/wiki_login.html'

        self.render(
            tmpl,
            kwd=kwd,
            # cfg= cfg, # Todo: should delete
            userinfo=self.userinfo,
        )

    @tornado.web.authenticated
    def wikinsert(self):
        if self.userinfo.role[0] > '0':
            pass
        else:
            return False

        post_data = self.get_post_data()

        post_data['user_name'] = self.get_current_user()
        if self.mwiki.get_by_wiki(post_data['title']):
            pass
        else:
            self.mwiki.insert_data(post_data)

        self.redirect('/wiki/{0}'.format(
            tornado.escape.url_escape(post_data['title'])))