예제 #1
0
    def list(self, kind, tag_slug, cur_p=''):
        '''
        根据 cat_handler.py 中的 def view_cat_new(self, cat_slug, cur_p = '')
        '''
        # 下面用来使用关键字过滤信息,如果网站信息量不是很大不要开启
        # Todo:
        # if self.get_current_user():
        #     redisvr.sadd(config.redis_kw + self.userinfo.user_name, tag_slug)

        if cur_p == '':
            current_page_number = 1
        else:
            try:
                current_page_number = int(cur_p)
            except TypeError:
                current_page_number = 1
            except Exception as err:
                print(err.args)
                print(str(err))
                print(repr(err))

        current_page_number = 1 if current_page_number < 1 else current_page_number

        pager_num = int(
            MPost2Label.total_number(tag_slug, kind) / CMS_CFG['list_num'])
        tag_info = MLabel.get_by_slug(tag_slug)
        if tag_info:
            tag_name = tag_info.name
        else:
            tag_name = 'Label search results'
        kwd = {
            'tag_name': tag_name,
            'tag_slug': tag_slug,
            'title': tag_name,
            'current_page': current_page_number,
            'router': router_post[kind],
            'kind': kind
        }

        the_list_file = './templates/list/label_{kind}.html'.format(kind=kind)

        if os.path.exists(the_list_file):
            tmpl = 'list/label_{kind}.html'.format(kind=kind)

        else:
            tmpl = 'list/label.html'

        self.render(tmpl,
                    infos=MPost2Label.query_pager_by_slug(
                        tag_slug,
                        kind=kind,
                        current_page_num=current_page_number),
                    kwd=kwd,
                    userinfo=self.userinfo,
                    pager=self.gen_pager(kind, tag_slug, pager_num,
                                         current_page_number),
                    cfg=CMS_CFG)
예제 #2
0
    def tearDown(self):
        print("function teardown")

        self.uu.delete(self.uid)
        MCategory.delete(self.tag_id)
        self.uu.delete(self.post_id2)
        self.uu.delete(self.post_id)
        MPost2Catalog.remove_relation(self.post_id, self.tag_id)
        tt = MLabel.get_by_slug(self.slug)
        if tt:
            MLabel.delete(tt.uid)
예제 #3
0
    def tearDown(self):
        print("function teardown")

        tt = MPost.get_by_uid(self.post_id)
        if tt:
            print('777777777777')
            MPost.delete(self.post_id)

        tt = MLabel.get_by_slug(self.tag_id)
        if tt:
            print('8888888888')
            MLabel.delete(tt.uid)
예제 #4
0
    def tearDown(self):
        print("function teardown")

        tt = self.uu.get_by_uid(self.app_f)
        if tt:
            MPost2Catalog.remove_relation(self.app_t, self.tag_id)
            MPost2Catalog.remove_relation(self.app_f, self.tag_id)
            MCategory.delete(self.tag_id)

            MPost.delete(self.app_f)
            MPost.delete(self.app_t)

        MRelation.delete(self.uid)
        tt = MLabel.get_by_slug(self.slug)
        if tt:
            MLabel.delete(tt.uid)
예제 #5
0
    def tearDown(self):
        print("function teardown")
        tt = MCategory.get_by_uid(self.tag_id)
        if tt:
            MCategory.delete(self.tag_id)
        tt = MPost.get_by_uid(self.post_id)
        if tt:
            MPost.delete(self.post_id)

            MPost2Catalog.remove_relation(self.post_id, self.tag_id)
        tt = MPost.get_by_uid(self.post_id2)
        if tt:
            MPost.delete(self.post_id2)

            MPost2Catalog.remove_relation(self.post_id2, self.tag_id)

        tt = MLabel.get_by_slug(self.slug)
        if tt:
            print('8888888888')
            MLabel.delete(self.slug)
예제 #6
0
    def tearDown(self):
        print("function teardown")
        tt = self.uu.get_by_uid(self.uid)

        if tt:
            print('翻翻翻翻翻翻翻翻翻翻翻翻翻翻翻翻翻翻3')
            self.uu.delete(self.uid)
        tt = MCategory.get_by_uid(self.tag_id)
        if tt:
            MCategory.delete(self.tag_id)
        tt = self.uu.get_by_uid(self.post_id)
        if tt:
            MCategory.delete(self.tag_id)

            MPost.delete(self.post_id2)
            MPost.delete(self.post_id)

            MPost2Catalog.remove_relation(self.post_id, self.tag_id)
            print('545456365635653')

        tt = MLabel.get_by_slug(self.slug)
        if tt:
            print('8888888888')
            MLabel.delete(tt.uid)
예제 #7
0
 def test_get_by_slug(self):
     MLabel.get_by_slug(self.name)
     assert True
예제 #8
0
class TestMLabel():
    def setup(self):
        print('setup 方法执行于本类中每条用例之前')
        self.uu = MLabel()
        self.name = 'name'
        self.tmpl_uid = ''
        self.uid = tools.get_uu4d()
        self.post_id = '2222'

    def test_create_tag(self):
        post_data = {
            'name': self.name,
        }
        newid = MLabel.create_tag(post_data['name'])

        tt = MLabel.get_id_by_name(post_data['name'])

        self.tmpl_uid = tt
        assert tt == newid
        self.tearDown()

    def test_create_tag_with_uid(self):
        '''Wiki insert: Test invalid title'''
        post_data = {
            'name': self.name,
        }
        self.uu.create_tag_with_uid(self.uid, post_data['name'])
        a = self.uu.get_id_by_name(post_data['name'])
        assert a == self.uid
        self.tearDown()

    def add_message(self, **kwargs):
        p_d = {
            'title': kwargs.get('title', 'iiiii'),
            'cnt_md': kwargs.get('cnt_md', 'grgr'),
            'time_create': kwargs.get('time_create', '1992'),
            'time_update': kwargs.get('time_update', '1996070600'),
            'user_name': kwargs.get('user_name', 'yuanyuan'),
            'view_count': kwargs.get('view_count', 1),
            'logo': kwargs.get('logo', 'prprprprpr'),
            'memo': kwargs.get('memo', ''),
            'order': kwargs.get('order', '1'),
            'keywords': kwargs.get('keywords', ''),
            'extinfo': kwargs.get('extinfo', {}),
            'kind': kwargs.get('kind2', '1'),
            'valid': kwargs.get('valid', 1),
        }
        post_id = kwargs.get('post_id', self.post_id)

        MPost.create_post(post_id, p_d)
        self.uu.create_tag_with_uid(self.uid, self.name)
        MPost2Label.add_record(self.post_id, self.name)

    def test_get_id_by_name(self):
        self.add_message()
        a = self.uu.get_id_by_name(self.name)
        print(a)
        print(self.uid)
        assert a == self.uid
        self.tearDown()

    def test_get_by_slug(self):
        self.add_message()
        a = self.uu.get_by_slug(self.uid)
        assert a.name == self.name
        self.tearDown()

    def test_delete(self):
        self.add_message()
        a = self.uu.get_by_slug(self.uid)
        assert a.name == self.name
        self.uu.delete(self.uid)
        a = self.uu.get_by_slug(self.uid)
        print(a)
        assert a == False
        self.tearDown()

    def tearDown(self):
        print("function teardown")
        tt = self.uu.get_by_slug(self.tmpl_uid)
        if tt:
            print('99999999')
            self.uu.delete(self.tmpl_uid)
        tt = self.uu.get_by_slug(self.uid)
        if tt:
            print('444444444')
            self.uu.delete(self.uid)

        tt = MPost.get_by_uid(self.post_id)
        if tt:
            print('0000000000')
            MPost.delete(self.post_id)